def edit_event(request, event_slug): event = Event.objects.filter(slug__iexact=event_slug).first() if not event: return handler404(request) event_form = EventForm(request.POST or None, prefix='event', instance=event) ContactsFormSet = modelformset_factory(Contact, form=ContactForm, can_delete=True) contacts_formset = ContactsFormSet(request.POST or None, prefix='contacts-form', queryset=event.contacts.all()) if request.POST: if event_form.is_valid() and contacts_formset.is_valid(): try: the_event = event_form.save() contacts = contacts_formset.save(commit=False) for a_contact in contacts: a_contact.event = the_event contacts_formset.save() return HttpResponseRedirect('/event/' + the_event.slug) 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', update_event_info(event_slug, request, {'form': event_form, 'domain': request.get_host(), 'protocol': request.scheme, 'contacts_formset': contacts_formset}), context_instance=RequestContext(request))
def edit_event(request, event_slug): event = Event.objects.get(slug__iexact=event_slug) event_form = EventForm(request.POST or None, prefix='event', instance=event) ContactsFormSet = modelformset_factory(Contact, form=ContactForm, can_delete=True) contacts_formset = ContactsFormSet(request.POST or None, prefix='contacts-form', queryset=event.contacts.all()) if request.POST: if event_form.is_valid() and contacts_formset.is_valid(): try: the_event = event_form.save() contacts = contacts_formset.save(commit=False) for a_contact in contacts: a_contact.event = the_event contacts_formset.save() return HttpResponseRedirect('/event/' + the_event.slug) 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', update_event_info(event_slug, {'form': event_form, 'domain': request.get_host(), 'protocol': request.scheme, 'contacts_formset': contacts_formset}), context_instance=RequestContext(request))
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 EventCreate(request): """Event Creation module""" if request.user.is_authenticated(): if request.method == 'POST': # If the form has been submitted event_form = EventForm( request.POST) # A form bound to the POST data if event_form.is_valid(): new_event = event_form.save() defineRole(request.user, new_event, 'E') # return render_to_response('add_teams.html') # Redirect after POST # return redirect('addTeam', eid = new_event.pk) # addTeam(request , event_id = new_event.pk) url = "/events/add/" + str(new_event.pk) return HttpResponseRedirect(url) else: event_form = EventForm() # An unbound form return render_to_response('event_form.html', { 'event_form': event_form, }, context_instance=RequestContext(request)) else: return render_to_response('errorpage.html')
def edit_event(request, event_slug): event = get_object_or_404(Event, slug__iexact=event_slug) event_form = EventForm(request.POST or None, prefix='event', instance=event) ContactsFormSet = modelformset_factory(Contact, form=ContactForm, can_delete=True) contacts_formset = ContactsFormSet(request.POST or None, prefix='contacts-form', queryset=event.contacts.all()) 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.filter(event=event)) if request.POST: if event_form.is_valid() and contacts_formset.is_valid() and event_date_formset.is_valid(): try: the_event = event_form.save() contacts = contacts_formset.save(commit=False) event_dates = event_date_formset.save(commit=False) for a_contact in contacts: a_contact.event = the_event for event_date in event_dates: event_date.event = the_event contacts_formset.save() event_date_formset.save() return HttpResponseRedirect(reverse("index", args=(the_event.slug,))) except Exception as e: logger.error(e) pass messages.error(request, _("There is a problem with your event. Please check the form for errors.")) return render(request, 'event/create.html', update_event_info(event_slug, request, {'form': event_form, 'domain': request.get_host(), 'protocol': request.scheme, 'contacts_formset': contacts_formset, 'event_date_formset': event_date_formset}))
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 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 EventCreate(request): """Event Creation module""" if request.user.is_authenticated(): if request.method == 'POST': # If the form has been submitted event_form = EventForm(request.POST) # A form bound to the POST data if event_form.is_valid(): new_event = event_form.save() defineRole(request.user,new_event,'E') # return render_to_response('add_teams.html') # Redirect after POST # return redirect('addTeam', eid = new_event.pk) # addTeam(request , event_id = new_event.pk) url = "/events/add/"+str(new_event.pk) return HttpResponseRedirect(url) else: event_form = EventForm() # An unbound form return render_to_response('event_form.html', { 'event_form': event_form, },context_instance=RequestContext(request)) else: return render_to_response('errorpage.html')