Exemplo n.º 1
0
def task_list_detailed(request, username):
    context = {}
    current_tasks = Task.objects.filter(date__year=Edition.get_current_year())
    # get the requested users tasks
    context['tasks'] = current_tasks.filter(volunteers__user__username=username)
    context['profile_user'] = User.objects.filter(username=username)[0]
    context['volunteer'] = Volunteer.objects.filter(user__username=username)[0]

    if request.POST:
        # create the HttpResponse object with the appropriate PDF headers.
        context.update({ 'pagesize':'A4'})
        return render_to_pdf(request, 'volunteers/tasks_detailed.html', context)

    return render(request, 'volunteers/tasks_detailed.html', context)
Exemplo n.º 2
0
def profile_detail(request, username,
    template_name=userena_settings.USERENA_PROFILE_DETAIL_TEMPLATE,
    extra_context=None, **kwargs):
    """
        Detailed view of an user.

        :param username:
            String of the username of which the profile should be viewed.

        :param template_name:
            String representing the template name that should be used to display
            the profile.

        :param extra_context:
            Dictionary of variables which should be supplied to the template. The
            ``profile`` key is always the current profile.

        **Context**

        ``profile``
            Instance of the currently viewed ``Profile``.
    """
    user = get_object_or_404(get_user_model(), username__iexact=username)
    current_tasks = Task.objects.filter(date__year=Edition.get_current_year())

    profile_model = get_profile_model()
    try:
        profile = user.get_profile()
    except profile_model.DoesNotExist:
        profile = profile_model.objects.create(user=user)

    if not profile.can_view_profile(request.user):
        raise PermissionDenied
    if not extra_context: extra_context = dict()
    extra_context['profile'] = user.get_profile()
    extra_context['tasks'] = current_tasks.filter(volunteers__user=user)
    extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL
    return ExtraContextTemplateView.as_view(template_name=template_name, extra_context=extra_context)(request)
Exemplo n.º 3
0
def task_list(request):
    # get the signed in volunteer
    volunteer = Volunteer.objects.get(user=request.user)
    is_dr_manhattan, dr_manhattan_task_sets = volunteer.detect_dr_manhattan()
    dr_manhattan_task_ids = [x.id for x in set.union(*dr_manhattan_task_sets)] if dr_manhattan_task_sets else []
    current_tasks = Task.objects.filter(date__year=Edition.get_current_year())
    ok_tasks = current_tasks.exclude(id__in=dr_manhattan_task_ids)
    throwaway = current_tasks.order_by('date').distinct('date')
    days = [x.date for x in throwaway]

    # when the user submitted the form
    if request.method == 'POST':
        # get the checked tasks
        task_ids = request.POST.getlist('task')

        # checked boxes, add the volunteer to the tasks when he/she is not added
        for task in Task.objects.filter(id__in=task_ids):
            VolunteerTask.objects.get_or_create(task=task, volunteer=volunteer)

        # unchecked boxes, delete him/her from the task
        for task in Task.objects.exclude(id__in=task_ids):
            VolunteerTask.objects.filter(task=task, volunteer=volunteer).delete()

        # show success message when enabled
        if userena_settings.USERENA_USE_MESSAGES:
            messages.success(request, _('Your tasks have been updated.'), fail_silently=True)

        # redirect to prevent repost
        return redirect('/tasks')

    # get the categories the volunteer is interested in
    categories_by_task_pref = {
        'preferred tasks': TaskCategory.objects.filter(volunteer=volunteer),
        'other tasks': TaskCategory.objects.exclude(volunteer=volunteer),
    }
    # get the preferred and other tasks, preserve key order with srteddict for view
    context = {
        'tasks': SortedDict({}),
        'checked': {},
        'attending': {},
        'is_dr_manhattan': is_dr_manhattan,
        'dr_manhattan_task_sets': dr_manhattan_task_sets,
    }
    context['volunteer'] = volunteer
    context['tasks']['preferred tasks'] = SortedDict.fromkeys(days, {})
    context['tasks']['other tasks'] = SortedDict.fromkeys(days, {})
    for category_group in context['tasks']:
        for day in context['tasks'][category_group]:
            context['tasks'][category_group][day] = SortedDict.fromkeys(categories_by_task_pref[category_group], [])
            for category in context['tasks'][category_group][day]:
                dct = ok_tasks.filter(template__category=category, date=day)
                context['tasks'][category_group][day][category] = dct

    # mark checked, attending tasks
    for task in current_tasks:
        context['checked'][task.id] = 'checked' if volunteer in task.volunteers.all() else ''

    # take the moderation tasks to talks the volunteer is attending
    for task in current_tasks.filter(talk__volunteers=volunteer):
        context['attending'][task.id] = True

    return render(request, 'volunteers/tasks.html', context)