Example #1
0
def resource_reject_view(request, id):
    if not request.user.is_staff:
        return HttpResponse(status=401, content="Not Authorized")

    resource = Resource.objects.get(pk=id)

    if request.method == 'POST':
        form = ResourceRejectForm(data=request.POST)
        form.fields['criteria'].choices = [(t.id, t.description) for t in ResourceCriteria.objects.all(
        ).order_by('category_order_by', 'order_by')]

        if form.is_valid():
            resource.status = Resource.REJECTED
            resource.save()
            notes = form.cleaned_data.get("notes")
            criteria = form.cleaned_data.get("criteria")
            resource_workflow.send(sender=resource, resource=resource, request=request,
                                   status=Resource.REJECTED, notes=notes, criteria=criteria)
            return HttpResponseRedirect(reverse('orb_resource_reject_sent', args=[resource.id]))
    else:
        form = ResourceRejectForm()
        form.fields['criteria'].choices = [(t.id, t.description) for t in ResourceCriteria.objects.all(
        ).order_by('category_order_by', 'order_by')]

    return render(request, 'orb/resource/reject_form.html', {
        'resource': resource,
        'form': form,
    })
Example #2
0
def resource_reject_view(request, id):
    if not request.user.is_staff:
        return HttpResponse(status=401, content="Not Authorized")

    resource = Resource.objects.get(pk=id)

    if request.method == 'POST':
        form = ResourceRejectForm(data=request.POST)
        form.fields['criteria'].choices = [(t.id, t.description) for t in ResourceCriteria.objects.all(
        ).order_by('category_order_by', 'order_by')]

        if form.is_valid():
            resource.status = Resource.REJECTED
            resource.save()
            notes = form.cleaned_data.get("notes")
            criteria = form.cleaned_data.get("criteria")
            resource_workflow.send(sender=resource, resource=resource, request=request,
                                   status=Resource.REJECTED, notes=notes, criteria=criteria)
            return HttpResponseRedirect(reverse('orb_resource_reject_sent', args=[resource.id]))
    else:
        form = ResourceRejectForm()
        form.fields['criteria'].choices = [(t.id, t.description) for t in ResourceCriteria.objects.all(
        ).order_by('category_order_by', 'order_by')]

    return render(request, 'orb/resource/reject_form.html', {
        'resource': resource,
        'form': form,
    })
Example #3
0
def resource_create_step1_view(request):
    if request.user.is_anonymous:
        return render(request, 'orb/login_required.html', {
            'message': _('You need to be logged in to add a resource.'),
        })

    if request.method == 'POST':
        form = ResourceStep1Form(request.POST, request.FILES, request=request)
        resource_form_set_choices(form)
        if form.is_valid():
            # save resource
            resource = Resource(status=Resource.PENDING,
                                create_user=request.user, update_user=request.user)
            resource.title = form.cleaned_data.get("title")
            resource.description = form.cleaned_data.get("description")
            if form.cleaned_data.get("study_time_number") and form.cleaned_data.get("study_time_unit"):
                resource.study_time_number = form.cleaned_data.get(
                    "study_time_number")
                resource.study_time_unit = form.cleaned_data.get(
                    "study_time_unit")
            if 'image' in request.FILES:
                resource.image = request.FILES["image"]
            resource.attribution = form.cleaned_data.get("attribution")
            resource.save()

            # add organisation(s)/geography and other tags
            resource_add_free_text_tags(
                resource, form.cleaned_data.get('organisations'), request.user, 'organisation')
            resource_add_free_text_tags(
                resource, form.cleaned_data.get('geography'), request.user, 'geography')
            resource_add_free_text_tags(
                resource, form.cleaned_data.get('languages'), request.user, 'language')
            resource_add_free_text_tags(
                resource, form.cleaned_data.get('other_tags'), request.user, 'other')

            # add tags
            resource_add_tags(request, form, resource)

            # see if email needs to be sent
            resource_workflow.send(sender=resource, resource=resource, request=request,
                                   status=Resource.PENDING, notes="")
            resource_submitted.send(sender=resource, resource=resource, request=request)

            # redirect to step 2
            # Redirect after POST
            return HttpResponseRedirect(reverse('orb_resource_create2', args=[resource.id]))

    else:
        if request.user.userprofile.organisation:
            user_org = request.user.userprofile.organisation.name
            initial = {'organisations': user_org, }
        else:
            initial = {}
        form = ResourceStep1Form(initial=initial, request=request)
        resource_form_set_choices(form)

    return render(request, 'orb/resource/create_step1.html', {'form': form})
Example #4
0
def resource_create_step1_view(request):
    if request.user.is_anonymous():
        return render(request, 'orb/login_required.html', {
            'message': _(u'You need to be logged in to add a resource.'),
        })

    if request.method == 'POST':
        form = ResourceStep1Form(request.POST, request.FILES, request=request)
        resource_form_set_choices(form)
        if form.is_valid():
            # save resource
            resource = Resource(status=Resource.PENDING,
                                create_user=request.user, update_user=request.user)
            resource.title = form.cleaned_data.get("title")
            resource.description = form.cleaned_data.get("description")
            if form.cleaned_data.get("study_time_number") and form.cleaned_data.get("study_time_unit"):
                resource.study_time_number = form.cleaned_data.get(
                    "study_time_number")
                resource.study_time_unit = form.cleaned_data.get(
                    "study_time_unit")
            if request.FILES.has_key('image'):
                resource.image = request.FILES["image"]
            resource.attribution = form.cleaned_data.get("attribution")
            resource.save()

            # add organisation(s)/geography and other tags
            resource_add_free_text_tags(
                resource, form.cleaned_data.get('organisations'), request.user, 'organisation')
            resource_add_free_text_tags(
                resource, form.cleaned_data.get('geography'), request.user, 'geography')
            resource_add_free_text_tags(
                resource, form.cleaned_data.get('languages'), request.user, 'language')
            resource_add_free_text_tags(
                resource, form.cleaned_data.get('other_tags'), request.user, 'other')

            # add tags
            resource_add_tags(request, form, resource)

            # see if email needs to be sent
            resource_workflow.send(sender=resource, resource=resource, request=request,
                                   status=Resource.PENDING, notes="")
            resource_submitted.send(sender=resource, resource=resource, request=request)

            # redirect to step 2
            # Redirect after POST
            return HttpResponseRedirect(reverse('orb_resource_create2', args=[resource.id]))

    else:
        if request.user.userprofile.organisation:
            user_org = request.user.userprofile.organisation.name
            initial = {'organisations': user_org, }
        else:
            initial = {}
        form = ResourceStep1Form(initial=initial, request=request)
        resource_form_set_choices(form)

    return render(request, 'orb/resource/create_step1.html', {'form': form})
Example #5
0
def resource_approve_view(request, id):
    if not request.user.is_staff:
        return HttpResponse(status=401, content="Not Authorized")
    resource = Resource.objects.get(pk=id)
    resource.status = Resource.APPROVED
    resource.save()

    resource_workflow.send(sender=resource, resource=resource,
                           request=request, status=Resource.APPROVED, notes="")
    return render(request, 'orb/resource/status_updated.html', {'resource': resource})
Example #6
0
def resource_approve_view(request, id):
    if not request.user.is_staff:
        return HttpResponse(status=401, content="Not Authorized")
    resource = Resource.objects.get(pk=id)
    resource.status = Resource.APPROVED
    resource.save()

    resource_workflow.send(sender=resource, resource=resource,
                           request=request, status=Resource.APPROVED, notes="")
    return render(request, 'orb/resource/status_updated.html', {'resource': resource})