Ejemplo n.º 1
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(id=ObjectId(object_id), user=request.user, perm='can_edit')
    object = resource.curations[int(index)]
    
    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():
            user = get_account(request.user.id)
            curation = form.save(do_save=False)
            curation.item_metadata.update(author=user)
            curation.save()
            resource.save(reindex=True)
            return HttpResponseRedirect(reverse('curation', args=[resource.id, index]))
    else:
        form = CurationForm(instance=object)

    template_context = {'form': form}

    return render_to_response(
        template_name,
        template_context,
        RequestContext(request)
    )
Ejemplo n.º 2
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.º 3
0
def resource_find(request, template='depot/resource_find.html'):
    """docstring for resource_find"""

    results = locations = []
    centre = None
    pins = []
    # places = []
    result = request.REQUEST.get('result', '')
    if request.method == 'POST' or result:
        # result = request.REQUEST.get('result', '')
        if result == 'Cancel':
            return HttpResponseRedirect(reverse('resource-list'))
        form = FindResourceForm(request.REQUEST)

        if form.is_valid():
            user = get_account(request.user.id)
            for result in form.results:
                resource = get_one_or_404(id=ObjectId(result['res_id']))

                try:
                    curation_index, curation = get_curation_for_user_resource(
                        user, resource)
                except TypeError:
                    curation_index = curation = None

                curation_form = CurationForm(initial={'outcome': STATUS_OK},
                                             instance=curation)
                results.append({
                    'resource_result': result,
                    'curation': curation,
                    'curation_form': curation_form,
                    'curation_index': curation_index
                })
            locations = form.locations
            centre = form.centre
            # pins = [loc['obj'] for loc in locations]

    else:
        form = FindResourceForm(
            initial={
                'post_code': 'aberdeen',
                'boost_location': settings.SOLR_LOC_BOOST_DEFAULT
            })

    # print places
    context = {
        'form': form,
        'results': results,
        'locations': locations,
        'centre': centre,
        'pins': pins,
        'yahoo_appid': settings.YAHOO_KEY,
        'google_key': settings.GOOGLE_KEY,
    }
    return render_to_response(template, RequestContext(request, context))
Ejemplo n.º 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(id=ObjectId(object_id),
                              user=request.user,
                              perm='can_edit')
    object = resource.curations[int(index)]

    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():
            user = get_account(request.user.id)
            curation = form.save(do_save=False)
            curation.item_metadata.update(author=user)
            curation.save()
            resource.save(reindex=True)
            return HttpResponseRedirect(
                reverse('curation', args=[resource.id, index]))
    else:
        form = CurationForm(instance=object)

    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
    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.º 6
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)
    )