コード例 #1
0
ファイル: views.py プロジェクト: freshehr/engineclub
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))
コード例 #2
0
ファイル: views.py プロジェクト: freshehr/engineclub
def curations_for_group_html(request, object_id, template_name="depot/curations_for_group_embed.html"):

    object = get_one_or_404(obj_class=Account, id=ObjectId(object_id))
    curations = [c.resource for c in Curation.objects(owner=object).order_by("-item_metadata__last_modified")[:10]]
    template_context = {"object": object, "curations": curations}

    return render_to_response(template_name, template_context, RequestContext(request))
コード例 #3
0
ファイル: utils.py プロジェクト: freshehr/engineclub
 def render(self, context):
     owner = self.owner.resolve(context)
     # context[self.varname] = list(Resource.objects(curations__owner=owner)[:int(self.num)])
     context[self.varname] = [
         c.resource for c in Curation.objects(owner=owner).order_by(
             '-item_metadata__last_modified')[:int(self.num)]
     ]
     return ''
コード例 #4
0
ファイル: views.py プロジェクト: verbosity/engineclub
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"))
コード例 #5
0
ファイル: views.py プロジェクト: verbosity/engineclub
def curations_for_group(request, object_id, template_name="depot/curations_for_group.html"):
    """docstring for curations_for_group"""
    object = get_one_or_404(obj_class=Account, id=object_id)

    # curations = list(Resource.objects(curations__owner=object)[:10])
    curations = [c.resource for c in Curation.objects(owner=object).order_by("-item_metadata__last_modified")[:10]]

    template_context = {"object": object, "curations": curations}

    return render_to_response(template_name, template_context, RequestContext(request))
コード例 #6
0
def curations_for_group_html(request, object_id, template_name='depot/curations_for_group_embed.html'):

    object = get_one_or_404(obj_class=Account, id=ObjectId(object_id))
    curations = [c.resource for c in Curation.objects(owner=object).order_by('-item_metadata__last_modified')[:10]]
    template_context = {'object': object, 'curations': curations}

    return render_to_response(
        template_name,
        template_context,
        RequestContext(request)
    )
コード例 #7
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'))
コード例 #8
0
ファイル: views.py プロジェクト: freshehr/engineclub
def curations_for_group_js(request, object_id, template_name="depot/curations_for_group_embed.js"):

    object = get_one_or_404(obj_class=Account, id=ObjectId(object_id))
    curations = [c.resource for c in Curation.objects(owner=object).order_by("-item_metadata__last_modified")[:10]]
    base_url = Site.objects.get_current().domain
    print base_url
    template_context = Context({"object": object, "curations": curations, "base_url": "http://%s" % base_url})

    response = HttpResponse(mimetype="text/javascript")
    t = loader.get_template(template_name)
    response.write(t.render(template_context))
    return response
コード例 #9
0
def curations_for_group_js(request, object_id, template_name='depot/curations_for_group_embed.js'):
    
    object = get_one_or_404(obj_class=Account, id=ObjectId(object_id))
    curations = [c.resource for c in Curation.objects(owner=object).order_by('-item_metadata__last_modified')[:10]]
    base_url = Site.objects.get_current().domain
    print base_url
    template_context = Context(
        {'object': object, 'curations': curations, 'base_url': 'http://%s' % base_url})

    response = HttpResponse(mimetype='text/javascript')
    t = loader.get_template(template_name)
    response.write(t.render(template_context))
    return response
コード例 #10
0
ファイル: tests.py プロジェクト: verbosity/engineclub
 def test_curations(self):
     """docstring for test_curations"""
     
     
     acct = Account.objects.get(name="Derek Hoy")
     print acct, acct.id
     
     print list(Resource.objects(curations__owner=acct))
     
     
     curations = Curation.objects(owner=acct).order_by('-item_metadata__last_modified')
     
     for c in curations:
         print c.owner, c.item_metadata.last_modified,  c.resource
コード例 #11
0
ファイル: tests.py プロジェクト: freshehr/engineclub
 def test_curations(self):
     """docstring for test_curations"""
     
     
     acct = Account.objects.get(name="Derek Hoy")
     print acct, acct.id
     
     print list(Resource.objects(curations__owner=acct))
     
     
     curations = Curation.objects(owner=acct).order_by('-item_metadata__last_modified')
     
     for c in curations:
         print c.owner, c.item_metadata.last_modified,  c.resource.title
コード例 #12
0
ファイル: views.py プロジェクト: pombredanne/engineclub
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)
    )
コード例 #13
0
def curations_for_group(request,
                        object_id,
                        template_name='depot/curations_for_group.html'):
    """docstring for curations_for_group"""
    object = get_one_or_404(obj_class=Account, id=object_id)

    # curations = list(Resource.objects(curations__owner=object)[:10])
    curations = [
        c.resource for c in Curation.objects(
            owner=object).order_by('-item_metadata__last_modified')[:10]
    ]

    template_context = {'object': object, 'curations': curations}

    return render_to_response(template_name, template_context,
                              RequestContext(request))
コード例 #14
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))
コード例 #15
0
ファイル: utils.py プロジェクト: freshehr/engineclub
 def render(self, context):
     owner = self.owner.resolve(context)
     # context[self.varname] = list(Resource.objects(curations__owner=owner)[:int(self.num)])
     context[self.varname] = [c.resource for c in Curation.objects(owner=owner).order_by('-item_metadata__last_modified')[:int(self.num)]]
     return ''