示例#1
0
def lecture_update(request, lecture_id=None):
    """
    Staff member can add lecture for other user, can edit all lectures
    """
    zosia = Zosia.objects.find_active()
    kwargs = {}
    ctx = {}

    if lecture_id:
        lecture = get_object_or_404(Lecture, pk=lecture_id)
        kwargs['instance'] = lecture
        ctx['object'] = lecture

    form = LectureAdminForm(request.POST or None, **kwargs)
    ctx['form'] = form

    if request.method == 'POST':
        if form.is_valid():
            lecture = form.save(commit=False)
            lecture.zosia = zosia
            lecture.save()
            messages.success(request, _("Lecture has been saved."))
            return redirect('lectures_all_staff')
        else:
            messages.error(request, errors_format(form))

    return render(request, 'lectures/add.html', ctx)
示例#2
0
def lecture_add(request):
    """
    participant can add his own lecture
    """
    zosia = Zosia.objects.find_active()
    if not zosia.is_lectures_open:
        messages.error(request, _("Call for paper is not open right now!"))
        return redirect(reverse('index'))

    form = LectureForm(request.POST or None)
    ctx = {'form': form}

    if request.method == 'POST':
        if form.is_valid():
            lecture = form.save(commit=False)
            lecture.zosia = zosia
            lecture.author = request.user
            lecture.save()
            messages.success(
                request,
                _("Lecture has been saved, it'll be displayed after it's accepted by organizers.")
            )
            return redirect('lectures_index')
        else:
            messages.error(request, errors_format(form))

    return render(request, 'lectures/add.html', ctx)
示例#3
0
def update(request, question_id=None):
    kwargs = {}
    if question_id is not None:
        question = get_object_or_404(QA, pk=question_id)
        kwargs['instance'] = question
    else:
        question = None

    form = QAForm(request.POST or None, **kwargs)

    if request.method == 'POST':
        if form.is_valid():
            form.save()
            return redirect('questions_index_staff')
        else:
            messages.error(request, errors_format(form))

    ctx = {'form': form, 'question': question}
    return render(request, 'questions/update.html', ctx)
示例#4
0
def register(request):
    zosia = Zosia.objects.find_active_or_404()

    if not zosia.is_registration_open:
        messages.error(request, _('Registration for ZOSIA is not open yet'))
        return redirect(reverse('index'))

    user_prefs = UserPreferences.objects.filter(zosia=zosia,
                                                user=request.user).first()

    if zosia.is_registration_over and user_prefs is None:
        messages.error(request, _('You missed registration for ZOSIA'))
        return redirect(reverse('index'))

    ctx = {
        'field_dependencies': PAYMENT_GROUPS,
        'payed': False,
        'zosia': zosia
    }
    form_args = {}

    if user_prefs is not None:
        ctx['object'] = user_prefs
        form_args['instance'] = user_prefs

    form = UserPreferencesForm(request.user, request.POST or None, **form_args)
    ctx['form'] = form

    if user_prefs and user_prefs.payment_accepted:
        ctx['payed'] = True
        form.disable()

    if request.method == 'POST':
        if form.is_valid():
            form.call(zosia)
            messages.success(request, _("Preferences saved!"))

            return redirect(reverse('accounts_profile') + '#zosia')
        else:
            messages.error(request, errors_format(form))

    return render(request, 'users/register.html', ctx)
示例#5
0
def update(request, sponsor_id=None):
    ctx = {}
    kwargs = {}
    if sponsor_id is not None:
        sponsor = get_object_or_404(Sponsor, pk=sponsor_id)
        ctx['object'] = sponsor
        kwargs['instance'] = sponsor

    form = SponsorForm(request.POST or None, request.FILES or None, **kwargs)
    ctx['form'] = form
    ctx['s3_objects'] = list_bucket_objects(BUCKET_NAME)
    ctx['bucket_url'] = BUCKET_URL

    if request.method == 'POST':
        if form.is_valid():
            form.save()
            messages.success(request, _("Form saved!"))
            return redirect(reverse('sponsors_index'))
        else:
            messages.error(request, errors_format(form))

    return render(request, 'sponsors/update.html', ctx)
示例#6
0
def user_preferences_edit(request, pk=None):
    ctx = {}
    kwargs = {}

    if pk is not None:
        user_preferences = get_object_or_404(UserPreferences, pk=pk)
        ctx['object'] = user_preferences
        kwargs['instance'] = user_preferences

    form = UserPreferencesAdminForm(request.POST or None, **kwargs)
    ctx['form'] = form

    if request.method == 'POST':
        if form.is_valid():
            form.save()
            messages.success(request, _("Form saved!"))

            return redirect(reverse('user_preferences_index'))
        else:
            messages.error(request, errors_format(form))

    return render(request, 'users/user_preferences_edit.html', ctx)