def attendee_registration_by_collaborator(request, event_slug): event = Event.objects.filter(slug__iexact=event_slug).first() if not event: return handler404(request) attendee = NonRegisteredAttendee() form = AttendeeRegistrationByCollaboratorForm(request.POST or None, instance=attendee) if request.POST: if form.is_valid(): email = form.cleaned_data["email"] if EventUser.objects.filter(event=event, user__email__iexact=email).count() > 0: messages.error(request, _("The attendee has registered for this event, use correct form")) return HttpResponseRedirect(reverse("attendee_search", args=(event_slug,))) if EventUser.objects.filter(event=event, nonregisteredattendee__email__iexact=email).count() > 0: form.add_error('email', _("Email already registered for this event")) try: form.save() eventuser = EventUser(event=event, nonregisteredattendee=attendee, assisted=True) eventuser.save() if form.cleaned_data["is_installing"]: installer = InstallationAttendee(eventUser=eventuser, installation_additional_info=form.cleaned_data[ "installation_additional_info"]) installer.save() else: attendee = Attendee(eventUser=eventuser) attendee.save() messages.success(request, _('The attendee was successfully registered . Happy Hacking!')) return HttpResponseRedirect(reverse("attendee_search", args=(event_slug,))) except Exception: pass messages.error(request, _("The attendee couldn't be registered (check form errors)")) return render(request, 'registration/attendee/by-collaborator.html', update_event_info(event_slug, request, {'form': form}))
def attendee_registration_by_collaborator(request, event_slug): event = Event.objects.get(slug__iexact=event_slug) attendee = NonRegisteredAttendee() form = AttendeeRegistrationByCollaboratorForm(request.POST or None, instance=attendee) if request.POST: if form.is_valid(): email = form.cleaned_data["email"] if EventUser.objects.filter(event=event, user__email__iexact=email).count() > 0: messages.error(request, _("The attendee has registered for this event, use correct form")) return HttpResponseRedirect(reverse("attendee_search", args=(event_slug,))) if EventUser.objects.filter(event=event, nonregisteredattendee__email__iexact=email).count() > 0: form.add_error('email', _("Email already registered for this event")) try: form.save() eventuser = EventUser(event=event, nonregisteredattendee=attendee, assisted=True) eventuser.save() if form.cleaned_data["is_installing"]: installer = InstallationAttendee(eventUser=eventuser, installation_additional_info=form.cleaned_data[ "installation_additional_info"]) installer.save() else: attendee = Attendee(eventUser=eventuser) attendee.save() messages.success(request, _('The attendee was successfully registered . Happy Hacking!')) return HttpResponseRedirect(reverse("attendee_search", args=(event_slug,))) except Exception: pass messages.error(request, _("The attendee couldn't be registered (check form errors)")) return render(request, 'registration/attendee/by-collaborator.html', update_event_info(event_slug, {'form': form}))
def create_event(request): event_form = EventForm(request.POST or None, prefix='event') ContactsFormSet = modelformset_factory(Contact, form=ContactForm, can_delete=True) contacts_formset = ContactsFormSet(request.POST or None, prefix='contacts-form', queryset=Contact.objects.none()) EventDateFormset = modelformset_factory(EventDate, form=EventDateForm, formset=EventDateModelFormset, can_delete=True) event_date_formset = EventDateFormset(request.POST or None, prefix='event-date-form', queryset=EventDate.objects.none()) if request.POST: if event_form.is_valid() and contacts_formset.is_valid() and event_date_formset.is_valid(): organizer = None event_user = None the_event = None contacts = None event_dates = None try: the_event = event_form.save() event_user = EventUser.objects.create(user=request.user, event=the_event) organizer = create_organizer(event_user) contacts = contacts_formset.save(commit=False) event_dates = event_date_formset.save(commit=False) for a_contact in contacts: a_contact.event = the_event a_contact.save() for event_date in event_dates: event_date.event = the_event event_date.save() return HttpResponseRedirect(reverse("index", args=(the_event.slug,))) except Exception as e: logger.error(e) try: if organizer is not None: Organizer.delete(organizer) if event_user is not None: EventUser.delete(event_user) if the_event is not None: Event.delete(the_event) if contacts is not None: for a_contact in contacts: Contact.objects.delete(a_contact) if event_dates is not None: for event_date in event_dates: EventDate.objects.delete(event_date) except Exception: pass messages.error(request, _("There is a problem with your event. Please check the form for errors.")) return render(request, 'event/create.html', {'form': event_form, 'domain': request.get_host(), 'protocol': request.scheme, 'contacts_formset': contacts_formset, 'event_date_formset': event_date_formset})
def generic_registration(request, event_slug, registration_model, new_role_form, msg_success, msg_error, template): event = get_object_or_404(Event, slug__iexact=event_slug) if not event.registration_is_open: return render(request, 'registration/closed-registration.html', update_event_info(event_slug, request)) errors = [] event_user = EventUser.objects.filter(event=event, user=request.user).first() if not event_user: event_user = EventUser(event=event, user=request.user) new_role = registration_model.objects.filter(event_user=event_user) if new_role: # Ya esta registrado con ese "rol" messages.error(request, _("You are already registered for this event")) return HttpResponseRedirect(reverse("index", args=(event_slug,))) new_role = registration_model(event_user=event_user) if request.POST: event_user_form = EventUserRegistrationForm(request.POST, instance=event_user) new_role_form = new_role_form(request.POST, instance=new_role) forms = [event_user_form, new_role_form] if event_user_form.is_valid() and new_role_form.is_valid(): try: event_user = event_user_form.save() new_role = new_role_form.save() new_role.event_user = event_user new_role.save() # if not event_user.ticket: # try: # send_event_ticket(event_user) # event_user.ticket = True # event_user.save() # msg_success += unicode(_(". Please check your email for the corresponding ticket.")) # except Exception: # msg_success += unicode( # _(" but we couldn't send you your ticket. Please, check it out from the # menu.")) messages.success(request, msg_success) return HttpResponseRedirect('/event/' + event_slug) except Exception as e: logger.error(e) pass messages.error(request, msg_error) else: event_user_form = EventUserRegistrationForm(instance=event_user) new_role_form = new_role_form(instance=new_role) forms = [event_user_form, new_role_form] return render(request, template, update_event_info(event_slug, request, {'forms': forms, 'errors': errors, 'multipart': False}))
def create_event(request): event_form = EventForm(request.POST or None, prefix='event') ContactsFormSet = modelformset_factory(Contact, form=ContactForm, can_delete=True) contacts_formset = ContactsFormSet(request.POST or None, prefix='contacts-form', queryset=Contact.objects.none()) if request.POST: if event_form.is_valid() and contacts_formset.is_valid(): organizer = None eventUser = None the_event = None contacts = None try: the_event = event_form.save() eventUser = EventUser.objects.create(user=request.user, event=the_event) organizer = create_organizer(eventUser) contacts = contacts_formset.save(commit=False) for a_contact in contacts: a_contact.event = the_event a_contact.save() return HttpResponseRedirect('/event/' + the_event.slug) except Exception: if organizer is not None: Organizer.delete(organizer) if eventUser is not None: EventUser.delete(eventUser) if the_event is not None: Event.delete(the_event) if contacts is not None: for a_contact in contacts: Contact.objects.delete(a_contact) messages.error(request, _("There is a problem with your event. Please check the form for errors.")) return render(request, 'event/create.html', {'form': event_form, 'domain': request.get_host(), 'protocol': request.scheme, 'contacts_formset': contacts_formset}, context_instance=RequestContext(request))
def generic_registration(request, event_slug, registration_model, registration_form, msg_success, msg_error, template): event = Event.objects.filter(slug__iexact=event_slug).first() if not event: return handler404(request) if not event.registration_is_open: return render(request, 'registration/closed-registration.html', update_event_info(event_slug, request)) errors = [] eventUser = EventUser.objects.filter(event=event, user=request.user).first() if not eventUser: eventUser = EventUser(event=event, user=request.user) registration = registration_model.objects.filter(eventUser=eventUser) # FIXME: Chanchada installation = InstallationAttendee.objects.filter(eventUser=eventUser) if registration or installation: # Ya esta registrado con ese "rol" messages.error(request, _("You are already registered for this event")) return HttpResponseRedirect(reverse("index", args=(event_slug,))) registration = registration_model(eventUser=eventUser) if request.POST: eventUser_form = EventUserRegistrationForm(request.POST, instance=eventUser) registration_form = registration_form(request.POST, instance=registration) forms = [eventUser_form, registration_form] if eventUser_form.is_valid() and registration_form.is_valid(): try: eventUser = eventUser_form.save() # FIXME: Chanchada if registration_model is Attendee and registration_form.cleaned_data["is_installing"]: installation = InstallationAttendee(eventUser=eventUser, installation_additional_info=registration_form.cleaned_data[ "installation_additional_info"]) installation.save() else: registration = registration_form.save() registration.eventUser = eventUser registration.save() if not eventUser.ticket: try: send_event_ticket(eventUser, request.META.get('LANG')) eventUser.ticket = True eventUser.save() msg_success += unicode(_(". Please check your email for the corresponding ticket.")) except Exception: msg_success += unicode( _(" but we couldn't send you your ticket. Please, check it out from the menu.")) messages.success(request, msg_success) return HttpResponseRedirect('/event/' + event_slug) except Exception: pass messages.error(request, msg_error) else: eventUser_form = EventUserRegistrationForm(instance=eventUser) registration_form = registration_form(instance=registration) forms = [eventUser_form, registration_form] return render(request, template, update_event_info(event_slug, request, {'forms': forms, 'errors': errors, 'multipart': False}))
def generic_registration(request, event_slug, registration_model, registration_form, msg_success, msg_error, template): event = Event.objects.get(slug__iexact=event_slug) if not event.registration_is_open: return render(request, 'registration/closed-registration.html', update_event_info(event_slug)) errors = [] eventUser = EventUser.objects.filter(event=event, user=request.user).first() if not eventUser: eventUser = EventUser(event=event, user=request.user) registration = registration_model.objects.filter(eventUser=eventUser) # FIXME: Chanchada installation = InstallationAttendee.objects.filter(eventUser=eventUser) if registration or installation: # Ya esta registrado con ese "rol" messages.error(request, _("You are already registered for this event")) return HttpResponseRedirect(reverse("index", args=(event_slug,))) registration = registration_model(eventUser=eventUser) if request.POST: eventUser_form = EventUserRegistrationForm(request.POST, instance=eventUser) registration_form = registration_form(request.POST, instance=registration) forms = [eventUser_form, registration_form] if eventUser_form.is_valid() and registration_form.is_valid(): try: eventUser = eventUser_form.save() # FIXME: Chanchada if registration_model is Attendee and registration_form.cleaned_data["is_installing"]: installation = InstallationAttendee(eventUser=eventUser, installation_additional_info=registration_form.cleaned_data[ "installation_additional_info"]) installation.save() else: registration = registration_form.save() registration.eventUser = eventUser registration.save() if not eventUser.ticket: try: send_event_ticket(eventUser, request.META.get('LANG')) eventUser.ticket = True eventUser.save() msg_success += unicode(_(". Please check your email for the corresponding ticket.")) except Exception: msg_success += unicode(_(" but we couldn't send you your ticket. Please, check it out from the menu.")) messages.success(request, msg_success) return HttpResponseRedirect('/event/' + event_slug) except Exception: pass messages.error(request, msg_error) else: eventUser_form = EventUserRegistrationForm(instance=eventUser) registration_form = registration_form(instance=registration) forms = [eventUser_form, registration_form] return render(request, template, update_event_info(event_slug, {'forms': forms, 'errors': errors, 'multipart': False}))