Beispiel #1
0
def admin_activity_edit(request, association_name, activity_id):

    association = get_object_or_404(Association, name=association_name)
    current_year = association.signing_year  # util.get_current_year()

    # The connected user must be a board member (status < 5)
    if not Member.objects.filter(
            user=request.user.id, association=association.id,
            year=current_year, status__lt=5).exists():
        raise PermissionDenied

    activity = get_object_or_404(
        Activity, id=activity_id, association=association.id)

    message = False  # TODO : use the message middleware for confirmations
    activity_edition_form = ActivityForm(
        request.POST or None, request.FILES or None, instance=activity)

    if activity_edition_form.is_valid():
        activity_edition_form.save()
        message = True

    return render_to_response(
        "admin_activities_edit.html",
        {
            'request': request,
            'association': association,
            'activity': activity,
            'form': activity_edition_form,
            'message': message
        },
        context_instance=RequestContext(request))
Beispiel #2
0
def admin_activities(request, association_name):
    """
    Edit and create new activities.

    :param request: request object
    :param association_name: name of the association to manage
    """

    association = get_object_or_404(Association, name=association_name)
    current_year = association.signing_year  # util.get_current_year()

    # The connected user must be a board member (status < 5)
    if not Member.objects.filter(
            user=request.user.id, association=association.id,
            year=current_year, status__lt=5).exists():
        raise PermissionDenied

    message = False  # TODO : use the message middleware for confirmations
    create_activity_form = ActivityForm(
        request.POST or None, request.FILES or None)

    if create_activity_form.is_valid():
        new_activity = create_activity_form.save(commit=False)
        new_activity.association = association
        create_activity_form.save()
        create_activity_form = ActivityForm()

        message = True

    return render_to_response(
        "admin_activities.html",
        {
            'request': request,
            'form': create_activity_form,
            'association': association,
            # 'active_forms': active_forms,
            'message': message
        },
        context_instance=RequestContext(request))