Ejemplo n.º 1
0
def curation_add(request, object_id, template_name="depot/curation_edit.html"):
    """docstring for curation_add"""
    resource = get_one_or_404(id=ObjectId(object_id))
    user = get_account(request.user.id)

    curation = get_curation_for_user_resource(user, resource)
    if curation:
        index, cur = curation
        messages.success(request, "You already have a curation for this resource.")
        return HttpResponseRedirect(reverse("curation", args=[resource.id, index]))

    if request.method == "POST":
        result = request.POST.get("result", "")
        if result == "Cancel":
            return HttpResponseRedirect(reverse("resource", args=[resource.id]))
        form = CurationForm(request.POST)
        if form.is_valid():
            curation = Curation(**form.cleaned_data)
            curation.owner = user
            curation.item_metadata.update(author=user)
            curation.resource = resource
            curation.save()
            resource.curations.append(curation)
            resource.save(reindex=True)
            index = len(resource.curations) - 1

            return HttpResponseRedirect(reverse("curation", args=[resource.id, index]))
    else:
        initial = {"outcome": STATUS_OK}
        form = CurationForm(initial=initial)

    template_context = {"form": form}

    return render_to_response(template_name, template_context, RequestContext(request))
Ejemplo n.º 2
0
def fix_curationless_resources(request):
    i = 0
    r = []
    for res in Resource.objects.all():
        if not res.curations:
            obj = Curation(outcome=STATUS_OK, tags=res.tags, owner=res.owner)
            obj.item_metadata.author = res.owner
            obj.resource = res
            obj.save()
            res.curations.append(obj)
            res.save(reindex=True)

            r.append('<a href="http://127.0.0.1:8080/depot/resource/%s">%s</a>' % (res._id, res.title))
            i += 1

    note = "fixed %s resources with no curations: %s" % (i, ", ".join(r))
    messages.success(request, "job done. %s" % note)

    return HttpResponseRedirect(reverse("cab"))
Ejemplo n.º 3
0
def fix_curationless_resources(request):
    i = 0
    r = []
    for res in Resource.objects.all():
        if not res.curations:
            obj = Curation(outcome=STATUS_OK, tags=res.tags, owner=res.owner)
            obj.item_metadata.author = res.owner
            obj.resource = res
            obj.save()
            res.curations.append(obj)
            res.save(reindex=True)

            r.append(
                '<a href="http://127.0.0.1:8080/depot/resource/%s">%s</a>' %
                (res._id, res.title))
            i += 1

    note = 'fixed %s resources with no curations: %s' % (i, ', '.join(r))
    messages.success(request, 'job done. %s' % note)

    return HttpResponseRedirect(reverse('cab'))
Ejemplo n.º 4
0
def curation_add(request, object_id, template_name='depot/curation_edit.html'):
    """docstring for curation_add"""
    resource = get_one_or_404(id=ObjectId(object_id))
    user = get_account(request.user.id)

    # check if user already has a curation for this resource
    curation = get_curation_for_user_resource(user, resource)
    if curation:
        index, cur = curation
        messages.success(request,
                         'You already have a curation for this resource.')
        return HttpResponseRedirect(
            reverse('curation', args=[resource.id, index]))

    if request.method == 'POST':
        result = request.POST.get('result', '')
        if result == 'Cancel':
            return HttpResponseRedirect(reverse('resource',
                                                args=[resource.id]))
        form = CurationForm(request.POST)
        if form.is_valid():
            curation = Curation(**form.cleaned_data)
            curation.owner = user
            curation.item_metadata.update(author=user)
            curation.resource = resource
            curation.save()
            resource.curations.append(curation)
            resource.save(reindex=True)
            index = len(resource.curations) - 1

            return HttpResponseRedirect(
                reverse('curation', args=[resource.id, index]))
    else:
        initial = {'outcome': STATUS_OK}
        form = CurationForm(initial=initial)

    template_context = {'form': form}

    return render_to_response(template_name, template_context,
                              RequestContext(request))
Ejemplo n.º 5
0
def curation_add(request, object_id, template_name='depot/curation_edit.html'):
    """docstring for curation_add"""
    resource = get_one_or_404(id=ObjectId(object_id))
    user = get_account(request.user.id)
    
    # check if user already has a curation for this resource
    for index, cur in enumerate(resource.curations):
        if cur.owner.id == user.id:
            messages.success(request, 'You already have a curation for this resource.')
            return HttpResponseRedirect(reverse('curation', args=[resource.id, index]))
    
    if request.method == 'POST':
        result = request.POST.get('result', '')
        if result == 'Cancel':
            return HttpResponseRedirect(reverse('resource', args=[resource.id]))
        form = CurationForm(request.POST)
        if form.is_valid():
            curation = Curation(**form.cleaned_data)
            curation.owner = user
            curation.item_metadata.update(author=user)
            curation.resource = resource
            curation.save()
            resource.curations.append(curation)
            resource.save(reindex=True)
            index = len(resource.curations) - 1
            return HttpResponseRedirect(reverse('curation', args=[resource.id, index]))
    else:
        initial = { 'outcome': STATUS_OK}
        form = CurationForm(initial=initial)

    template_context = {'form': form}

    return render_to_response(
        template_name,
        template_context,
        RequestContext(request)
    )