Exemple #1
0
def talk_registration(request, sede_url, pk):
    errors = []
    error = False
    talk = None
    sede = Sede.objects.get(url__iexact=sede_url)

    # FIXME: Esto es lo que se llama una buena chanchada!
    post = None
    if request.POST:
        start_time = datetime.datetime.strptime(request.POST.get('start_date', None), '%H:%M')
        end_time = datetime.datetime.strptime(request.POST.get('end_date', None), '%H:%M')

        start_time_posta = datetime.datetime.combine(sede.date, start_time.time())
        end_time_posta = datetime.datetime.combine(sede.date, end_time.time())

        post = request.POST.copy()

        post['start_date'] = start_time_posta.strftime('%Y-%m-%d %H:%M:%S')
        post['end_date'] = end_time_posta.strftime('%Y-%m-%d %H:%M:%S')

    # Fin de la chanchada

    talk_form = TalkForm(sede_url, post)
    proposal = TalkProposal.objects.get(pk=pk)
    forms = [talk_form]
    if request.POST:
        if talk_form.is_valid() and room_available(request, talk_form.instance, sede_url):
            try:
                proposal.confirmed = True
                proposal.save()
                talk = talk_form.save()
                talk.talk_proposal = proposal
                talk.save()
                messages.success(request, _("The talk was registered successfully!"))
                return HttpResponseRedirect(reverse("talk_detail", args=[sede_url, talk.pk]))
            except Exception:
                if talk is not None:
                    Talk.delete(talk)
                if proposal.confirmed:
                    proposal.confirmed = False
                    proposal.save()
        errors = get_forms_errors(forms)
        error = True
        if errors:
            messages.error(request, _("The talk wasn't registered successfully (check form errors)"))
    comments = Comment.objects.filter(proposal=proposal)
    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,
                  'talks/detail.html',
                  update_sede_info(sede_url, render_dict))
Exemple #2
0
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))
Exemple #3
0
def proposal_detail(request, event_slug, pk):
    proposal = TalkProposal.objects.get(pk=pk)
    comments = Comment.objects.filter(activity=proposal.activity)
    render_dict = dict(comments=comments, comment_form=CommentForm(), proposal=proposal)
    vote = Vote.objects.get_for_user(proposal, request.user)
    score = Vote.objects.get_score(proposal)
    if vote or score:
        render_dict.update({'vote': vote, 'score': score})
    if proposal.confirmed_talk:
        render_dict.update({'talk': proposal, 'form': TalkForm(event_slug, instance=proposal.activity),
                            'form_presentation': PresentationForm(instance=proposal), 'errors': []})
    else:
        render_dict.update({'form': TalkForm(event_slug, instance=proposal.activity), 'errors': []})
    return render(request, 'activities/talks/detail.html', update_event_info(event_slug, render_dict))
Exemple #4
0
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))
Exemple #5
0
def proposal_detail(request, sede_url, pk):
    proposal = TalkProposal.objects.get(pk=pk)
    comments = Comment.objects.filter(proposal=proposal)
    render_dict = dict(comments=comments, comment_form=CommentForm(), user=request.user, proposal=proposal)
    vote = Vote.objects.get_for_user(proposal, request.user)
    score = Vote.objects.get_score(proposal)
    if vote or score:
        render_dict.update({'vote': vote, 'score': score})
    if proposal.confirmed:
        talk = Talk.objects.get(talk_proposal=proposal)
        render_dict.update({'talk': talk, 'form': TalkForm(sede_url, instance=talk),
                            'form_presentation': PresentationForm(instance=proposal), 'errors': []})
    else:
        render_dict.update({'form': TalkForm(sede_url), 'errors': []})
    return render(request, 'talks/detail.html', update_sede_info(sede_url, render_dict))
Exemple #6
0
def talks(request, sede_url):
    sede = Sede.objects.get(url__iexact=sede_url)
    talks_list = Talk.objects.filter(talk_proposal__sede=sede)
    proposals = TalkProposal.objects.filter(sede=sede)
    for proposal in proposals:
        setattr(proposal, 'form', TalkForm(sede_url))
        setattr(proposal, 'errors', [])
    return render(request, 'talks/talks_home.html',
                  update_sede_info(sede_url, {'talks': talks_list, 'proposals': proposals, 'sede': sede}, sede))
Exemple #7
0
def activities(request, event_slug):
    event = Event.objects.get(slug__iexact=event_slug)
    talks_list, proposals, activities_not_confirmed, activities_confirmed = [], [], [], []
    activities_list = Activity.objects.filter(event=event)
    for activity in activities_list:
        talk_proposal = TalkProposal.objects.filter(activity=activity).first()
        if talk_proposal:
            talks_list.append(talk_proposal) if talk_proposal.confirmed_talk else proposals.append(talk_proposal)
        else:
            activities_confirmed.append(activity) if activity.confirmed else activities_not_confirmed.append(activity)
    for proposal in proposals:
        setattr(proposal, 'form', TalkForm(event_slug, instance=proposal.activity))
        setattr(proposal, 'errors', [])
    return render(request, 'activities/activities_home.html',
                  update_event_info(event_slug, {'talks': talks_list, 'proposals': proposals,
                                                 'activities_confirmed': activities_confirmed,
                                                 'activities_not_confirmed': activities_not_confirmed,
                                                 'event': event}, event))