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.filter(slug__iexact=event_slug).first() if not event: return handler404(request) if not event.talk_proposal_is_open: messages.error(request, _("The talk 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,))) errors = [] new_activity, new_proposal = None, None if pk: proposal = TalkProposal.objects.filter(pk=pk).first() if not proposal: return handler404(request) 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, request, {'forms': forms, 'errors': errors, 'multipart': False}))
def talk_registration(request, event_slug, pk): errors = [] error = False event = Event.objects.filter(slug__iexact=event_slug).first() if not event: return handler404(request) # FIXME: Esto es lo que se llama una buena chanchada! post = generate_datetime(request, event) # Fin de la chanchada talk_form = TalkForm(event_slug, post) proposal = TalkProposal.objects.filter(pk=pk).first() if not proposal: return handler404(request) forms = [talk_form] if request.POST: if talk_form.is_valid() and \ Activity.room_available(request=request, instance=talk_form.instance, event_slug=event_slug): try: proposal.confirmed_talk = True activity = proposal.activity activity.start_date = post['start_date'] activity.end_date = post['end_date'] room = Room.objects.filter(pk=request.POST.get('room')).first() if not room: return handler404(request) activity.room = room activity.confirmed = True activity.save() proposal.save() messages.success(request, _("The talk was registered successfully!")) return HttpResponseRedirect(reverse("talk_detail", args=[event_slug, proposal.pk])) except Exception: if proposal.activity.confirmed: proposal.activity.confirmed = False proposal.activity.save() if proposal.confirmed_talk: proposal.confirmed_talk = False proposal.save() errors = get_forms_errors(forms) error = True if errors: messages.error(request, _("The talk couldn't be registered (check form errors)")) comments = Comment.objects.filter(activity=proposal.activity) vote = Vote.objects.get_for_user(proposal, request.user) score = Vote.objects.get_score(proposal) render_dict = dict(comments=comments, comment_form=CommentForm(), user=request.user, proposal=proposal) if vote or score: render_dict.update({'vote': vote, 'score': score}) render_dict.update({'multipart': False, 'errors': errors, 'form': talk_form, 'error': error}) return render(request, 'activities/talks/detail.html', update_event_info(event_slug, request, render_dict))
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}))
def talk_registration(request, event_slug, pk): errors = [] error = False event = Event.objects.get(slug__iexact=event_slug) # FIXME: Esto es lo que se llama una buena chanchada! post = generate_datetime(request, event) # Fin de la chanchada talk_form = TalkForm(event_slug, post) proposal = TalkProposal.objects.get(pk=pk) forms = [talk_form] if request.POST: if talk_form.is_valid() and \ Activity.room_available(request=request, instance=talk_form.instance, event_slug=event_slug): try: proposal.confirmed_talk = True activity = proposal.activity activity.start_date = post['start_date'] activity.end_date = post['end_date'] activity.room = Room.objects.get(pk=request.POST.get('room', None)) activity.confirmed = True activity.save() proposal.save() messages.success(request, _("The talk was registered successfully!")) return HttpResponseRedirect(reverse("talk_detail", args=[event_slug, proposal.pk])) except Exception: if proposal.activity.confirmed: proposal.activity.confirmed = False proposal.activity.save() if proposal.confirmed_talk: proposal.confirmed_talk = False proposal.save() errors = get_forms_errors(forms) error = True if errors: messages.error(request, _("The talk couldn't be registered (check form errors)")) comments = Comment.objects.filter(activity=proposal.activity) vote = Vote.objects.get_for_user(proposal, request.user) score = Vote.objects.get_score(proposal) render_dict = dict(comments=comments, comment_form=CommentForm(), user=request.user, proposal=proposal) if vote or score: render_dict.update({'vote': vote, 'score': score}) render_dict.update({'multipart': False, 'errors': errors, 'form': talk_form, 'error': error}) return render(request, 'activities/talks/detail.html', update_event_info(event_slug, render_dict))
def clean(self): obj = self.instance if obj.start_date or obj.end_date: Activity.room_available(error=True, instance=obj, event_slug=obj.event.slug)