def programme_admin_change_host_role_view(request, vars, event, programme_id, programme_role_id): programme = get_object_or_404(ProgrammeManagementProxy, id=int(programme_id), category__event=event) programme_role = ProgrammeRole.objects.get(id=int(programme_role_id), programme=programme) change_role_form = initialize_form(ChangeHostRoleForm, request, prefix='chr', event=event, instance=programme_role) forms = [change_role_form] SignupExtra = event.programme_event_meta.signup_extra_model if SignupExtra.supports_programme: SignupExtraForm = SignupExtra.get_programme_form_class() signup_extra = SignupExtra.for_event_and_person(event, request.user.person) signup_extra_form = initialize_form(SignupExtraForm, request, prefix='sex', instance=signup_extra ) forms.append(signup_extra_form) else: signup_extra_form = None if all(form.is_valid() for form in forms): instance = change_role_form.save() if signup_extra_form: signup_extra = signup_extra_form.process(signup_extra) instance.programme.apply_state() messages.success(request, _('The role was changed.')) else: messages.error(request, _("Please check the form.")) programme = change_role_form.instance.programme return redirect('programme_admin_detail_view', programme.event.slug, programme.pk)
def badges_admin_create_view(request, vars, event, personnel_class_slug=None): # XXX move this to core from programme.forms import ProgrammePersonForm initial = dict() if personnel_class_slug is not None: personnel_class = get_object_or_404(PersonnelClass, event=event, slug=personnel_class_slug) initial.update(personnel_class=personnel_class) badge_form = initialize_form(BadgeForm, request, prefix='badge_type', event=event, initial=initial) person_form = initialize_form(ProgrammePersonForm, request, prefix='person') if request.method == 'POST': if badge_form.is_valid() and person_form.is_valid(): person = person_form.save() badge = badge_form.save(commit=False) badge.person = person badge.save() messages.success(request, u'Henkilö on lisätty onnistuneesti.') return redirect('badges_admin_dashboard_view', event.slug) else: messages.error(request, u'Ole hyvä ja tarkista lomake.') vars.update( badge_form=badge_form, person_form=person_form, ) return render(request, 'badges_admin_create_view.jade', vars)
def initialize_signup_forms(request, event, signup, admin=False, SignupFormClass=None, SignupExtraFormClass=None): assert all([SignupFormClass, SignupExtraFormClass]) or not any([SignupFormClass, SignupExtraFormClass]) signup_extra = signup.signup_extra if SignupFormClass is None: # and SignupExtraFormClass is None from ..forms import SignupForm SignupFormClass = SignupForm SignupExtraFormClass = event.labour_event_meta.signup_extra_model.get_form_class() # Signup form and signup extra form not editable in admin mode signup_form = initialize_form(SignupFormClass, request, event=event, admin=admin, instance=signup, prefix='signup', ) signup_extra_form = initialize_form(SignupExtraFormClass, request, instance=signup_extra, prefix='extra', ) if admin: from ..forms import SignupAdminForm signup_admin_form = initialize_form(SignupAdminForm, request, event=event, instance=signup, prefix='admin', ) return signup_form, signup_extra_form, signup_admin_form else: return signup_form, signup_extra_form
def membership_admin_member_view(request, vars, organization, person_id): membership = get_object_or_404(Membership, organization=organization, person=int(person_id)) read_only = membership.person.user is not None member_form = initialize_form(MemberForm, request, instance=membership.person, readonly=read_only, prefix='member') membership_form = initialize_form(MembershipForm, request, instance=membership, prefix='membership') forms = [membership_form] if read_only else [membership_form, member_form] if request.method == 'POST': action = request.POST['action'] if action in ['save-edit', 'save-return']: if all(form.is_valid() for form in forms): for form in forms: form.save() membership.apply_state() messages.success(request, 'Jäsenen tiedot tallennettiin.') if action == 'save-return': return redirect('membership_admin_members_view', organization.slug) else: messages.error(request, 'Tarkista lomakkeen tiedot.') else: raise NotImplementedError(action) previous_membership, next_membership = membership.get_previous_and_next() tabs = [ Tab('membership-admin-person-tab', 'Jäsenen tiedot', active=True), Tab('membership-admin-state-tab', 'Jäsenyyden tila'), # Tab('membership-admin-events-tab', 'Jäsenyyteen liittyvät tapahtumat'), # Tab('membership-admin-payments-tab', 'Jäsenmaksut'), ] vars.update( member=membership.person, member_form=member_form, membership=membership, membership_form=membership_form, next_membership=next_membership, previous_membership=previous_membership, read_only=read_only, tabs=tabs, ) return render(request, 'membership_admin_member_view.jade', vars)
def membership_admin_member_view(request, vars, organization, person_id): membership = get_object_or_404(Membership, organization=organization, person=int(person_id)) read_only = membership.person.user is not None member_form = initialize_form(MemberForm, request, instance=membership.person, readonly=read_only, prefix='member') membership_form = initialize_form(MembershipForm, request, instance=membership, prefix='membership') if request.method == 'POST': action = request.POST['action'] if action in ['save-edit', 'save-return']: if read_only: valid = membership_form.is_valid() else: valid = membership_form.is_valid() and member_form.is_valid() if valid: membership_form.save() if not read_only: member_form.save() membership.apply_state() messages.success(request, u'Jäsenen tiedot tallennettiin.') if action == 'save-return': return redirect('membership_admin_members_view', organization.slug) else: messages.error(request, u'Tarkista lomakkeen tiedot.') else: raise NotImplementedError(action) previous_membership, next_membership = membership.get_previous_and_next() tabs = [ Tab('membership-admin-person-tab', u'Jäsenen tiedot', active=True), Tab('membership-admin-state-tab', u'Jäsenyyden tila'), #Tab('membership-admin-events-tab', u'Jäsenyyteen liittyvät tapahtumat'), #Tab('membership-admin-payments-tab', u'Jäsenmaksut'), ] vars.update( member=membership.person, member_form=member_form, membership=membership, membership_form=membership_form, next_membership=next_membership, previous_membership=previous_membership, read_only=read_only, tabs=tabs, ) return render(request, 'membership_admin_member_view.jade', vars)
def programme_feedback_view(request, event, programme_id): programme = get_object_or_404(Programme, id=int(programme_id), category__event=event) if not programme.is_open_for_feedback: messages.error( request, _('You cannot leave feedback about a programme that has not yet been delivered.' )) return redirect('core_event_view', event.slug) if request.user.is_authenticated: is_own_programme = request.user.person in programme.organizers.all() form = initialize_form(ProgrammeFeedbackForm, request, is_own_programme=is_own_programme) else: is_own_programme = False form = initialize_form(AnonymousProgrammeFeedbackForm, request) if request.method == 'POST': if form.is_valid(): feedback = form.save(commit=False) if feedback.is_anonymous and is_own_programme: messages.error( request, _('You cannot leave anonymous feedback about your own programme.' )) else: feedback.author = request.user.person if request.user.is_authenticated else None feedback.author_ip_address = get_ip(request) or '' feedback.programme = programme feedback.save() messages.success(request, _('Thank you for your feedback.')) return redirect('core_event_view', event.slug) else: messages.error(request, _('Please check the form.')) vars = dict( event=event, programme=programme, form=form, ) return render(request, 'programme_feedback_view.pug', vars)
def programme_admin_invitations_view(request, vars, event): pending_invitations = Invitation.objects.filter( programme__category__event=event, state='valid') if request.method == 'POST': action = request.POST.get('action') if action == 'cancel-invitation': form = initialize_form(IdForm, request) if form.is_valid(): invitation_id = form.cleaned_data['id'] invitation = get_object_or_404( Invitation, id=invitation_id, programme__category__event=event) invitation.state = 'revoked' invitation.save() invitation.programme.apply_state() messages.success(request, _('The invitation was cancelled.')) return redirect('programme_admin_invitations_view', event.slug) elif action == 'cancel-all-invitations': pending_invitations.update(state='revoked') messages.success(request, _('All pending invitations were cancelled.')) return redirect('programme_admin_invitations_view', event.slug) messages.error(request, _('Invalid request.')) vars.update(pending_invitations=pending_invitations) return render(request, 'programme_admin_invitations_view.pug', vars)
def get_for_accommodation_information(cls, request, ai): return initialize_form( cls, request, instance=ai, prefix="a%d" % ai.pk, )
def intra_admin_privileges_view(request, vars, event): meta = event.intra_event_meta users = meta.organizer_group.user_set.all().order_by( 'last_name', 'first_name') privileges_forms = [ initialize_form(PrivilegesForm, request, event=event, user=user, prefix=f'u{user.id}') for user in users ] if request.method == 'POST': if all(form.is_valid() for form in privileges_forms): for form in privileges_forms: form.save() messages.success(request, _('The privileges were updated.')) else: messages.error(request, _('Please check the form.')) vars.update( app_names=[ APP_NAMES[app_label] for app_label in meta.get_active_apps() ], privileges_forms=privileges_forms, ) return render(request, 'intra_admin_privileges_view.pug', vars)
def programme_admin_schedule_view(request, vars, event): from .public_views import actual_schedule_view if request.method == 'POST': action = request.POST.get('action') if action in schedule_actions: FormClass = schedule_actions[action] form = initialize_form(FormClass, request, event=event) if form.is_valid(): form.save() messages.success(request, _('The schedule change was successful.')) return redirect('programme_admin_schedule_view', event_slug=event.slug) else: messages.error(request, _('Please check the form.')) else: messages.error(request, _('Unknown action')) vars.update( add_view_form=ViewForm(event=event), ) return actual_schedule_view( request, event, internal_programmes=True, template='programme_admin_schedule_view.pug', vars=vars, show_programme_actions=True, )
def badges_admin_create_view(request, vars, event, personnel_class_slug=None): initial = dict() if personnel_class_slug is not None: personnel_class = get_object_or_404(PersonnelClass, event=event, slug=personnel_class_slug) initial.update(personnel_class=personnel_class) form = initialize_form(BadgeForm, request, prefix='badge_type', event=event, initial=initial) if request.method == 'POST': if form.is_valid(): badge = form.save(commit=False) badge.is_first_name_visible = bool(badge.first_name) badge.is_surname_visible = bool(badge.surname) badge.is_nick_visible = bool(badge.nick) badge.created_by = request.user try: badge.full_clean() except ValidationError, e: messages.error(request, e.message) else: badge.save() messages.success(request, _(u'The badge has been added.')) return redirect('badges_admin_dashboard_view', event.slug) else: messages.error(request, _(u'Please check the form.'))
def programme_admin_schedule_view(request, vars, event): from .public_views import actual_schedule_view if request.method == 'POST': action = request.POST.get('action') if action in schedule_actions: FormClass = schedule_actions[action] form = initialize_form(FormClass, request, event=event) if form.is_valid(): form.save() messages.success(request, _('The schedule change was successful.')) return redirect('programme_admin_schedule_view', event_slug=event.slug) else: messages.error(request, _('Please check the form.')) else: messages.error(request, _('Unknown action')) vars.update(add_view_form=ViewForm(event=event), ) return actual_schedule_view( request, event, internal_programmes=True, template='programme_admin_schedule_view.pug', vars=vars, show_programme_actions=True, )
def programme_profile_detail_view(request, programme_id): programme = get_object_or_404(ProgrammeProfileProxy, id=int(programme_id), organizers=request.user.person) event = programme.category.event form = initialize_form(ProgrammeSelfServiceForm, request, instance=programme, event=event, readonly=not programme.host_can_edit, ) if request.method == 'POST': if not programme.host_can_edit: messages.error(request, programme.host_cannot_edit_explanation) return redirect('programme_profile_detail_view', programme.id) elif form.is_valid(): form.save() messages.success(request, u'The changes were saved.') return redirect('programme_profile_view') else: messages.error(request, u'Please check the form.') vars = dict( event=event, form=form, freeform_organizers=FreeformOrganizer.objects.filter(programme=programme), invitations=Invitation.objects.filter(programme=programme, state='valid'), programme=programme, programme_roles=ProgrammeRole.objects.filter(programme=programme), ) return render(request, 'programme_profile_detail_view.jade', vars)
def programme_accept_invitation_view(request, event, code): invitation = get_object_or_404(Invitation, programme__category__event=event, code=code) if not invitation.state == 'valid': messages.error(request, _(u'The invitation is no longer valid.')) return redirect('core_event_view', event.slug) programme = invitation.programme form = initialize_form(ProgrammeSelfServiceForm, request, instance=programme, event=event, prefix='needs', ) if request.method == 'POST': if form.is_valid(): invitation.accept(request.user.person) form.save() programme.apply_state() messages.success(request, _(u'Thank you for accepting the invitation. You can change the information later from your profile.')) # TODO once there is programme_profile_programme_view, go there instead return redirect('core_event_view', event.slug) else: messages.error(request, _(u'Please check the form.')) vars = dict( form=form, ) return render(request, 'programme_accept_invitation_view.jade', vars)
def programme_feedback_view(request, event, programme_id): programme = get_object_or_404(Programme, id=int(programme_id), category__event=event) if not programme.is_open_for_feedback: messages.error(request, _('You cannot leave anonymous feedback about your own programme.')) return redirect('core_event_view', event.slug) is_own_programme = request.user.person in programme.organizers.all() form = initialize_form(ProgrammeFeedbackForm, request, is_own_programme=is_own_programme) if request.method == 'POST': if form.is_valid(): feedback = form.save(commit=False) if feedback.is_anonymous and is_own_programme: messages.error(request, _('You cannot leave anonymous feedback about your own programme.')) else: feedback.author = request.user.person feedback.author_ip_address = get_ip(request) or '' feedback.programme = programme feedback.save() messages.success(request, _('Thank you for your feedback.')) return redirect('core_event_view', event.slug) else: messages.error(request, _('Please check the form.')) vars = dict( event=event, programme=programme, form=form, ) return render(request, 'programme_feedback_view.jade', vars)
def programme_admin_invitations_view(request, vars, event): pending_invitations = Invitation.objects.filter(programme__category__event=event, state='valid') if request.method == 'POST': action = request.POST.get('action') if action == 'cancel-invitation': form = initialize_form(IdForm, request) if form.is_valid(): invitation_id = form.cleaned_data['id'] invitation = get_object_or_404(Invitation, id=invitation_id, programme__category__event=event) invitation.state = 'revoked' invitation.save() invitation.programme.apply_state() messages.success(request, _('The invitation was cancelled.')) return redirect('programme_admin_invitations_view', event.slug) elif action == 'cancel-all-invitations': pending_invitations.update(state='revoked') messages.success(request, _('All pending invitations were cancelled.')) return redirect('programme_admin_invitations_view', event.slug) messages.error(request, _('Invalid request.')) vars.update( pending_invitations=pending_invitations ) return render(request, 'programme_admin_invitations_view.pug', vars)
def tickets_admin_orders_view(request, vars, event): orders = [] form = initialize_form(SearchForm, request) if request.method == "POST": if form.is_valid(): orders = perform_search(event=event, **form.cleaned_data) else: orders = event.order_set.filter( confirm_time__isnull=False).order_by('-confirm_time') try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 paginator = Paginator(orders, 100) try: orders = paginator.page(page) except (EmptyPage, InvalidPage): orders = paginator.page(paginator.num_pages) vars.update(orders=orders, form=form) return render(request, 'tickets_admin_orders_view.pug', vars)
def generic_publish_unpublish_view( request, vars, event, meta, template, FormClass, save_success_message=_( "Application period start and end times were saved."), end_time_clear_message=_( "The end of the application period was in the past and has now been cleared. " "If you have an ending date for the application period, please set it below." ), start_now_success_message=_("The application period was started."), already_public_message=_("The application period is already underway."), stop_now_success_message=_("The application period was ended."), not_public_message=_("The application period is not currently underway."), ): form = initialize_form(FormClass, request, instance=meta) if request.method == 'POST': action = request.POST.get('action') if action == 'save': if form.is_valid(): form.save() messages.success(request, save_success_message) return redirect(request.path) else: messages.error(request, _("Please check the form.")) elif action == 'start-now': if not meta.is_public: if meta.publish(): messages.warning(request, end_time_clear_message) messages.success(request, start_now_success_message) else: messages.error(request, already_public_message) return redirect(request.path) elif action == 'stop-now': if meta.is_public: meta.unpublish() messages.success(request, stop_now_success_message) else: messages.error(request, not_public_message) return redirect(request.path) else: messages.error(request, _("Invalid request.")) vars.update( meta=meta, form=form, ) return render(request, template, vars)
def generic_publish_unpublish_view( request, vars, event, meta, template, FormClass, save_success_message=_("Application period start and end times were saved."), end_time_clear_message=_( "The end of the application period was in the past and has now been cleared. " "If you have an ending date for the application period, please set it below." ), start_now_success_message=_("The application period was started."), already_public_message=_("The application period is already underway."), stop_now_success_message=_("The application period was ended."), not_public_message=_("The application period is not currently underway."), ): form = initialize_form(FormClass, request, instance=meta) if request.method == 'POST': action = request.POST.get('action') if action == 'save': if form.is_valid(): form.save() messages.success(request, save_success_message) return redirect(request.path) else: messages.error(request, _("Please check the form.")) elif action == 'start-now': if not meta.is_public: if meta.publish(): messages.warning(request, end_time_clear_message) messages.success(request, start_now_success_message) else: messages.error(request, already_public_message) return redirect(request.path) elif action == 'stop-now': if meta.is_public: meta.unpublish() messages.success(request, stop_now_success_message) else: messages.error(request, not_public_message) return redirect(request.path) else: messages.error(request, _("Invalid request.")) vars.update( meta=meta, form=form, ) return render(request, template, vars)
def labour_survey_view(request, event, survey_slug): survey = get_object_or_404(Survey, slug=survey_slug, event=event) person = request.user.person Form = survey.form_class try: signup = Signup.objects.get(event=event, person=person) except Signup.DoesNotExist: signup = FakeSignup(event) try: instance = Form.get_instance_for_event_and_person(event, person) except ObjectDoesNotExist: instance = None if instance is None: messages.error(request, survey.does_not_apply_message) return redirect('core_event_view', event.slug) if not survey.is_active: if SurveyRecord.objects.filter(survey=survey, person=person).exists(): messages.warning( request, _('You have previously answered this survey that is no longer active. You may view ' 'your answers below, but you cannot alter them any more.')) else: messages.error(request, _('This survey is not currently active.')) return redirect('core_event_view', event.slug) form = initialize_form( Form, request, instance=instance, event=event, readonly=not survey.is_active, ) if request.method == 'POST': if form.is_valid() and survey.is_active: SurveyRecord.objects.get_or_create(survey=survey, person=person) form.save() messages.success(request, _('Thank you for your answers.')) return redirect('core_event_view', event.slug) else: messages.error(request, _('Please check the form.')) vars = dict( event=event, signup=signup, instance=instance, survey=survey, form=form, ) return render(request, 'labour_survey_view.pug', vars)
def get_for_order_and_product(cls, request, order, product, admin=False): order_product, unused = OrderProduct.objects.get_or_create(order=order, product=product) return initialize_form(OrderProductForm, request, instance=order_product, prefix="o%d" % order_product.pk, # XXX disallow changing amounts of electronic tickets for now readonly=admin and ((order.batch is not None and product.requires_shipping) or (order.is_paid and product.electronic_ticket)), )
def membership_apply_view(request, organization): meta = organization.membership_organization_meta mandatory_information_missing = not ( request.user.person and request.user.person.official_first_names and request.user.person.surname and request.user.person.muncipality and request.user.person.email ) already_member = Membership.objects.filter( organization=organization, person=request.user.person, ).exists() can_apply = (not mandatory_information_missing) and (not already_member) form = initialize_form(ApplicationForm, request) try: current_term = meta.get_current_term() except Term.DoesNotExist: current_term = None if request.method == 'POST': if already_member: messages.error(request, 'Olet jo jäsen tai jäsenhakemuksesi on jo käsiteltävänä.') elif mandatory_information_missing: messages.error(request, 'Profiilistasi puuttuu pakollisia tietoja.') elif not form.is_valid(): messages.error(request, 'Tarkista lomakkeen tiedot.') else: membership = form.save(commit=False) membership.organization = organization membership.person = request.user.person membership.state = 'approval' membership.save() messages.success(request, 'Kiitos jäsenyyshakemuksestasi! Yhdistyksen hallitus käsittelee ' 'hakemuksesi seuraavassa kokouksessaan.' ) return redirect('core_organization_view', organization.slug) vars = dict( already_member=already_member, can_apply=can_apply, form=form, mandatory_information_missing=mandatory_information_missing, meta=meta, organization=organization, current_term=current_term, ) return render(request, 'membership_apply_view.pug', vars)
def membership_apply_view(request, organization): meta = organization.membership_organization_meta mandatory_information_missing = not ( request.user.person and request.user.person.official_first_names and request.user.person.surname and request.user.person.muncipality and request.user.person.email ) already_member = Membership.objects.filter( organization=organization, person=request.user.person, ).exists() can_apply = (not mandatory_information_missing) and (not already_member) form = initialize_form(ApplicationForm, request) try: current_term = meta.get_current_term() except Term.DoesNotExist: current_term = None if request.method == 'POST': if already_member: messages.error(request, u'Olet jo jäsen tai jäsenhakemuksesi on jo käsiteltävänä.') elif mandatory_information_missing: messages.error(request, u'Profiilistasi puuttuu pakollisia tietoja.') elif not form.is_valid(): messages.error(request, u'Tarkista lomakkeen tiedot.') else: membership = form.save(commit=False) membership.organization = organization membership.person = request.user.person membership.state = 'approval' membership.save() messages.success(request, u'Kiitos jäsenyyshakemuksestasi! Yhdistyksen hallitus käsittelee ' u'hakemuksesi seuraavassa kokouksessaan.' ) return redirect('core_organization_view', organization.slug) vars = dict( already_member=already_member, can_apply=can_apply, form=form, mandatory_information_missing=mandatory_information_missing, meta=meta, organization=organization, current_term=current_term, ) return render(request, 'membership_apply_view.jade', vars)
def labour_survey_view(request, event, survey_slug): survey = get_object_or_404(Survey, slug=survey_slug, event=event) person = request.user.person Form = survey.form_class try: signup = Signup.objects.get(event=event, person=person) except Signup.DoesNotExist: signup = FakeSignup(event) try: instance = Form.get_instance_for_event_and_person(event, person) except ObjectDoesNotExist: instance = None if instance is None: messages.error(request, survey.does_not_apply_message) return redirect('core_event_view', event.slug) if not survey.is_active: if SurveyRecord.objects.filter(survey=survey, person=person).exists(): messages.warning(request, _( 'You have previously answered this survey that is no longer active. You may view ' 'your answers below, but you cannot alter them any more.' )) else: messages.error(request, _('This survey is not currently active.')) return redirect('core_event_view', event.slug) form = initialize_form(Form, request, instance=instance, event=event, readonly=not survey.is_active, ) if request.method == 'POST': if form.is_valid() and survey.is_active: SurveyRecord.objects.get_or_create(survey=survey, person=person) form.save() messages.success(request, _('Thank you for your answers.')) return redirect('core_event_view', event.slug) else: messages.error(request, _('Please check the form.')) vars = dict( event=event, signup=signup, instance=instance, survey=survey, form=form, ) return render(request, 'labour_survey_view.pug', vars)
def make_form(self, request, event): order = get_order(request, event) sizes_by_type = self._get_sizes(event) forms = [] for shirt_type, shirt_sizes in sizes_by_type: for size in shirt_sizes: shirt_order, created = ShirtOrder.objects.get_or_create(order=order, size=size) form = initialize_form(ShirtOrderForm, request, instance=shirt_order, prefix="s%d" % shirt_order.pk) forms.append(form) return forms
def labour_admin_jobcategory_view(request, vars, event, job_category_slug=None): meta = event.labour_event_meta if job_category_slug is not None: # Edit existing job_category = get_object_or_404(JobCategoryManagementProxy, event=event, slug=job_category_slug) else: # Add new job_category = JobCategoryManagementProxy(event=event, app_label='labour') form = initialize_form(JobCategoryForm, request, instance=job_category, event=event) if request.method == 'POST': action = request.POST.get('action') if action in ('save-return', 'save-edit'): if form.is_valid(): job_category = form.save() meta.create_groups_async() messages.success(request, _("The job category was saved.")) if action == 'save-return': return redirect('labour_admin_jobcategories_view', event.slug) elif action == 'save-edit': return redirect('labour_admin_jobcategory_view', event.slug, job_category.slug) else: raise NotImplementedError(action) else: messages.error(request, _("Please check the form.")) elif action == 'remove' and job_category.can_remove: job_category.delete() messages.success(request, _("The job category was removed.")) return redirect('labour_admin_jobcategories_view', event.slug) else: messages.error(request, _("Invalid request.")) vars.update( form=form, job_category=job_category, ) return render(request, 'labour_admin_jobcategory_view.jade', vars)
def labour_admin_startstop_view(request, vars, event): meta = event.labour_event_meta form = initialize_form(StartStopForm, request, instance=meta) if request.method == 'POST': action = request.POST.get('action') if action == 'save': if form.is_valid(): form.save() messages.success(request, _("Application period start and end times were saved.")) return redirect("labour_admin_startstop_view", event.slug) else: messages.error(request, _("Please check the form.")) elif action == 'start-now': if not meta.is_registration_open: meta.registration_opens = now() if meta.registration_closes <= meta.registration_closes: messages.warning(request, _( "The end of the application period was in the past and has now been cleared. " "If you have an ending date for the application period, please set it below." )) meta.registration_closes = None meta.save() messages.success(request, _("The application period was started.")) else: messages.error(request, _("The application period is already underway.")) return redirect("labour_admin_startstop_view", event.slug) elif action == 'stop-now': if meta.is_registration_open: meta.registration_closes = now() meta.save() messages.success(request, _("The application period was ended.")) else: messages.error(request, _("The application period is not currently underway.")) return redirect("labour_admin_startstop_view", event.slug) else: messages.error(request, _("Invalid request.")) vars.update( meta=meta, form=form, ) return render(request, 'labour_admin_startstop_view.jade', vars)
def _badges_view(request, vars, event): new_batch_form = initialize_form( CreateBatchForm, request, event=event, initial=dict(max_items=100), ) if request.method == 'POST': if 'new-batch' in request.POST: if new_batch_form.is_valid(): batch = Batch.create(event=event, **new_batch_form.cleaned_data) messages.success( request, "Erä {batch.pk} on luotu onnistuneesti".format( batch=batch)) return redirect(request.path) else: messages.error(request, "Ole hyvä ja korjaa lomakkeen virheet.") elif 'cancel-batch' in request.POST or 'confirm-batch' in request.POST: hidden_batch_crouching_form = HiddenBatchCrouchingForm( request.POST) if hidden_batch_crouching_form.is_valid(): batch = get_object_or_404(Batch, event=event, pk=hidden_batch_crouching_form. cleaned_data['batch_id']) if 'cancel-batch' in request.POST and batch.can_cancel: batch.cancel() messages.success(request, "Erä peruttiin.") return redirect(request.path) elif 'confirm-batch' in request.POST and batch.can_confirm: batch.confirm() messages.success(request, "Erä on merkitty valmiiksi.") return redirect(request.path) # error messages.error(request, "Et ole tulitikku kung-fulleni.") vars.update(new_batch_form=new_batch_form, batches=Batch.objects.filter( event=event).order_by(created_at_field)) return render(request, template, vars)
def programme_admin_change_invitation_role_view(request, vars, event, programme_id, invitation_id): programme = get_object_or_404(ProgrammeManagementProxy, id=int(programme_id), category__event=event) invitation = Invitation.objects.get(id=int(invitation_id), programme=programme) change_role_form = initialize_form(ChangeInvitationRoleForm, request, prefix='cir', event=event, instance=invitation) if change_role_form.is_valid(): instance = change_role_form.save() instance.programme.apply_state() messages.success(request, _('The role was changed.')) else: messages.error(request, _("Please check the form.")) programme = change_role_form.instance.programme return redirect('programme_admin_detail_view', programme.event.slug, programme.pk)
def get_for_order_and_product(cls, request, order, product, admin=False): order_product, unused = OrderProduct.objects.get_or_create( order=order, product=product) return initialize_form( OrderProductForm, request, instance=order_product, prefix="o%d" % order_product.pk, # XXX disallow changing amounts of electronic tickets for now readonly=admin and ((order.batch is not None and product.requires_shipping) or (order.is_paid and product.electronic_ticket)), )
def labour_person_qualification_view(request, qualification): vars = page_wizard_vars(request) person = request.user.person qualification = get_object_or_404(Qualification, slug=qualification) try: person_qualification = qualification.personqualification_set.get(person=person) except PersonQualification.DoesNotExist: person_qualification = PersonQualification( person=person, qualification=qualification ) QualificationExtra = qualification.qualification_extra_model if QualificationExtra: QualificationExtraForm = QualificationExtra.get_form_class() qualification_extra = person_qualification.qualification_extra form = initialize_form(QualificationExtraForm, request, instance=qualification_extra) else: qualification_extra = None form = None if request.method == 'POST': form_valid = not form or (form and form.is_valid()) if form_valid: person_qualification.save() if form: qualification_extra.personqualification = person_qualification form.save() messages.success(request, _('The qualification has been updated.')) return redirect('labour_qualifications_view') else: messages.error(request, _('Please check the form.')) vars.update( person_qualification=person_qualification, form=form ) if 'page_wizard' in vars: template_name = 'labour_new_user_person_qualification_view.jade' else: template_name = 'labour_profile_person_qualification_view.jade' return render(request, template_name, vars)
def labour_person_qualification_view(request, qualification): vars = page_wizard_vars(request) person = request.user.person qualification = get_object_or_404(Qualification, slug=qualification) try: person_qualification = qualification.personqualification_set.get(person=person) except PersonQualification.DoesNotExist: person_qualification = PersonQualification( person=person, qualification=qualification ) QualificationExtra = qualification.qualification_extra_model if QualificationExtra: QualificationExtraForm = QualificationExtra.get_form_class() qualification_extra = person_qualification.qualification_extra form = initialize_form(QualificationExtraForm, request, instance=qualification_extra) else: qualification_extra = None form = None if request.method == 'POST': form_valid = not form or (form and form.is_valid()) if form_valid: person_qualification.save() if form: qualification_extra.personqualification = person_qualification form.save() messages.success(request, u'Pätevyys tallennettiin.') return redirect('labour_qualifications_view') else: messages.error(request, u'Ole hyvä ja korjaa lomakkeen virheet.') vars.update( person_qualification=person_qualification, form=form ) if 'page_wizard' in vars: template_name = 'labour_new_user_person_qualification_view.jade' else: template_name = 'labour_profile_person_qualification_view.jade' return render(request, template_name, vars)
def feedback_view(request): feedback_form = initialize_form(FeedbackForm, request) if feedback_form.is_valid(): feedback = feedback_form.save(commit=False) if request.user.is_authenticated: feedback.author = request.user feedback.context = request.META.get('HTTP_REFERER', '') feedback.author_ip_address = get_ip(request) or '' feedback.save() return HttpResponse(status=201) else: return HttpResponse(status=400)
def programme_admin_create_view(request, vars, event): form = initialize_form(ProgrammePublicForm, request, event=event) if request.method == 'POST': if form.is_valid(): programme = form.save() messages.success(request, _('The programme was created.')) return redirect('programme_admin_detail_view', event.slug, programme.pk) else: messages.error(request, _('Please check the form.')) vars.update( form=form, ) return render(request, 'programme_admin_create_view.jade', vars)
def make_form(self, request, event): order = get_order(request, event) sizes_by_type = self._get_sizes(event) forms = [] for shirt_type, shirt_sizes in sizes_by_type: for size in shirt_sizes: shirt_order, created = ShirtOrder.objects.get_or_create( order=order, size=size) form = initialize_form(ShirtOrderForm, request, instance=shirt_order, prefix="s%d" % shirt_order.pk) forms.append(form) return forms
def feedback_view(request): feedback_form = initialize_form(FeedbackForm, request) if feedback_form.is_valid(): feedback = feedback_form.save(commit=False) if request.user.is_authenticated(): feedback.author = request.user feedback.context = request.META.get('HTTP_REFERER', '') feedback.author_ip_address = get_ip(request) or '' feedback.save() return HttpResponse(status=201) else: return HttpResponse(status=400)
def membership_admin_term_view(request, vars, organization, term_id=None): meta = organization.membership_organization_meta if term_id: term = get_object_or_404(Term, id=int(term_id), organization=organization) else: term = Term(organization=organization) terms = [(the_term, (the_term.pk == term.pk if term else False)) for the_term in Term.objects.filter(organization=organization)] terms.append((NewTerm(organization), (term_id is None))) today = date.today() form = initialize_form(TermForm, request, instance=term, initial={} if term.pk else dict( title=today.year, start_date=today.replace(month=1, day=1), end_date=today.replace(month=12, day=31), )) if request.method == 'POST': if form.is_valid(): term = form.save() # There may be unpaid membership fee entries. If membership fee was changed, # these need to be invalidated. MembershipFeePayment.objects.filter( term=term, payment_date__isnull=True).delete() return redirect('membership_admin_term_view', organization_slug=organization.slug, term_id=term.id) else: messages.error(request, _('Please check the form.')) vars.update( form=form, meta=meta, term=term, terms=terms, ) return render(request, 'membership_admin_term_view.pug', vars)
def programme_admin_schedule_update_view_view(request, vars, event, view_id): view = get_object_or_404(View, id=int(view_id), event=event) action = request.POST.get('action') if action in view_actions: FormClass = view_actions[action] form = initialize_form(FormClass, request, instance=view) if form.is_valid(): form.save() messages.success(request, _('The schedule change was successful.')) return redirect('programme_admin_schedule_view', event_slug=event.slug) else: messages.error(request, _('Please check the form.')) else: messages.error(request, _('Unknown action')) return redirect('programme_admin_schedule_view', event_slug=event.slug)
def admin_create_view(request, vars, event): form = initialize_form(ProgrammeAdminCreateForm, request, event=event) if request.method == 'POST': if form.is_valid(): programme = form.save(commit=False) programme.save() form.save_m2m() messages.success(request, _('The programme was created.')) return redirect('programme:admin_detail_view', event.slug, programme.pk) else: messages.error(request, _('Please check the form.')) vars.update(form=form, ) return render(request, 'programme_admin_create_view.pug', vars)
def _badges_view(request, vars, event): new_batch_form = initialize_form(CreateBatchForm, request, event=event, initial=dict(max_items=100), ) if request.method == 'POST': if 'new-batch' in request.POST: if new_batch_form.is_valid(): batch = Batch.create(event=event, **new_batch_form.cleaned_data) messages.success(request, u"Erä {batch.pk} on luotu onnistuneesti".format(batch=batch)) return redirect(request.path) else: messages.error(request, u"Ole hyvä ja korjaa lomakkeen virheet.") elif 'cancel-batch' in request.POST or 'confirm-batch' in request.POST: hidden_batch_crouching_form = HiddenBatchCrouchingForm(request.POST) if hidden_batch_crouching_form.is_valid(): batch = get_object_or_404(Batch, event=event, pk=hidden_batch_crouching_form.cleaned_data['batch_id'] ) if 'cancel-batch' in request.POST and batch.can_cancel: batch.cancel() messages.success(request, u"Erä peruttiin.") return redirect(request.path) elif 'confirm-batch' in request.POST and batch.can_confirm: batch.confirm() messages.success(request, u"Erä on merkitty valmiiksi.") return redirect(request.path) # error messages.error(request, u"Et ole tulitikku kung-fulleni.") vars.update( new_batch_form=new_batch_form, batches=Batch.objects.filter(event=event).order_by(created_at_field) ) return render(request, template, vars)
def tickets_admin_accommodation_create_view(request, vars, event, limit_group_id): limit_group_id = int(limit_group_id) limit_group = get_object_or_404(LimitGroup, id=limit_group_id, event=event) form = initialize_form(AccommodationInformationForm, request) if request.method == 'POST': info = form.save() info.limit_groups = [limit_group] info.save() messages.success(request, u'Majoittuja lisättiin.') return redirect('tickets_admin_accommodation_filtered_view', event.slug, limit_group_id) vars.update( form=form, limit_group=limit_group, ) return render(request, 'tickets_admin_accommodation_create_view.jade', vars)
def enrollment_enroll_view(request, event): meta = event.enrollment_event_meta already_enrolled = Enrollment.objects.filter( event=event, person=request.user.person, ).exists() if already_enrolled: # TODO Display messages.error(request, _("You are already enrolled in this event.")) return redirect('core_event_view', event.slug) EnrollmentForm = meta.form_class form = initialize_form(EnrollmentForm, request) if request.method == 'POST': # TODO Allow changing/cancelling enrollment as long as enrollment period is open if form.is_valid(): enrollment = form.save(commit=False) enrollment.event = event enrollment.person = request.user.person enrollment.save() form.save_m2m() messages.success(request, _("Thank you for enrolling.") ) return redirect('core_event_view', event.slug) else: messages.error(request, _("Please check the form.")) vars = dict( already_enrolled=already_enrolled, event_slug = event, event=event, form=form, ) return render(request, 'enrollment_enroll_view.jade', vars)
def badges_admin_create_view(request, vars, event, personnel_class_slug=None): initial = dict() if personnel_class_slug is not None: personnel_class = get_object_or_404(PersonnelClass, event=event, slug=personnel_class_slug) initial.update(personnel_class=personnel_class) form = initialize_form(BadgeForm, request, prefix='badge_type', event=event, initial=initial) if request.method == 'POST': if form.is_valid(): badge = form.save(commit=False) badge.is_first_name_visible = bool(badge.first_name) badge.is_surname_visible = bool(badge.surname) badge.is_nick_visible = bool(badge.nick) badge.created_by = request.user try: badge.full_clean() except ValidationError as e: messages.error(request, e.message) else: badge.save() messages.success(request, _('The badge has been added.')) return redirect('badges_admin_dashboard_view', event.slug) else: messages.error(request, _('Please check the form.')) vars.update(form=form, ) return render(request, 'badges_admin_create_view.pug', vars)
def tickets_admin_accommodation_create_view(request, vars, event, limit_group_id): limit_group_id = int(limit_group_id) limit_group = get_object_or_404(LimitGroup, id=limit_group_id, event=event) form = initialize_form(AccommodationInformationForm, request) if request.method == 'POST': info = form.save() info.limit_groups = [limit_group] info.save() messages.success(request, 'Majoittuja lisättiin.') return redirect('tickets_admin_accommodation_filtered_view', event.slug, limit_group_id) vars.update( form=form, limit_group=limit_group, ) return render(request, 'tickets_admin_accommodation_create_view.pug', vars)
def enrollment_enroll_view(request, event): meta = event.enrollment_event_meta already_enrolled = Enrollment.objects.filter( event=event, person=request.user.person, ).exists() if already_enrolled: # TODO Display messages.error(request, _("You are already enrolled in this event.")) return redirect('core_event_view', event.slug) EnrollmentForm = meta.form_class form = initialize_form(EnrollmentForm, request) if request.method == 'POST': # TODO Allow changing/cancelling enrollment as long as enrollment period is open if form.is_valid(): enrollment = form.save(commit=False) enrollment.event = event enrollment.person = request.user.person enrollment.save() form.save_m2m() messages.success(request, _("Thank you for enrolling.")) return redirect('core_event_view', event.slug) else: messages.error(request, _("Please check the form.")) vars = dict( already_enrolled=already_enrolled, event_slug=event, event=event, form=form, ) return render(request, 'enrollment_enroll_view.jade', vars)
def intra_admin_privileges_view(request, vars, event): meta = event.intra_event_meta users = meta.organizer_group.user_set.all().order_by('last_name', 'first_name') privileges_forms = [ initialize_form(PrivilegesForm, request, event=event, user=user, prefix=f'u{user.id}') for user in users ] if request.method == 'POST': if all(form.is_valid() for form in privileges_forms): for form in privileges_forms: form.save() messages.success(request, _('The privileges were updated.')) else: messages.error(request, _('Please check the form.')) vars.update( app_names=[APP_NAMES[app_label] for app_label in meta.get_active_apps()], privileges_forms=privileges_forms, ) return render(request, 'intra_admin_privileges_view.pug', vars)
def tickets_admin_orders_view(request, vars, event): orders = [] form = initialize_form(SearchForm, request) if request.method == "POST": if form.is_valid(): orders = perform_search(event=event, **form.cleaned_data) else: orders = event.order_set.filter(confirm_time__isnull=False).order_by('-confirm_time') try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 paginator = Paginator(orders, 100) try: orders = paginator.page(page) except (EmptyPage, InvalidPage): orders = paginator.page(paginator.num_pages) vars.update(orders=orders, form=form) return render(request, 'tickets_admin_orders_view.jade', vars)
def make_form(self, request, event): return initialize_form(NullForm, request)
def labour_admin_signup_view(request, vars, event, person_id): person = get_object_or_404(Person, pk=int(person_id)) signup = get_object_or_404(Signup, person=person, event=event) old_state_flags = signup._state_flags signup_form, signup_extra_form, signup_admin_form = initialize_signup_forms( request, event, signup, admin=True) person_form = initialize_form( AdminPersonForm, request, instance=signup.person, prefix='person', readonly=True, event=event, ) if request.method == 'POST': # XXX Need to update state before validation to catch accepting people without accepted job categories for state_name in signup.next_states: command_name = 'set-state-{state_name}'.format( state_name=state_name) if command_name in request.POST: old_state_flags = signup._state_flags signup.state = state_name break if signup_form.is_valid() and signup_extra_form.is_valid( ) and signup_admin_form.is_valid(): signup_form.save() signup_extra_form.save() signup_admin_form.save() signup.apply_state() messages.success(request, 'Tiedot tallennettiin.') if 'save-return' in request.POST: return redirect('labour_admin_signups_view', event.slug) else: return redirect('labour_admin_signup_view', event.slug, person.pk) else: # XXX Restore state just for shows, suboptimal but signup._state_flags = old_state_flags messages.error(request, 'Ole hyvä ja tarkista lomake.') non_qualified_category_names = [ jc.name for jc in JobCategory.objects.filter(event=event) if not jc.is_person_qualified(signup.person) ] non_applied_categories = list(JobCategory.objects.filter(event=event)) for applied_category in signup.job_categories.all(): non_applied_categories.remove(applied_category) non_applied_category_names = [cat.name for cat in non_applied_categories] previous_signup, next_signup = signup.get_previous_and_next_signup() historic_signups = Signup.objects.filter(person=signup.person).exclude( event=event).order_by('-event__start_time') if not person.allow_work_history_sharing: # The user has elected to not share their full work history between organizations. # Only show work history for the current organization. historic_signups = historic_signups.filter( event__organization=event.organization) tabs = [ Tab('labour-admin-signup-state-tab', 'Hakemuksen tila', active=True), Tab('labour-admin-signup-person-tab', 'Hakijan tiedot'), Tab('labour-admin-signup-application-tab', 'Hakemuksen tiedot'), Tab('labour-admin-signup-messages-tab', 'Työvoimaviestit', notifications=signup.person_messages.count()), Tab('labour-admin-signup-shifts-tab', 'Työvuorot'), Tab('labour-admin-signup-history-tab', 'Työskentelyhistoria', notifications=historic_signups.count()), ] vars.update( historic_signups=historic_signups, next_signup=next_signup, person_form=person_form, previous_signup=previous_signup, signup=signup, signup_admin_form=signup_admin_form, signup_extra_form=signup_extra_form, signup_form=signup_form, tabs=tabs, total_hours=signup.shifts.all().aggregate(Sum('hours'))['hours__sum'], # XXX hack: widget customization is very difficult, so apply styles via JS non_applied_category_names_json=json.dumps(non_applied_category_names), non_qualified_category_names_json=json.dumps( non_qualified_category_names), ) person.log_view(request, event=event) return render(request, 'labour_admin_signup_view.jade', vars)
def programme_profile_detail_view(request, programme_id): programme_role_qs = ProgrammeRole.objects.filter( person=request.user.person, programme=int(programme_id)) try: programme_role = get_object_or_404(programme_role_qs) except ProgrammeRole.MultipleObjectsReturned: programme_role = programme_role_qs.first() logger.warn('Multiple roles for same programme/person: %s', programme_role.programme) programme = programme_role.programme event = programme.category.event if programme.form_used: alternative_programme_form = programme.form_used FormClass = alternative_programme_form.programme_form_class else: # implicit default form alternative_programme_form = None FormClass = ProgrammeSelfServiceForm form = initialize_form( FormClass, request, instance=programme, event=event, readonly=not programme.host_can_edit, ) sired_invitation_formset = get_sired_invitation_formset( request, num_extra_invites=programme_role.extra_invites_left, ) forms = [form, sired_invitation_formset] SignupExtra = event.programme_event_meta.signup_extra_model if SignupExtra.supports_programme: SignupExtraForm = SignupExtra.get_programme_form_class() signup_extra = SignupExtra.for_event_and_person( event, request.user.person) signup_extra_form = initialize_form( SignupExtraForm, request, instance=signup_extra, prefix='extra', ) forms.append(signup_extra_form) else: signup_extra = None signup_extra_form = None if request.method == 'POST': if not programme.host_can_edit: messages.error(request, programme.host_cannot_edit_explanation) return redirect('programme_profile_detail_view', programme.id) elif all(the_form.is_valid() for the_form in forms): with transaction.atomic(): form.save() if signup_extra_form: signup_extra = signup_extra_form.process(signup_extra) for extra_invite in sired_invitation_formset.save( commit=False): extra_invite.programme = programme extra_invite.created_by = request.user extra_invite.role = programme_role.role extra_invite.sire = programme_role extra_invite.save() extra_invite.send(request) messages.success(request, _('The changes were saved.')) return redirect('programme_profile_view') else: messages.error(request, 'Please check the form.') invitations = Invitation.objects.filter(programme=programme, state='valid') invitations = list(invitations) for invitation in invitations: invitation.sired_by_current_user = invitation.sire and invitation.sire.person == request.user.person vars = dict( alternative_programme_form=alternative_programme_form, event=event, form=form, freeform_organizers=FreeformOrganizer.objects.filter( programme=programme), host_can_invite_more=programme_role.extra_invites_left > 0, invitations=invitations, num_extra_invites=programme_role.extra_invites_left, programme_role=programme_role, programme_roles=ProgrammeRole.objects.filter(programme=programme), programme=programme, signup_extra_form=signup_extra_form, sired_invitation_formset=sired_invitation_formset, ) return render(request, 'programme_profile_detail_view.jade', vars)
def labour_admin_mail_editor_view(request, vars, event, message_id=None): from mailings.models import Message from mailings.forms import MessageForm if message_id: message = get_object_or_404(Message, recipient__event=event, pk=int(message_id)) else: message = None form = initialize_form(MessageForm, request, event=event, instance=message) if request.method == 'POST': if 'delete' in request.POST: assert not message.sent_at message.delete() messages.success(request, u'Viesti poistettiin.') return redirect('labour_admin_mail_view', event.slug) else: if form.is_valid(): message = form.save(commit=False) if 'save-send' in request.POST: message.save() message.send() messages.success(request, u'Viesti lähetettiin. Se lähetetään automaattisesti myös kaikille uusille vastaanottajille.') elif 'save-expire' in request.POST: message.save() message.expire() messages.success(request, u'Viesti merkittiin vanhentuneeksi. Sitä ei lähetetä enää uusille vastaanottajille.') elif 'save-unexpire' in request.POST: message.save() message.unexpire() messages.success(request, u'Viesti otettiin uudelleen käyttöön. Se lähetetään automaattisesti myös kaikille uusille vastaanottajille.') elif 'save-return' in request.POST: message.save() messages.success(request, u'Muutokset viestiin tallennettiin.') return redirect('labour_admin_mail_view', event.slug) elif 'save-edit' in request.POST: message.save() messages.success(request, u'Muutokset viestiin tallennettiin.') else: messages.error(request, u'Tuntematon toiminto.') return redirect('labour_admin_mail_editor_view', event.slug, message.pk) else: messages.error(request, u'Ole hyvä ja tarkasta lomake.') vars.update( message=message, form=form, sender="TODO", ) return render(request, 'labour_admin_mail_editor_view.jade', vars)
def intra_admin_team_member_view(request, vars, event, team_slug=None, person_id=None): meta = event.intra_event_meta initial_data = dict() if team_slug is not None: team = get_object_or_404(Team, event=event, slug=team_slug) initial_data.update(team=team) else: team = None if person_id is not None: person = get_object_or_404(Person, id=int(person_id), user__groups=meta.organizer_group, ) initial_data.update(person=person) else: person = None team_member_form = None if team and person: try: team_member = TeamMember.objects.get(team=team, person=person) except TeamMember.DoesNotExist: pass else: team_member_form = initialize_form(TeamMemberForm, request, event=event, instance=team_member) if not team_member_form: team_member_form = initialize_form(TeamMemberForm, request, event=event, initial=initial_data) if request.method == 'POST': action = request.POST.get('action') if action in ['save-return', 'save-continue']: if team_member_form.is_valid(): creating_new = not team_member_form.instance.pk team_member = team_member_form.save() if creating_new: messages.success(request, _('The member was added to the team.')) else: messages.success(request, _('The team member was updated.')) if action == 'save-return': return redirect('intra_organizer_view', event.slug) elif action == 'save-continue': return redirect('intra_admin_team_member_view', event.slug, team_member.team.slug, team_member.person.id) else: messages.error(request, _('Please check the team_member_form.')) elif action == 'delete': if not team_member.pk: return HttpResponseNotFound() team_member.delete() messages.success(request, _('The member was removed from the team.')) return redirect('intra_organizer_view', event.slug) else: messages.error(request, _('Invalid action.')) vars.update( team_member_form=team_member_form, ) return render(request, 'intra_admin_team_member_view.pug', vars)
def tickets_admin_order_view(request, vars, event, order_id): order = get_object_or_404(Order, id=int(order_id), event=event) customer_form = initialize_form( CustomerForm, request, instance=order.customer, prefix='customer', ) order_form = initialize_form( AdminOrderForm, request, instance=order, prefix='order', readonly=True, ) order_product_forms = OrderProductForm.get_for_order(request, order, admin=True) can_mark_paid = order.is_confirmed and not order.is_paid and not order.is_cancelled can_resend = order.is_confirmed and order.is_paid and not order.is_cancelled can_cancel = order.is_confirmed and not order.is_cancelled can_uncancel = order.is_cancelled if request.method == 'POST': if customer_form.is_valid() and all( form.fields['count'].widget.attrs.get('readonly', False) or form.is_valid() for form in order_product_forms): def save(): customer_form.save() for form in order_product_forms: if form.fields['count'].widget.attrs.get( 'readonly', False): continue form.save() order.clean_up_order_products() if 'cancel' in request.POST and can_cancel: save() order.cancel() messages.success(request, 'Tilaus peruutettiin.') return redirect('tickets_admin_order_view', event.slug, order.pk) elif 'uncancel' in request.POST and can_uncancel: save() order.uncancel() messages.success(request, 'Tilaus palautettiin.') return redirect('tickets_admin_order_view', event.slug, order.pk) elif 'mark-paid' in request.POST and can_mark_paid: save() order.confirm_payment() messages.success(request, 'Tilaus merkittiin maksetuksi.') return redirect('tickets_admin_order_view', event.slug, order.pk) elif 'resend-confirmation' in request.POST and can_resend: save() order.send_confirmation_message('payment_confirmation') messages.success(request, 'Vahvistusviesti lähetettiin uudelleen.') return redirect('tickets_admin_order_view', event.slug, order.pk) elif 'save' in request.POST: save() messages.success(request, 'Muutokset tallennettiin.') else: messages.error(request, 'Tuntematon tai kielletty toiminto.') else: messages.error(request, 'Ole hyvä ja tarkista lomake.') vars.update( order=order, customer_form=customer_form, order_form=order_form, can_cancel=can_cancel, can_mark_paid=can_mark_paid, can_resend=can_resend, can_uncancel=can_uncancel, # XXX due to template being shared with public view, needs to be named "form" form=order_product_forms, ) # Slightly abusing the core.person.view entry type as there is no Person. # But the context field provides enough clue. emit('core.person.viewed', request=request, event=event) return render(request, 'tickets_admin_order_view.pug', vars)
def make_form(self, request, event): order = get_order(request, event) return initialize_form(CustomerForm, request, instance=order.customer)
def tickets_admin_order_view(request, vars, event, order_id): order = get_object_or_404(Order, id=int(order_id), event=event) customer_form = initialize_form(CustomerForm, request, instance=order.customer, prefix='customer', ) order_form = initialize_form(AdminOrderForm, request, instance=order, prefix='order', readonly=True, ) order_product_forms = OrderProductForm.get_for_order(request, order, admin=True) can_mark_paid = order.is_confirmed and not order.is_paid and not order.is_cancelled can_resend = order.is_confirmed and order.is_paid and not order.is_cancelled can_cancel = order.is_confirmed and not order.is_cancelled can_uncancel = order.is_cancelled if request.method == 'POST': if customer_form.is_valid() and all(form.fields['count'].widget.attrs.get('readonly', False) or form.is_valid() for form in order_product_forms): def save(): customer_form.save() for form in order_product_forms: if form.fields['count'].widget.attrs.get('readonly', False): continue form.save() order.clean_up_order_products() if 'cancel' in request.POST and can_cancel: save() order.cancel() messages.success(request, u'Tilaus peruutettiin.') return redirect('tickets_admin_order_view', event.slug, order.pk) elif 'uncancel' in request.POST and can_uncancel: save() order.uncancel() messages.success(request, u'Tilaus palautettiin.') return redirect('tickets_admin_order_view', event.slug, order.pk) elif 'mark-paid' in request.POST and can_mark_paid: save() order.confirm_payment() messages.success(request, u'Tilaus merkittiin maksetuksi.') return redirect('tickets_admin_order_view', event.slug, order.pk) elif 'resend-confirmation' in request.POST and can_resend: save() order.send_confirmation_message('payment_confirmation') messages.success(request, u'Vahvistusviesti lähetettiin uudelleen.') return redirect('tickets_admin_order_view', event.slug, order.pk) elif 'save' in request.POST: save() messages.success(request, u'Muutokset tallennettiin.') else: messages.error(request, u'Tuntematon tai kielletty toiminto.') else: messages.error(request, u'Ole hyvä ja tarkista lomake.') vars.update( order=order, customer_form=customer_form, order_form=order_form, can_cancel=can_cancel, can_mark_paid=can_mark_paid, can_resend=can_resend, can_uncancel=can_uncancel, # XXX due to template being shared with public view, needs to be named "form" form=order_product_forms, ) return render(request, 'tickets_admin_order_view.jade', vars)