def activity(request, event_slug, pk=None): event = Event.objects.get(slug__iexact=event_slug) post = generate_datetime(request, event) errors = [] new_activity = None activity = Activity.objects.get(pk=pk) if pk else Activity(event=event) activity_form = ActivityCompleteForm(event_slug, post or None, instance=activity) forms = [activity_form] if request.POST: if activity_form.is_valid() and \ Activity.room_available(request=request, instance=activity_form.instance, event_slug=event_slug): try: activity = activity_form.save() activity.confirmed = True activity.start_date = post['start_date'] activity.end_date = post['end_date'] activity.room = Room.objects.get(pk=request.POST.get('room', None)) activity.save() messages.success(request, _("The activity has been registered successfully")) return HttpResponseRedirect(reverse('activities', args=[event_slug])) except Exception: if new_activity is not None: Activity.delete(new_activity) messages.error(request, _("The activity couldn't be registered (check form errors)")) errors = get_forms_errors(forms) return render(request, 'activities/activity.html', update_event_info(event_slug, {'forms': forms, 'errors': errors, 'multipart': False}))
def activity_proposal(request, event_slug): event = get_object_or_404(Event, slug__iexact=event_slug) if not event.activity_proposal_is_open: messages.error(request, _( "The activity proposal is already closed or the event is not accepting proposals through this " + "page. Please contact the Event Organization Team to submit it.")) return HttpResponseRedirect(reverse('index', args=(event_slug,))) activity = Activity(event=event, status='1') activity_form = ActivityProposalForm(request.POST or None, request.FILES or None, instance=activity) if request.POST: if activity_form.is_valid(): try: activity = activity_form.save() return HttpResponseRedirect(reverse('image_cropping', args=(event_slug, activity.pk))) except Exception as e: logger.error(e) pass messages.error(request, _("There was a problem submitting the proposal. Please check the form for errors.")) return render(request, 'activities/proposal.html', update_event_info(event_slug, request, {'form': activity_form, 'errors': [], 'multipart': True}, event=event))
def talk_proposal(request, event_slug, pk=None): event = Event.objects.get(slug__iexact=event_slug) if not event.talk_proposal_is_open: messages.error(request, _("The talk proposal is already close or the event is not accepting proposals through this" "page. Please contact the Event Organization Team to submit it.")) return HttpResponseRedirect(reverse('index', args=(event_slug,))) errors = [] new_activity, new_proposal = None, None if pk: proposal = TalkProposal.objects.get(pk=pk) activity = proposal.activity else: activity = Activity(event=event) proposal = TalkProposal(activity=activity) activity_form = ActivityForm(request.POST or None, instance=activity) proposal_form = TalkProposalForm(request.POST or None, request.FILES or None, instance=proposal) forms = [activity_form, proposal_form] if request.POST: if activity_form.is_valid(): try: new_activity = activity_form.save() if proposal_form.is_valid(): new_proposal = proposal_form.save() new_proposal.activity = new_activity new_proposal.save() return HttpResponseRedirect(reverse('image_cropping', args=(event_slug, proposal.pk))) except Exception: pass if new_activity is not None: Activity.delete(new_activity) if new_proposal is not None: TalkProposal.delete(new_proposal) messages.error(request, _("The proposal couldn't be registered (check form errors)")) errors = get_forms_errors(forms) return render(request, 'activities/talks/proposal.html', update_event_info(event_slug, {'forms': forms, 'errors': errors, 'multipart': False}))