Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option join a tutorial using API call #166

Open
niels-beier opened this issue Jul 24, 2022 · 3 comments
Open

Option join a tutorial using API call #166

niels-beier opened this issue Jul 24, 2022 · 3 comments

Comments

@niels-beier
Copy link

It would be nice to be able to join a tutorial using an API call. Until now the only option is to join via the website which is inconvenient when nearly everything else can be managed completely using the API.

@christian-heusel
Copy link
Collaborator

Yep, sounds like a great idea! 😄 I think you have to implement it yourself tho as I am unsure whether there is an official maintainer for müsli right now .. I do currently not have the time to contribute in my spare time. 😬

@niels-beier
Copy link
Author

So how does Müsli actually add a student to a tutorial of a lecture? Till now, I was only able to find a test for adding a student to a lecture but the used webtest is not discoverable for me.

@christian-heusel
Copy link
Collaborator

Template:

<a role="button" class="btn-sm btn-primary mr-2"
tal:condition="(tutorial.student_count < tutorial.max_students) and not subscribed_tutorial"
tal:attributes="href request.route_path('tutorial_subscribe', tutorial_id=tutorial.id)">
Beitreten
</a>

Logic:

@view_config(route_name='tutorial_subscribe', context=TutorialContext, permission='subscribe')
def subscribe(context=None, request=None, tutorial=None, user=None, db=None):
tutorial = request.context.tutorials[0] if tutorial is None else tutorial
user = request.user if user is None else user
db = request.db if db is None else db
lecture = tutorial.lecture
if tutorial.max_students > tutorial.students.count():
lrs = db.query(models.LectureRemovedStudent).get((lecture.id, user.id))
if lrs: db.delete(lrs)
ls = db.query(models.LectureStudent).get((lecture.id, user.id))
if ls:
oldtutorial = ls.tutorial
else:
ls = models.LectureStudent()
ls.lecture = lecture
ls.student = user
oldtutorial = None
ls.tutorial = tutorial
if not ls in db: db.add(ls)
db.commit()
if request is not None:
if oldtutorial:
sendChangesMailUnsubscribe(request, oldtutorial, user, toTutorial=tutorial)
sendChangesMailSubscribe(request, tutorial, user, fromTutorial=oldtutorial)
request.session.flash('Erfolgreich in Übungsgruppe eingetragen', queue='messages')
else:
if request is not None:
request.session.flash('Maximale Teilnehmerzahl bereits erreicht', queue='errors')
if request is not None:
return HTTPFound(location=request.route_url('lecture_view', lecture_id=lecture.id))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants