Exemple #1
0
def set_present(request, event_url_name, shift_pk):
    event, job, shift, helper = get_or_404(event_url_name, shift_pk=shift_pk)

    # check permission
    if not has_access(request.user, event, ACCESS_GIFTS_HANDLE_PRESENCE):
        return nopermission(request)

    # check if active
    if not event.gifts:
        return notactive(request)

    form = PresentForm(request.POST or None, shift=shift, user=request.user)

    if form.is_valid():
        form.save()

        messages.success(request, _("Presence was saved"))

        return HttpResponseRedirect(reverse('gifts:set_present',
                                    args=[event.url_name, shift.pk, ]))

    context = {'event': event,
               'shift': shift,
               'form': form}
    return render(request, 'gifts/set_present.html', context)
Exemple #2
0
def edit_badge(request, event_url_name, helper_pk):
    event, job, shift, helper = get_or_404(event_url_name, helper_pk=helper_pk)

    # check permission
    if not event.is_admin(request.user):
        return nopermission(request)

    # check if badge system is active
    if not event.badges:
        return notactive(request)

    form = BadgeForm(request.POST or None, request.FILES or None,
                     instance=helper.badge)

    if form.is_valid():
        form.save()

        return HttpResponseRedirect(reverse('view_helper',
                                            args=[event_url_name, helper.pk]))

    # render page
    context = {'event': event,
               'helper': helper,
               'form': form}
    return render(request, 'badges/edit_badge.html', context)
Exemple #3
0
def warnings(request, event_url_name, job_pk):
    event, job, shift, helper = get_or_404(event_url_name, job_pk)

    # check permission
    if not event.is_admin(request.user):
        return nopermission(request)

    # check if badge system is active
    if not event.badges:
        return notactive(request)

    # TODO: check if possible

    helpers = warnings_for_job(job)

    # render
    context = {'event': event, 'helpers': helpers}
    return render(request, 'badges/warnings.html', context)
Exemple #4
0
def generate(request, event_url_name, job_pk=None, generate_all=False):
    event, job, shift, helper = get_or_404(event_url_name, job_pk)

    # check permission
    if not event.is_admin(request.user):
        return nopermission(request)

    # check if badge system is active
    if not event.badges:
        return notactive(request)

    # TODO: check if possible, show error page

    # skip already printed badges?
    skip_printed = event.badge_settings.barcodes and not generate_all

    # start generation
    result = tasks.generate_badges.delay(event.pk, job_pk, skip_printed)

    # name
    name = None
    if job:
        if skip_printed:
            name = _("{} (only unregistered)").format(job.name)
        else:
            name = _("{} (all)").format(job.name)
    else:
        if skip_printed:
            name = _("All unregistered badges")
        else:
            name = _("Really all badges")

    # add to session
    if 'badge_tasks' not in request.session:
        request.session['badge_tasks'] = []

    task = create_task_dict(result.task_id, name, event)

    request.session['badge_tasks'].insert(0, task)
    request.session.modified = True

    return HttpResponseRedirect(reverse('badges:index', args=[event.url_name]))
Exemple #5
0
def generate(request,
             event_url_name,
             job_pk=None,
             generate=None,
             skip_printed=True):
    """
    Schedule a job to generates badges and handle the "frontend things".

    Parameters:
    :param job_pk: If set, the badges for this job will be generated
    :param generate: `job`, `special` or `all`
    :param skip_printed: Skip already registered badges
    """
    event, job, shift, helper = get_or_404(event_url_name, job_pk)

    # validate generate parameter
    if generate not in ["job", "special", "all"]:
        raise ValueError("Invalid parameter generate")
    if generate == "job" and not job:
        raise ValueError("Job missing")

    # check permission
    if not has_access(request.user, event, ACCESS_BADGES_GENERATE):
        return nopermission(request)

    # check if badge system is active
    if not event.badges:
        return notactive(request)

    # TODO: check if possible, show error page

    # if we do not have barcodes, we cannot skip printed badges
    if not event.badge_settings.barcodes:
        skip_printed = False

    # start generation
    result = tasks.generate_badges.delay(event.pk, job_pk, generate,
                                         skip_printed)

    # name to be displayed in web interface
    name = None
    if job:
        if skip_printed:
            name = _("{} (only unregistered)").format(job.name)
        else:
            name = _("{} (all)").format(job.name)
    elif generate == "special":
        if skip_printed:
            name = _("Special badges (only unregistered)")
        else:
            name = _("Special badges (all)")
    else:
        if skip_printed:
            name = _("All unregistered badges")
        else:
            name = _("Really all badges")

    # add to session
    if 'badge_tasks' not in request.session:
        request.session['badge_tasks'] = []

    task = create_task_dict(result.task_id, name, event)

    request.session['badge_tasks'].insert(0, task)
    request.session.modified = True

    return HttpResponseRedirect(reverse('badges:index', args=[event.url_name]))