Пример #1
0
def copy_project(request, pk):
    """
    Copy a proposal from a previous timeslot. Only for staff that is allowed to see the proposal to copy.

    :param pk: the id of proposal to copy
    :param request:
    :return:
    """

    if request.method == 'POST':
        form = ProposalFormCreate(request.POST, request=request)
        if form.is_valid():
            prop = form.save()

            mail_proposal_all(request, prop)
            if prop.Private.all():
                for std in prop.Private.all():
                    mail_proposal_private(prop, std, "A private proposal was created for you.")
            return render(request, "proposals/message_project.html", {"Message": "Proposal created!", "Proposal": prop})
    else:
        old_proposal = get_object_or_404(Proposal, pk=pk)
        oldpk = old_proposal.pk
        old_proposal.pk = None
        # default timeslot. Overridden by form if this is not in phase 1.
        old_proposal.TimeSlot = get_timeslot()
        # Assistants and privates are removed, because m2m is not copied in this way.
        form = ProposalFormCreate(request=request, instance=old_proposal, copy=oldpk)
    if get_timephase_number() == 1:
        return render(request, 'GenericForm.html', {'form': form,
                                                    'formtitle': 'Edit copied proposal',
                                                    'buttontext': 'Create and go to next step'})
    else:
        return render(request, 'GenericForm.html', {'form': form,
                                                    'formtitle': 'Edit copied proposal (For next timeslot)',
                                                    'buttontext': 'Create and go to next step'})
Пример #2
0
def create_project(request):
    """
    Create a new proposal. Only for staff. Generating a new proposal for this timeslot is only allowed in the first
    timephase. In other timephases projects can only be generated for the next timeslot.

    :param request:
    :return:
    """
    if request.method == 'POST':
        form = ProposalFormCreate(request.POST, request=request)
        if form.is_valid():
            prop = form.save()
            mail_proposal_all(request, prop)
            check_content_policy.CPVCheckThread(prop).start()
            if prop.Private.all():
                for std in prop.Private.all():
                    mail_proposal_private(prop, std, "A private proposal was created for you.")
            return render(request, "proposals/message_project.html", {"Message": "Proposal created!", "Proposal": prop})
    else:
        init = {}
        if get_grouptype("1") in request.user.groups.all():
            init["ResponsibleStaff"] = request.user.id
        elif get_grouptype("2") in request.user.groups.all() or get_grouptype('2u'):
            init["Assistants"] = [request.user.id]
        form = ProposalFormCreate(request=request, initial=init)
    if get_timephase_number() == 1:
        return render(request, 'GenericForm.html', {'form': form,
                                                    'formtitle': 'Create new Proposal',
                                                    'buttontext': 'Create and go to next step'})
    else:
        return render(request, 'GenericForm.html', {'form': form,
                                                    'formtitle': 'Create new Proposal (For next timeslot)',
                                                    'buttontext': 'Create and go to next step'})
Пример #3
0
def upgrade_status_api(request, pk):
    """
    API call to increase the status of a proposal.

    :param request:
    :param pk: id of proposal
    :return:
    """
    obj = get_object_or_404(Proposal, pk=pk)

    if obj.Status == 4:
        return HttpResponse("Already at final stage", status=403)

    if obj.Status == 3 and obj.nextyear():
        return HttpResponse("Cannot publish proposal for future timeslot",
                            status=403)

    elif get_timephase_number() > 2 and \
            obj.TimeSlot == get_timeslot() and \
            get_grouptype('3') not in request.user.groups.all():
        return HttpResponse(
            "Proposal frozen in this timeslot. The timephase of editing has ended.",
            status=403)

    elif request.user in obj.Assistants.all() and obj.Status >= 2:
        return HttpResponse(
            "You are an assistant and not allowed to increase status further",
            status=403)
    # Done in can_edit decorator
    # elif obj.Track.Head != request.user and obj.Status > 2 and not get_grouptype('3') in request.user.groups.all():
    #     return HttpResponse("Not allowed to publish as non track head", status=403)

    else:
        oldstatus = obj.Status
        if oldstatus == 2:
            # per default go to publish from 4, 3 is only used if it is explicitly downgraded
            newstatus = 4
        else:
            newstatus = obj.Status + 1

        obj.Status = newstatus
        obj.save()
        mail_proposal_all(request, obj)

        notification = ProposalStatusChange()
        notification.Subject = obj
        notification.Actor = request.user
        notification.StatusFrom = oldstatus
        notification.StatusTo = newstatus
        notification.save()

        if obj.Status > 3:
            for assistant in obj.Assistants.all():
                if get_grouptype("2u") in assistant.groups.all():
                    verify_assistant_fn(assistant)
        if obj.Status == 4:
            # put the object in cache if status goes from 3->4
            cache.set('proposal_{}'.format(pk), obj, None)
            cache.delete('listproposalsbodyhtml')
        return HttpResponse(getStatStr(obj.Status))
Пример #4
0
def downgrade_status_api(request, pk, message=''):
    """
    API call to decrease the status of a proposal.

    :param request:
    :param pk: id of proposal
    :param message: message why the proposal was downgraded
    :return:
    """
    obj = get_object_or_404(Proposal, pk=pk)
    oldstatus = obj.Status

    if oldstatus == 4:
        # track head downgrade to 3, owner downgrade to 4
        if request.user == obj.Track.Head:
            newstatus = 3
        else:
            newstatus = 2
    else:
        newstatus = oldstatus - 1

    obj.Status = newstatus
    obj.save()
    mail_proposal_all(request, obj, message)

    notification = ProposalStatusChange()
    notification.Subject = obj
    notification.Message = message
    notification.Actor = request.user
    notification.StatusFrom = oldstatus
    notification.StatusTo = newstatus
    notification.save()

    # destroy the cache for this if oldstatus was published
    if oldstatus == 4:
        if 'listproposalsbodyhtml' in cache:
            cache.delete('listproposalsbodyhtml')
        if 'proposal_{}'.format(pk) in cache:
            cache.delete('proposal_{}'.format(pk))
        if 'proposaldetail{}'.format(pk) in cache:
            cache.delete('proposaldetail{}'.format(pk))

    return HttpResponse(get_status_str(obj.Status))
Пример #5
0
def upgrade_status_api(request, pk):
    """
    API call to increase the status of a proposal.

    :param request:
    :param pk: id of proposal
    :return:
    """
    obj = get_object_or_404(Proposal, pk=pk)

    oldstatus = obj.Status
    if oldstatus == 2:
        # per default go to publish from 4, 3 is only used if it is explicitly downgraded
        newstatus = 4
    else:
        newstatus = obj.Status + 1

    obj.Status = newstatus
    obj.save()
    mail_proposal_all(request, obj)

    notification = ProposalStatusChange()
    notification.Subject = obj
    notification.Actor = request.user
    notification.StatusFrom = oldstatus
    notification.StatusTo = newstatus
    notification.save()

    if obj.Status > 3:
        for assistant in obj.Assistants.all():
            if get_grouptype("2u") in assistant.groups.all():
                verify_assistant_fn(assistant)
    if obj.Status == 4:
        # put the object in cache if status goes from 3->4
        cache.set('proposal_{}'.format(pk), obj, settings.PROJECT_OBJECT_CACHE_DURATION)
        cache.delete('listproposalsbodyhtml')
    return HttpResponse(get_status_str(obj.Status))