def form_valid(self, form): settings = Settings.instance() if settings is None or not settings.clothing_ordering_enabled: return HttpResponseForbidden() super_return = super().form_valid(form) person = form.person orders = '\n'.join(o.info() for o in Order.get_current(person=person)) if orders == "": orders = _("Keine Bestellungen") email = EmailMessage() email.subject = _("Kleiderbestellung %(ophase)s") % { 'ophase': str(Ophase.current()) } email_template = loader.get_template('clothing/mail/order.txt') email.body = email_template.render({ 'name': person.prename, 'orders': orders, 'editurl': self.request.build_absolute_uri(reverse('clothing:overview')) }) email.to = [person.email] email.reply_to = [Ophase.current().contact_email_address] email.send() return super_return
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) current_ophase = Ophase.current() group_categories = Ophase.current().categories.all() group_category_choices = [(gc.id, str(gc)) for gc in group_categories] self.fields['category'] = forms.ChoiceField( label=_('Gruppenkategorie'), choices=group_category_choices) tutor_groups = TutorGroup.objects.filter(ophase=current_ophase) tutors = Person.objects.filter(ophase=current_ophase, is_tutor=True) for gc in group_categories: category_css_class = str(gc).lower().replace(' ', '-') css_classes = ['tutor-select', category_css_class] tutor_choices_per_category = [ (t.id, "{} ({})".format(t.get_name(), t.tutor_experience)) for t in tutors.filter(tutor_for=gc) ] for group in tutor_groups.filter(group_category=gc): current_tutors_per_group = [g.id for g in group.tutors.all()] self.fields["group-" + str(group.id)] = forms.MultipleChoiceField( label=str(group), choices=tutor_choices_per_category, initial=current_tutors_per_group, required=False) self.fields["group-" + str(group.id)].widget.attrs = { 'class': ' '.join(css_classes) }
def form_valid(self, form): settings = Settings.instance() if settings is None or not settings.any_registration_enabled(): return HttpResponseForbidden() try: if form.instance.tutor_experience is None: form.instance.tutor_experience = 0 super_return = super().form_valid(form) except IntegrityError: # this should happen when unique constraints fail template = loader.get_template("staff/already_registered.html") return TemplateResponse(self.request, template) # the enumeration symbol esym = '\n * ' form_list = [] for field in form.fields: label = form[field].label # remove html from label label = label.split('<', 1)[0].strip() content = form.cleaned_data[field] #Remove all fields that are not set if content: #format Many to Many and foreign key if isinstance(content, QuerySet): content = esym + esym.join(str(c) for c in content) #format True as normal language if isinstance(content, bool): content = _('Ja') form_list.append('{}: {}'.format(label, content)) form_content = '\n'.join(form_list) values = { 'ophase_title': str(Ophase.current()), 'user_prename': form.cleaned_data['prename'], 'user_name': form.cleaned_data['name'], 'user_email': form.cleaned_data['email'], 'email_changedata': Ophase.current().contact_email_address, 'form_content': form_content, } email = EmailMessage() email.subject = _('{ophase_title} Registrierung').format(**values) email.to = [ '{user_prename} {user_name} <{user_email}>'.format(**values) ] email_template = loader.get_template('staff/mail/register.txt') email.body = email_template.render(values) email.reply_to = [Ophase.current().contact_email_address] email.send() return super_return
def form_valid(self, form): settings = Settings.instance() if settings is None or not settings.any_registration_enabled(): return HttpResponseForbidden() try: if form.instance.tutor_experience is None: form.instance.tutor_experience = 0 super_return = super().form_valid(form) except IntegrityError: # this should happen when unique constraints fail template = loader.get_template("staff/already_registered.html") return TemplateResponse(self.request, template) # the enumeration symbol esym = '\n * ' form_list = [] for field in form.fields: label = form[field].label # remove html from label label = label.split('<', 1)[0].strip() content = form.cleaned_data[field] #Remove all fields that are not set if content: #format Many to Many and foreign key if isinstance(content, QuerySet): content = esym + esym.join(str(c) for c in content) #format True as normal language if isinstance(content, bool): content = _('Ja') form_list.append('{}: {}'.format(label, content)) form_content = '\n'.join(form_list) values = {'ophase_title': str(Ophase.current()), 'user_prename': form.cleaned_data['prename'], 'user_name': form.cleaned_data['name'], 'user_email': form.cleaned_data['email'], 'email_changedata': Ophase.current().contact_email_address, 'form_content': form_content, } email = EmailMessage() email.subject = _('{ophase_title} Registrierung').format(**values) email.to = ['{user_prename} {user_name} <{user_email}>'.format(**values)] email_template = loader.get_template('staff/mail/register.txt') email.body = email_template.render(values) email.reply_to = [Ophase.current().contact_email_address] email.send() return super_return
def get_context_data(self, **kwargs): context = super(NametagCreation, self).get_context_data(**kwargs) persons = Person.objects.filter( Q(ophase=Ophase.current()), Q(is_helper=True) | Q(is_tutor=True) | Q(is_orga=True)).prefetch_related('orga_jobs').order_by('name') context['staff'] = persons context['count_staff'] = persons.count() context['groupscount'] = TutorGroup.objects.filter( ophase=Ophase.current()).count() context['groups_without_picture'] = TutorGroup.objects.filter( ophase=Ophase.current(), picture='').count() context['form'] = TutorGroupSelect return context
def form_valid(self, form): settings = Settings.instance() if settings is None or not settings.clothing_ordering_enabled: return HttpResponseForbidden() super_return = super().form_valid(form) person = form.person orders = '\n'.join(o.info() for o in Order.get_current(person=person)) if orders == "": orders = _("Keine Bestellungen") email = EmailMessage() ophase_current = Ophase.current() email.subject = _("Kleiderbestellung %(ophase)s") % {'ophase': str(ophase_current)} email_template = loader.get_template('clothing/mail/order.txt') email.body = email_template.render({ 'name': person.prename, 'orders': orders, 'editurl': self.request.build_absolute_uri(reverse('clothing:overview')) }) email.to = [person.email] email.reply_to = [ophase_current.contact_email_address] email.send() return super_return
def form_valid(self, form): template = loader.get_template( "staff/dashboard/group_mass_create_success.html") context = self.get_context_data() current_ophase = Ophase.current() if current_ophase is None: context['ophase'] = False else: context['ophase'] = True category = OphaseCategory.objects.get( id=form.cleaned_data['category']) existing_group_names = set( group.name for group in TutorGroup.objects.filter(ophase=current_ophase)) new_groups = [] context['duplicate_group_count'] = 0 for name in form.cleaned_data['group_names'].splitlines(): if name not in existing_group_names: new_groups.append( TutorGroup(ophase=current_ophase, name=name, group_category=category)) else: context['duplicate_group_count'] += 1 context['new_group_count'] = len(new_groups) TutorGroup.objects.bulk_create(new_groups) return TemplateResponse(self.request, template, context=context)
def filter_jobs_for_ophase_current(cls): """ Find all jobs relevant for the current ophase All jobs with either no category or at least one matching category will be returned :return: object manager of all matching jobs """ return cls.filter_jobs_for_ophase(Ophase.current())
def get_context_data(self): context = super().get_context_data() current_ophase = Ophase.current() context['ophase_title'] = 'Ophase' if current_ophase is not None: context['ophase_title'] = str(current_ophase) students = Student.get_current() context['count_student'] = students.count() context['count_exam'] = students.filter(want_exam=True).count() t_groups = TutorGroup.objects t_groups = t_groups.annotate(num=Count('student')) t_groups = t_groups.annotate(num_exam=Sum('student__want_exam')) t_groups = t_groups.order_by('group_category', 'name') # With some DB Backends Sum returns True instead of 1 # int() fixes it. # see https://github.com/d120/pyophase/issues/47 for group in t_groups: if group.num_exam is not None: group.num_exam = int(group.num_exam) context['tutor_groups'] = t_groups return context
def generate_cert(queryset): """ Generates a PDF file with exam certificates for students in the queryset """ current_ophase = Ophase.current() (pdf, pdflatex_output) = LaTeX.render({"items": queryset.prefetch_related('tutor_group', 'tutor_group__tutors', ), "current_ophase": current_ophase}, 'students/reports/exam-report.tex', ['scheine.sty', 'OPhasenWesen.png'], 'students') return (pdf, pdflatex_output)
def form_valid(self, form): session = self.request.session current_ophase = Ophase.current() if current_ophase is None: session['gmc_ophase'] = False else: session['gmc_ophase'] = True category = OphaseCategory.objects.get(id=form.cleaned_data['category']) existing_group_names = set( group.name for group in TutorGroup.objects.filter(ophase=current_ophase)) submitted_group_names = set(form.cleaned_data['group_names'].splitlines()) new_group_names = submitted_group_names.difference(existing_group_names) ntg = partial(TutorGroup, ophase=current_ophase, group_category=category) new_groups = (ntg(name=n) for n in new_group_names) session['gmc_duplicate_group_count'] = len(submitted_group_names) - len(new_group_names) session['gmc_new_group_count'] = len(new_group_names) TutorGroup.objects.bulk_create(new_groups) return super().form_valid(form)
def get_context_data(self): context = super().get_context_data() current_ophase = Ophase.current() assignment = self._get_latest_assignment() if current_ophase is None: context['message'] = _("Keine Ophase, keine Zuteilung") context['status_icon'] = "check" context['submessage'] = "" elif assignment is None: context['message'] = _("Noch keine gültige Zuteilung") context['status_icon'] = "remove" context['submessage'] = "" elif self._correct_count(assignment): context['message'] = _("Gültige Zuteilung") context['status_icon'] = "check" formatted_datetime = formats.date_format(timezone.localtime(assignment.created_at), 'SHORT_DATETIME_FORMAT') context['submessage'] = _('Erstellt am %(formated_datetime)s') % { 'formated_datetime' : formatted_datetime,} else: context['message'] = _("Achtung: Zuteilung ist ungültig") context['status_icon'] = "remove" context['submessage'] = "" return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) category = get_object_or_404(OphaseActiveCategory, ophase=Ophase.current(), category=self.object) context['ophase_category_duration'] = category.get_human_duration() return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) students_settings = StudentsSettings.instance() staff_settings = StaffSettings.instance() workshop_settings = WorkshopSettings.instance() website_settings = WebsiteSettings.instance() current_ophase = Ophase.current() context['current_ophase'] = current_ophase context['website_settings'] = website_settings context['student_registration_enabled'] = False context['any_staff_registration_enabled'] = False if current_ophase is not None: if students_settings is not None: context[ 'student_registration_enabled'] = students_settings.student_registration_enabled if staff_settings is not None: context[ 'any_staff_registration_enabled'] = staff_settings.any_registration_enabled( ) if workshop_settings is not None: context['any_staff_registration_enabled'] = context[ 'any_staff_registration_enabled'] or workshop_settings.workshop_submission_enabled return context
def get_context_data(self): context = super().get_context_data() current_ophase = Ophase.current() context['ophase_title'] = 'Ophase' if current_ophase is not None: context['ophase_title'] = str(current_ophase) students = Student.get_current() context['count_student'] = students.count() context['count_exam'] = students.filter(want_exam=True).count() t_groups = TutorGroup.objects t_groups = t_groups.annotate(num=Count('student')) t_groups = t_groups.annotate(num_exam=Sum('student__want_exam')) t_groups = t_groups.order_by('group_category', 'name') # With some DB Backends Sum returns True instead of 1 # int() fixes it. # see https://github.com/d120/pyophase/issues/47 for group in t_groups: if group.num_exam is not None: group.num_exam = int(group.num_exam) context['tutor_groups'] = t_groups return context
def get_status(self): current_ophase = Ophase.current() if current_ophase is not None: Staff = Person.objects.filter(ophase=current_ophase) if Staff.count() > 10: return "success" return "danger"
def form_valid(self, form): session = self.request.session current_ophase = Ophase.current() if current_ophase is None: session['gmc_ophase'] = False else: session['gmc_ophase'] = True category = OphaseCategory.objects.get(id=form.cleaned_data['category']) existing_group_names = set( group.name for group in TutorGroup.objects.filter(ophase=current_ophase)) submitted_group_names = set(form.cleaned_data['group_names'].splitlines()) new_group_names = submitted_group_names.difference(existing_group_names) ntg = partial(TutorGroup, ophase=current_ophase, group_category=category) new_groups = (ntg(name=n) for n in new_group_names) session['gmc_duplicate_group_count'] = len(submitted_group_names) - len(new_group_names) session['gmc_new_group_count'] = len(new_group_names) TutorGroup.objects.bulk_create(new_groups) return super().form_valid(form)
class TutorGroupSelect(forms.Form): try: TutorGruppe = forms.ModelMultipleChoiceField( widget=forms.SelectMultiple, queryset=TutorGroup.objects.filter(ophase=Ophase.current())) except OperationalError: pass # if database is not initialized, this try-block still ensures that this form can be imported
def get_context_data(self, **kwargs): current_ophase = Ophase.current() if current_ophase is not None: context = super().get_context_data(**kwargs) context['ophase_title'] = str(current_ophase) context['title'] = self.title return context
def get_context_data(self, **kwargs): current_ophase = Ophase.current() settings = Settings.instance() if current_ophase is not None and settings is not None: vacancies = [] if settings.tutor_registration_enabled: vacancies.append(_('Tutoren')) if settings.orga_registration_enabled: vacancies.append(_('Organisatoren')) if settings.helper_registration_enabled: vacancies.append(_('Helfer')) vacancies_str = '.'.join(vacancies) vacancies_str = vacancies_str.replace('.', ', ', len(vacancies)-2) vacancies_str = vacancies_str.replace('.', ' %s '% _('und')) context = super().get_context_data(**kwargs) context['ophase_title'] = str(current_ophase) context['ophase_duration'] = current_ophase.get_human_duration() context['any_registration_enabled'] = settings.any_registration_enabled() context['tutor_registration_enabled'] = settings.tutor_registration_enabled context['orga_registration_enabled'] = settings.orga_registration_enabled context['helper_registration_enabled'] = settings.helper_registration_enabled context['staff_vacancies'] = vacancies_str return context else: context = super().get_context_data(**kwargs) context['ophase_title'] = 'Ophase' context['any_registration_enabled'] = False return context
def get_context_data(self, **kwargs): current_ophase = Ophase.current() if current_ophase is not None: context = super().get_context_data(**kwargs) context['ophase_title'] = str(current_ophase) context['title'] = self.title return context
def get_context_data(self, **kwargs): current_ophase = Ophase.current() settings = Settings.instance() if current_ophase is not None and settings is not None: vacancies = [] if settings.tutor_registration_enabled: vacancies.append(_('Tutoren')) if settings.orga_registration_enabled: vacancies.append(_('Organisatoren')) if settings.helper_registration_enabled: vacancies.append(_('Helfer')) vacancies_str = '.'.join(vacancies) vacancies_str = vacancies_str.replace('.', ', ', len(vacancies)-2) vacancies_str = vacancies_str.replace('.', ' %s '% _('und')) context = super().get_context_data(**kwargs) context['ophase_title'] = str(current_ophase) context['ophase_duration'] = current_ophase.get_human_duration() context['any_registration_enabled'] = settings.any_registration_enabled() context['tutor_registration_enabled'] = settings.tutor_registration_enabled context['orga_registration_enabled'] = settings.orga_registration_enabled context['helper_registration_enabled'] = settings.helper_registration_enabled context['staff_vacancies'] = vacancies_str return context else: context = super().get_context_data(**kwargs) context['ophase_title'] = 'Ophase' context['any_registration_enabled'] = False return context
def __init__(self, *args, **kwargs): exam_enabled = kwargs.pop('exam_enabled', False) super().__init__(*args, **kwargs) if exam_enabled == False: del self.fields['want_exam'] self.fields["tutor_group"].queryset = TutorGroup.objects.filter(ophase=Ophase.current())
def save(self, *args, **kwargs): if self.ophase_id is None: # set Ophase to current active one. We assume that there is only one active Ophase at the same time! self.ophase = Ophase.current() # ensure tutor flag is set when group is selected if self.tutor_for is not None: self.is_tutor = True super().save(*args, **kwargs)
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) current_ophase = Ophase.current() website_settings = WebsiteSettings.instance() context['current_ophase'] = current_ophase context['ophase_title'] = str(current_ophase) context['website_settings'] = website_settings context['ophase_duration'] = current_ophase.get_human_duration() return context
def __init__(self, *args, **kwargs): exam_enabled = kwargs.pop('exam_enabled', False) super().__init__(*args, **kwargs) if exam_enabled == False: del self.fields['want_exam'] self.fields["tutor_group"].queryset = TutorGroup.objects.filter( ophase=Ophase.current())
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) current_ophase = Ophase.current() website_settings = WebsiteSettings.instance() context['current_ophase'] = current_ophase context['ophase_title'] = str(current_ophase) context['website_settings'] = website_settings context['ophase_duration'] = current_ophase.get_human_duration() return context
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) category_choices = [(gc.id, str(gc)) for gc in Ophase.current().categories.all()] self.fields['category'] = forms.ChoiceField( label=_('Gruppenkategorie'), choices=category_choices) self.fields['group_names'] = forms.CharField( label=_('Gruppennamen'), help_text=_('Einen Gruppennamen pro Zeile eintragen.'), widget=forms.Textarea)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) current_ophase = Ophase.current() group_categories = Ophase.current().categories.all() group_category_choices = [(gc.id, str(gc)) for gc in group_categories] self.fields['category'] = forms.ChoiceField(label=_('Gruppenkategorie'), choices=group_category_choices) tutor_groups = TutorGroup.objects.filter(ophase=current_ophase) tutors = Person.objects.filter(ophase=current_ophase, is_tutor=True) for gc in group_categories: category_css_class = str(gc).lower().replace(' ', '-') css_classes = ['tutor-select', category_css_class] tutor_choices_per_category = [(t.id, "{} ({})".format(t.get_name(), t.tutor_experience)) for t in tutors.filter(tutor_for=gc)] for group in tutor_groups.filter(group_category=gc): current_tutors_per_group = [g.id for g in group.tutors.all()] self.fields["group-" + str(group.id)] = forms.MultipleChoiceField(label=str(group), choices=tutor_choices_per_category, initial=current_tutors_per_group, required=False) self.fields["group-" + str(group.id)].widget.attrs = {'class': ' '.join(css_classes)}
def get_context_data(self, **kwargs): current_ophase = Ophase.current() settings = Settings.instance() context = super().get_context_data(**kwargs) if current_ophase is not None and settings is not None: context['ophase_title'] = str(current_ophase) context['orga_email'] = settings.orga_email else: context['ophase_title'] = 'Ophase' return context
def get_context_data(self): context = super().get_context_data() current_ophase = Ophase.current() if current_ophase is not None: workshops = Workshop.get_current() context['num_workshops'] = workshops.count() context['filled_slots'] = sum(w.how_often for w in workshops) context['num_workshop_tutors'] = len( set(w.tutor_mail for w in workshops)) return context
def test_register_student_success(self): """Test the success view without a registration""" # Delete the Ophase from fixtures Ophase.current().delete() c = Client() # Test whitout a ophase object response = c.get(reverse('students:registration_success')) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['ophase_title'], 'Ophase') # Create a ophase object o1 = Ophase.objects.create(name="Testophase", is_active=True) response = c.get(reverse('students:registration_success')) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['ophase_title'], str(o1))
def post(self, request, *args, **kwargs): tutorgroups = TutorGroup.objects.filter(ophase=Ophase.current()) for group in tutorgroups: if request.POST['action-' + str(group.id)] == 'change': group.picture = request.FILES[str(group.id)] group.save() elif request.POST['action-' + str(group.id)] == 'delete': group.picture.delete() messages.info(request, _('Bilder erfolgreich hochgeladen.')) return redirect('dashboard:staff:group_picture_add')
def get_context_data(self, **kwargs): current_ophase = Ophase.current() settings = Settings.instance() context = super().get_context_data(**kwargs) if current_ophase is not None and settings is not None: context['ophase_title'] = str(current_ophase) context['orga_email'] = settings.orga_email else: context['ophase_title'] = 'Ophase' return context
def post(self, request, *args, **kwargs): tutorgroups = TutorGroup.objects.filter(ophase=Ophase.current()) for group in tutorgroups: if request.POST['action-' + str(group.id)] == 'change': group.picture = request.FILES[str(group.id)] group.save() elif request.POST['action-' + str(group.id)] == 'delete': group.picture.delete() messages.info(request, _( 'Bilder erfolgreich hochgeladen.')) return redirect('dashboard:staff:group_picture_add')
def generate_nametags(queryset, template='staff/reports/tutorenschilder.tex', context=None): """ Generates a PDF file with nametags for students in the queryset""" if context is None: context = {} context['items'] = queryset context['current_ophase'] = Ophase.current() (pdf, pdflatex_output) = LaTeX.render(context, template, ['OPhasenWesen.png'], 'staff') return (pdf, pdflatex_output)
def generate_nametags(queryset, template='staff/reports/tutorenschilder.tex', context=None): """ Generates a PDF file with nametags for students in the queryset""" if context is None: context = {} context['items'] = queryset context['current_ophase'] = Ophase.current() (pdf, pdflatex_output) = LaTeX.render(context, template, [ 'OPhasenWesen.png'], 'staff') return (pdf, pdflatex_output)
def get_context_data(self, **kwargs): current_ophase = Ophase.current() settings = Settings.instance() context = super().get_context_data(**kwargs) if current_ophase is not None and settings is not None: context['ophase_title'] = str(current_ophase) context['student_registration_enabled'] = settings.student_registration_enabled else: context['ophase_title'] = 'Ophase' context['student_registration_enabled'] = False return context
def get_context_data(self, **kwargs): current_ophase = Ophase.current() settings = Settings.instance() context = super().get_context_data(**kwargs) if current_ophase is not None and settings is not None: context['ophase_title'] = str(current_ophase) context[ 'student_registration_enabled'] = settings.student_registration_enabled else: context['ophase_title'] = 'Ophase' context['student_registration_enabled'] = False return context
def get_status(self): current_ophase = Ophase.current() if current_ophase is None: return "default" assignment = self._get_latest_assignment() if assignment is None: return "warning" if self._correct_count(assignment): return "success" return "danger"
def get_context_data(self, **kwargs): context = super(NametagCreation, self).get_context_data(**kwargs) current_ophase = Ophase.current() persons = Person.objects.filter(Q(ophase=current_ophase), Q(is_helper=True) | Q(is_tutor=True) | Q(is_orga=True)).prefetch_related('orga_jobs').order_by('name') context['staff'] = persons context['count_staff'] = persons.count() context['groupscount'] = TutorGroup.objects.filter( ophase=current_ophase).count() context['groups_without_picture'] = TutorGroup.objects.filter( ophase=current_ophase, picture='').count() context['form'] = TutorGroupSelect return context
def get_context_data(self, **kwargs): current_ophase = Ophase.current() settings = Settings.instance() context = super().get_context_data(**kwargs) if current_ophase is not None and settings is not None: context['ophase_title'] = str(current_ophase) context['workshop_submission_enabled'] = settings.workshop_submission_enabled context['orga_email'] = settings.orga_email else: context['ophase_title'] = 'Ophase' context['workshop_submission_enabled'] = False context['orga_email'] = "" context['other_workshops'] = Workshop.get_current().order_by('title') return context
def get_context_data(self): context = super().get_context_data() current_ophase = Ophase.current() context['ophase_title'] = _('Ophase') if current_ophase is not None: context['ophase_title'] = str(current_ophase) Staff = Person.objects.filter(ophase=current_ophase) context['count_staff'] = Staff.count() context['count_tutor'] = Staff.filter(is_tutor=True).count() context['count_orga'] = Staff.filter(is_orga=True).count() context['count_helper'] = Staff.filter(is_helper=True).count() return context
def get_context_data(self, **kwargs): current_ophase = Ophase.current() context = super().get_context_data(**kwargs) context['ophase_title'] = 'Ophase' if current_ophase is not None: context['ophase_title'] = str(current_ophase) context['registration_form'] = 'students:registration' if 'exam_enabled' in self.request.session and \ self.request.session['exam_enabled'] == False: context['registration_form'] = 'students:registration-master' return context
def get_context_data(self, **kwargs): current_ophase = Ophase.current() settings = Settings.instance() context = super().get_context_data(**kwargs) if current_ophase is not None and settings is not None: context['ophase_title'] = str(current_ophase) context[ 'workshop_submission_enabled'] = settings.workshop_submission_enabled context['orga_email'] = settings.orga_email else: context['ophase_title'] = 'Ophase' context['workshop_submission_enabled'] = False context['orga_email'] = "" context['other_workshops'] = Workshop.get_current().order_by('title') return context
def get_context_data(self, **kwargs): current_ophase = Ophase.current() context = super().get_context_data(**kwargs) context['ophase_title'] = 'Ophase' if current_ophase is not None: context['ophase_title'] = str(current_ophase) context['registration_form'] = 'students:registration' if 'exam_enabled' in self.request.session and \ self.request.session['exam_enabled'] == False: context['registration_form'] = 'students:registration-master' return context
def generate_cert(queryset): """ Generates a PDF file with exam certificates for students in the queryset """ current_ophase = Ophase.current() (pdf, pdflatex_output) = LaTeX.render( { "items": queryset.prefetch_related( 'tutor_group', 'tutor_group__tutors', ), "current_ophase": current_ophase }, 'students/reports/exam-report.tex', ['scheine.sty', 'OPhasenWesen.png'], 'students') return (pdf, pdflatex_output)
def get_context_data(self): context = super().get_context_data() current_ophase = Ophase.current() context['ophase_title'] = 'Ophase' if current_ophase is not None: context['ophase_title'] = str(current_ophase) students = Student.get_current() context['studentCount'] = students.count() context['examCount'] = students.filter(want_exam=True).count() # Get the number of groups that have at least one Student in the current Ophase context['tutorGroupCount'] = TutorGroup.objects.filter(student__ophase=current_ophase).annotate(num=Count('student')).filter(num__gte=1).count() return context
def save(self, *args, **kwargs): if self.ophase_id is None: # set Ophase to current active one. We assume that there is only one active Ophase at the same time! self.ophase = Ophase.current() # Only allow changes (and creation of individual assignments) the first time the object is created # An Assignment cannot be changed afterwards if not self.pk: # Object is being created, thus no primary key field yet # Temporarily set count to 0 self.count = 0 super().save(*args, **kwargs) # Create Person to Room Assignments # (this has to be done after saving since a reference to the current object is needed) self.count = self.assign() # Now the count can be updated and saved again super().save(*args, **kwargs)
def get_context_data(self): context = super().get_context_data() current_ophase = Ophase.current() self.current_ophase = current_ophase context['ophase_title'] = _('Ophase') if current_ophase is not None: context['ophase_title'] = str(current_ophase) staff = Person.objects.filter(ophase=current_ophase) context.update(staff.aggregate(count_tutor=Count('pk', filter=Q(is_tutor=True)), \ count_orga=Count('pk', filter=Q(is_orga=True)), \ count_helper=Count('pk', filter=Q(is_helper=True)))) context['url_filter_ophase'] = "?ophase__id__exact={}".format( current_ophase.id) # Create list of current tutors (split by categories) context['categories_for_tutors'] = [] active_categories = current_ophase.ophaseactivecategory_set.all() for ac in active_categories: tutors_for_category = Person.objects.filter(ophase=current_ophase, is_tutor=True, tutor_for=ac.category) tutors_count = tutors_for_category.count() context['categories_for_tutors'].append( { "name": ac.category.name, "count": tutors_count, "tutor": tutors_for_category, "filter": "?ophase__id__exact={}&tutorstatus={}".format(current_ophase.id, ac.category.id) } ) # Create a list of all orgajobs and fill them with persons that selected this job context['orga_jobs'] = self.overview_data(OrgaJob) # Create a list of all helper and fill them with persons that selected this job context['helper_jobs'] = self.overview_data(HelperJob) return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) students_settings = StudentsSettings.instance() staff_settings = StaffSettings.instance() workshop_settings = WorkshopSettings.instance() website_settings = WebsiteSettings.instance() current_ophase = Ophase.current() context['current_ophase'] = current_ophase context['website_settings'] = website_settings context['student_registration_enabled'] = False context['any_staff_registration_enabled'] = False if current_ophase is not None: if students_settings is not None: context['student_registration_enabled'] = students_settings.student_registration_enabled if staff_settings is not None: context['any_staff_registration_enabled'] = staff_settings.any_registration_enabled() if workshop_settings is not None: context['any_staff_registration_enabled'] = context['any_staff_registration_enabled'] or workshop_settings.workshop_submission_enabled return context
def save(self, *args, **kwargs): if self.ophase_id is None: # set Ophase to current active one. We assume that there is only one active Ophase at the same time! self.ophase = Ophase.current() super().save(*args, **kwargs)
def get_queryset(self): return Newsletter.objects.annotate(num=Count(Case( When(student__ophase=Ophase.current(), then=1), output_field=IntegerField())))
def get_current(**kwargs): return Order.objects.filter(person__ophase=Ophase.current(), **kwargs)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) category_choices = [(gc.id, str(gc)) for gc in Ophase.current().categories.all()] self.fields['category'] = forms.ChoiceField(label=_('Gruppenkategorie'), choices=category_choices) self.fields['group_names'] = forms.CharField(label=_('Gruppennamen'), help_text=_('Einen Gruppennamen pro Zeile eintragen.'), widget=forms.Textarea)
def get_current(**kwargs): return Student.objects.filter(ophase=Ophase.current(), **kwargs)
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) category = get_object_or_404(OphaseActiveCategory, ophase=Ophase.current(), category=self.object) context['ophase_category_duration'] = category.get_human_duration() return context
def post(self, request, *args, **kwargs): # should generate all nametags if request.POST['action'] == 'all_nametags': queryset = Person.objects.filter(Q(ophase=Ophase.current()), Q(is_helper=True) | Q(is_tutor=True) | Q(is_orga=True)).prefetch_related('orga_jobs').order_by('name') return generate_nametag_response(request, queryset) # generate single nametag elif request.POST['action'] == 'single_nametag': person = {'prename': request.POST['prename'], 'name': request.POST['name']} if 'tutor' in request.POST: person['is_tutor'] = True if 'orga' in request.POST: person['is_orga'] = True if len(request.POST['extrahead']) != 0: person['nametag_shortname'] = request.POST['extrahead'] person['nametag_long'] = request.POST['extrarow'] person['get_approved_orgajob_names'] = [] if 'helpdesk' in request.POST: person['get_approved_orgajob_names'].append('Helpdesk') if 'leitung' in request.POST: person['get_approved_orgajob_names'].append('Leitung') return generate_nametag_response(request, [person], filename='schild.pdf') # generate group signs elif request.POST['action'] == 'group_signs': return generate_pdf_with_group_pictures_response(request, TutorGroup.objects.filter( ophase=Ophase.current()), 'schilder.pdf', 'staff/reports/gruppenschilder.tex') elif request.POST['action'] == 'group_overview': # check whether a file was uploaded if 'roomscsv' not in request.FILES: messages.error(request, _( 'Du hast keine csv-Datei hochgeladen.')) return redirect('dashboard:staff:nametags') csv = TextIOWrapper( request.FILES['roomscsv'].file, encoding=request.encoding) csv_list = list(reader(csv)) rooms = csv_list[2:] groups = TutorGroup.objects.filter(ophase=Ophase.current()) grouprooms = zip(groups, rooms) timetable = [list(zip(csv_list[0], roomnumber, csv_list[1])) for roomnumber in rooms] timetable_rooms = zip(groups, timetable) (group_overview_pdf, group_overview_log) = generate_pdf_with_group_pictures(request, groups, 'staff/reports/gruppenuebersicht.tex', {'grouprooms': grouprooms}) (handout_pdf, handout_log) = generate_pdf_with_group_pictures(request, groups, 'staff/reports/handzettel.tex', {'grouprooms': timetable_rooms}) memoryfile = BytesIO() zipfile = ZipFile(memoryfile, 'w') if group_overview_pdf is not None: zipfile.writestr('group-overview.pdf', group_overview_pdf) else: zipfile.writestr('group-overview-log.txt', group_overview_log[0].decode('utf-8')) if handout_pdf is not None: zipfile.writestr('handout.pdf', handout_pdf) else: zipfile.writestr('handout-log.txt', handout_log[0].decode('utf-8')) zipfile.close() response = HttpResponse(content_type='application/zip') response['Content-Disposition'] = 'attachment; filename=overview.zip' memoryfile.seek(0) response.write(memoryfile.read()) return response elif request.POST['action'] == 'freshmen_nametags': if not 'roomscsv' in request.FILES: messages.error(request, _( 'Du hast keine Raum csv-Datei hochgeladen.')) if not 'freshmencsv' in request.FILES: messages.error(request, _( 'Du hast keine Erstsemester csv-Datei hochgeladen.')) freshmen = [] else: freshmencsv = TextIOWrapper( request.FILES['freshmencsv'].file, encoding=request.encoding) freshmen = list(reader(freshmencsv))[1:] # if len(messages.get_messages(request)) != 0: # return redirect('dashboard:staff:nametags') roomscsv = TextIOWrapper( request.FILES['roomscsv'].file, encoding=request.encoding) rooms = list(reader(roomscsv)) group_capacities = [int(room) for room in [room[0] for room in rooms][2:]] # skip header form = TutorGroupSelect(request.POST) form.is_valid() groups = form.cleaned_data.get('TutorGruppe') if len(groups) != len(group_capacities): messages.error(request, _( 'Es wurden nicht genauso viele Räume wie Gruppen angelegt')) return redirect('dashboard:staff:nametags') # Add empty entries to end freshmen list to create empty tags for groups not full already freshmen.extend([[" ", " "]] * (len(groups) * 5)) groups_with_rooms = list(zip(groups, rooms[2:])) freshmen_group = list(zip(freshmen, cycle_bucket(groups_with_rooms, group_capacities))) # generate group assignement overview (assignement_pdf, assignement_log) = generate_nametags( [(f, g) for f, (g, r) in freshmen_group], template='staff/reports/gruppenzuweisung.tex') if not assignement_pdf: return render(request, "staff/reports/rendering-error.html", {"content": assignement_log[0].decode("utf-8")}) # combine this with the freshmen_group-zip freshmen_tags = [] for f, (g, r) in freshmen_group: timetable = list(zip(rooms[0], rooms[1], r[1:])) freshmen_tags.append([f, g, timetable]) # Empty tags are created together with other tags already empty_tags = [] """for i, group in enumerate(groups): for x in range(5): empty_tags.append((group, timetable[i])) """ (nametags_pdf, nametag_log) = generate_pdf_with_group_pictures(request=request, groups=groups, template='staff/reports/namensschilder-ersties.tex', context={'freshmen': freshmen_tags, 'empty_tags': empty_tags}) memoryfile = BytesIO() zipfile = ZipFile(memoryfile, 'w') if assignement_pdf is not None: zipfile.writestr('assignement-overview.pdf', assignement_pdf) else: zipfile.writestr('assignement-log.txt', assignement_log[0].decode('utf-8')) if nametags_pdf is not None: zipfile.writestr('nametags.pdf', nametags_pdf) else: zipfile.writestr('nametags-log.txt', nametag_log[0].decode('utf-8')) zipfile.close() response = HttpResponse(content_type='application/zip') response['Content-Disposition'] = 'attachment; filename=freshmen.zip' memoryfile.seek(0) response.write(memoryfile.read()) return response else: messages.error(request, _('Keine valide Aktion gewählt')) return redirect('dashboard:staff:nametags')
def get_context_data(self, **kwargs): context = super(GroupPictureAdd, self).get_context_data(**kwargs) context['groups'] = TutorGroup.objects.filter(ophase=Ophase.current()) return context