Пример #1
0
def signup_admin_editsignup(request, urlname, signupid, id):
    conference = get_authenticated_conference(request, urlname)
    signup = get_object_or_404(Signup, conference=conference, pk=signupid)

    if id == 'new':
        attendeesignup = AttendeeSignup(signup=signup)
    else:
        attendeesignup = get_object_or_404(AttendeeSignup, signup=signup, pk=id)

    reg = attendeesignup.attendee

    if request.method == 'POST' and request.POST['submit'] == 'Delete':
        reglog(reg, "Admin removed response to signup {}".format(signup.id), request.user)
        attendeesignup.delete()
        return HttpResponseRedirect('../../')
    elif request.method == 'POST':
        form = SignupAdminEditSignupForm(signup, isnew=(id == 'new'), instance=attendeesignup, data=request.POST)
        if form.is_valid():
            if (not signup.options) and (not form.cleaned_data['choice']):
                # Yes/no signup changed to no means we actually delete the
                # record completeliy.
                reglog(reg, "Admin removed response to signup {}".format(signup.id), request.user)
                attendeesignup.delete()
            else:
                form.save()
                reglog(reg, "Admin updated response to signup {}".format(signup.id), request.user)
            return HttpResponseRedirect('../../')
    else:
        form = SignupAdminEditSignupForm(signup, isnew=(id == 'new'), instance=attendeesignup)

    return render(request, 'confreg/admin_backend_form.html', {
        'basetemplate': 'confreg/confadmin_base.html',
        'conference': conference,
        'form': form,
        'what': 'attendee signup',
        'cancelurl': '../../',
        'allow_delete': (id != 'new'),
        'breadcrumbs': (
            ('/events/admin/{0}/signups/'.format(conference.urlname), 'Signups'),
            ('/events/admin/{0}/signups/{1}/'.format(conference.urlname, signup.id), signup.title),
        ),
        'helplink': 'signups',
    })
Пример #2
0
def signup(request, urlname, signupid):
    conference = get_conference_or_404(urlname)
    signup = get_object_or_404(Signup, conference=conference, id=signupid)
    reg = _check_signup_permissions(request, signup)

    attendee_signup = AttendeeSignup.objects.filter(signup=signup, attendee=reg)
    if len(attendee_signup) == 1:
        attendee_signup = attendee_signup[0]
    else:
        attendee_signup = None

    if signup.visible and attendee_signup:
        # Include the results
        cursor = connection.cursor()
        cursor.execute("SELECT firstname || ' ' || lastname FROM confreg_conferenceregistration r INNER JOIN confwiki_attendeesignup a ON a.attendee_id=r.id WHERE a.signup_id=%(signup)s AND r.payconfirmedat IS NOT NULL AND r.canceledat IS NULL ORDER BY lastname, firstname", {
            'signup': signup.id,
        })
        current = [r[0] for r in cursor.fetchall()]
    else:
        current = None

    if signup.deadline and signup.deadline < timezone.now():
        # This one is closed
        return render_conference_response(request, conference, 'wiki', 'confwiki/signup.html', {
            'closed': True,
            'signup': signup,
            'attendee_signup': attendee_signup,
            'current': current,
        })

    # Signup is active, so build a form.
    if request.method == 'POST':
        form = SignupSubmitForm(signup, attendee_signup, data=request.POST)
        if form.is_valid():
            if form.cleaned_data['choice'] == '':
                # Remove instead!
                if attendee_signup:
                    if signup.notify_changes:
                        send_conference_notification_template(
                            conference,
                            'Signup response removed from {}'.format(signup.title),
                            'confwiki/mail/admin_notify_signup_delete.txt',
                            {
                                'conference': conference,
                                'signup': signup,
                                'attendeesignup': attendee_signup,
                            },
                        )
                    attendee_signup.delete()
                    reglog(reg, "Deleted response to signup {}".format(signup.id), request.user)
                    messages.info(request, "Your response has been deleted.")
                # If it did not exist, don't bother deleting it
            else:
                # Store an actual response
                if attendee_signup:
                    oldchoice = attendee_signup.choice
                    attendee_signup.choice = form.cleaned_data['choice']
                    if signup.notify_changes and oldchoice != attendee_signup.choice:
                        send_conference_notification_template(
                            conference,
                            'Signup response updated for {}'.format(signup.title),
                            'confwiki/mail/admin_notify_signup_modify.txt',
                            {
                                'conference': conference,
                                'signup': signup,
                                'attendeesignup': attendee_signup,
                                'oldchoice': oldchoice,
                            },
                        )
                    reglog(reg, "Updated response to signup {} from {} to {}".format(
                        signup.id,
                        oldchoice,
                        attendee_signup.choice,
                    ), request.user)
                else:
                    attendee_signup = AttendeeSignup(attendee=reg,
                                                     signup=signup,
                                                     choice=form.cleaned_data['choice'])
                    if signup.notify_changes:
                        send_conference_notification_template(
                            conference,
                            'Attendee signed up for {}'.format(signup.title),
                            'confwiki/mail/admin_notify_signup.txt',
                            {
                                'conference': conference,
                                'signup': signup,
                                'attendeesignup': attendee_signup,
                            },
                        )
                    reglog(reg, "Recorded response to signup {}".format(signup.id), request.user)
                attendee_signup.save()
                messages.info(request, "Your response has been stored. Thank you!")

            return HttpResponseRedirect('../../')
    else:
        form = SignupSubmitForm(signup, attendee_signup)

    return render_conference_response(request, conference, 'wiki', 'confwiki/signup.html', {
        'closed': False,
        'signup': signup,
        'attendee_signup': attendee_signup,
        'current': current,
        'form': form,
    })