Exemple #1
0
def curation_add(request, object_id, template_name='depot/curation_edit.html'):
    """docstring for curation_add"""
    resource = get_one_or_404(Resource, id=ObjectId(object_id))
    user = get_account(request.user.id)

    curation = get_curation_for_acct_resource(user, resource)
    if curation:
        index, cur = curation
        messages.warning(
            request,
            'You already have a curation for this resource- you can edit it if you need to make changes.'
        )
        return HttpResponseRedirect(
            reverse('curation', args=[resource.id, index]))

    if request.method == 'POST':
        result = request.POST.get('result', '')
        next = request.GET.get('next', '')
        if next:
            url = '%s#res_%s' % (next, resource.id)
        else:
            url = ''
        if result == 'Cancel':
            return HttpResponseRedirect(
                url or reverse('resource', args=[resource.id]))
        form = CurationForm(request.POST)
        if form.is_valid(request.user):
            curation = Curation(**form.cleaned_data)
            curation.owner = user
            curation.item_metadata.update(author=user)
            add_curation(resource, curation)
            # TODO: move this into resource.add_curation
            increment_resource_crud('curation_add', account=user)
            index = len(resource.curations) - 1
            return HttpResponseRedirect(
                url or reverse('curation', args=[resource.id, index]))
    else:
        initial = {'outcome': STATUS_OK}
        form = CurationForm(initial=initial)

    template_context = {
        'next': urlquote_plus(request.GET.get('next', '')),
        'form': form,
        'resource': resource,
        'new': True
    }

    return render_to_response(template_name, template_context,
                              RequestContext(request))
Exemple #2
0
def curation_add(request, object_id, template_name='depot/curation_edit.html'):
    """docstring for curation_add"""
    resource = get_one_or_404(Resource, id=ObjectId(object_id))
    user = get_account(request.user.id)

    curation = get_curation_for_acct_resource(user, resource)
    if curation:
        index, cur = curation
        messages.warning(request, 'You already have a curation for this resource- you can edit it if you need to make changes.')
        return HttpResponseRedirect(reverse('curation', args=[resource.id, index]))

    if request.method == 'POST':
        result = request.POST.get('result', '')
        next = request.GET.get('next', '')
        if next:
            url = '%s#res_%s' % (next, resource.id)
        else:
            url = ''
        if result == 'Cancel':
            return HttpResponseRedirect(url or reverse('resource', args=[resource.id]))
        form = CurationForm(request.POST)
        if form.is_valid(request.user):
            curation = Curation(**form.cleaned_data)
            curation.owner = user
            curation.item_metadata.update(author=user)
            add_curation(resource, curation)
            # TODO: move this into resource.add_curation
            increment_resource_crud('curation_add', account=user)
            index = len(resource.curations) - 1
            return HttpResponseRedirect(url or reverse('curation', args=[resource.id, index]))
    else:
        initial = { 'outcome': STATUS_OK}
        form = CurationForm(initial=initial)

    template_context = {
        'next': urlquote_plus(request.GET.get('next', '')),
        'form': form,
        'resource': resource,
        'new': True
    }

    return render_to_response(
        template_name,
        template_context,
        RequestContext(request)
    )
Exemple #3
0
def curation_edit(request, object_id, index, template_name='depot/curation_edit.html'):
    """Curation is an EmbeddedDocument, so can't be saved, needs to be edited, then Resource saved."""
    resource = get_one_or_404(Resource, id=ObjectId(object_id))
    object = resource.curations[int(index)]
    if not request.user.has_perm('can_edit', object):
        raise PermissionDenied()

    if request.method == 'POST':
        result = request.POST.get('result', '')
        if result == 'Cancel':
            return HttpResponseRedirect(reverse('curation', args=[resource.id, index]))
        form = CurationForm(request.POST, instance=object)
        if form.is_valid(request.user):
            user = get_account(request.user.id)
            curation = form.save(do_save=False)
            curation.item_metadata.update(author=user)
            curation.save()
            increment_resource_crud('curation_edit', account=user)
            # reload the resource, don't know why, but needed for mongoengine 0.6
            resource = Resource.objects.get(id=resource.id)
            if curation.owner == resource.owner:
                resource.tags = list(set(curation.tags))
            resource.save(reindex=True)
            return HttpResponseRedirect(reverse('curation', args=[resource.id, index]))
    else:
        form = CurationForm(instance=object)

    template_context = {
        'form': form,
        'object': object,
        'resource': resource,
        'new': False
    }

    return render_to_response(
        template_name,
        template_context,
        RequestContext(request)
    )
Exemple #4
0
def curation_edit(request,
                  object_id,
                  index,
                  template_name='depot/curation_edit.html'):
    """Curation is an EmbeddedDocument, so can't be saved, needs to be edited, then Resource saved."""
    resource = get_one_or_404(Resource, id=ObjectId(object_id))
    object = resource.curations[int(index)]
    if not request.user.has_perm('can_edit', object):
        raise PermissionDenied()

    if request.method == 'POST':
        result = request.POST.get('result', '')
        if result == 'Cancel':
            return HttpResponseRedirect(
                reverse('curation', args=[resource.id, index]))
        form = CurationForm(request.POST, instance=object)
        if form.is_valid(request.user):
            user = get_account(request.user.id)
            curation = form.save(do_save=False)
            curation.item_metadata.update(author=user)
            curation.save()
            increment_resource_crud('curation_edit', account=user)
            # reload the resource, don't know why, but needed for mongoengine 0.6
            resource = Resource.objects.get(id=resource.id)
            if curation.owner == resource.owner:
                resource.tags = list(set(curation.tags))
            resource.save(reindex=True)
            return HttpResponseRedirect(
                reverse('curation', args=[resource.id, index]))
    else:
        form = CurationForm(instance=object)

    template_context = {
        'form': form,
        'object': object,
        'resource': resource,
        'new': False
    }

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