Ejemplo n.º 1
0
def subscription_form(request, basecontent_id):
    content = BaseContent.objects.get(id=basecontent_id)
    subscribable = content.subscribable_set.actives()
    if not subscribable:
        return HttpResponseRedirect(content.get_absolute_url())
    subscribable = subscribable[0]
    app_label, module_name = subscribable.class_name.split('.')
    content_type = ContentType.objects.get(app_label=app_label, model=module_name)
    model_class = content_type.model_class()
    data = None
    if request.POST:
        data = request.POST
    form = model_class.class_form()(data)
    if form.is_valid():
        subscription = form.save(commit=False)
        subscription.subscribable = subscribable
        subscription.save()
        subscriber_listing_url = reverse('subscriber_listing', args=(basecontent_id, ))
        send_info(
            request,
            _('Request send successfully. See <a href="%(subscriber_listing)s">suscriber list</a>') % {
                'subscriber_listing': subscriber_listing_url,
            },
        )
        url_redirect = content.get_absolute_url()
        invalidate_cache_for_path(url_redirect)
        return HttpResponseRedirect(url_redirect)
    return render_to_response('subscription/subscription_form.html',
                              {'form': form,
                               'content': content,
                              },
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def invalidate_cache(request):
    path = request.REQUEST.get('path', None)
    if path:
        invalidate_cache_for_path(path)
        request.user.message_set.create(message=_("Cache from this page was invalidated"))
        return HttpResponseRedirect(_get_redirect_to(request.GET, redirect_field_name='path'))
    return HttpResponse('path parameter is needed in HTTP request')
Ejemplo n.º 3
0
def subscription_form(request, basecontent_id):
    content = BaseContent.objects.get(id=basecontent_id)
    subscribable = content.subscribable_set.actives()
    if not subscribable:
        return HttpResponseRedirect(content.get_absolute_url())
    subscribable = subscribable[0]
    app_label, module_name = subscribable.class_name.split('.')
    content_type = ContentType.objects.get(app_label=app_label,
                                           model=module_name)
    model_class = content_type.model_class()
    data = None
    if request.POST:
        data = request.POST
    form = model_class.class_form()(data)
    if form.is_valid():
        subscription = form.save(commit=False)
        subscription.subscribable = subscribable
        subscription.save()
        subscriber_listing_url = reverse('subscriber_listing',
                                         args=(basecontent_id, ))
        send_info(
            request,
            _('Request send successfully. See <a href="%(subscriber_listing)s">suscriber list</a>'
              ) % {
                  'subscriber_listing': subscriber_listing_url,
              },
        )
        url_redirect = content.get_absolute_url()
        invalidate_cache_for_path(url_redirect)
        return HttpResponseRedirect(url_redirect)
    return render_to_response('subscription/subscription_form.html', {
        'form': form,
        'content': content,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 4
0
def invalidate_cache(request):
    path = request.REQUEST.get('path', None)
    if path:
        invalidate_cache_for_path(path)
        request.user.message_set.create(
            message=_("Cache from this page was invalidated"))
        return HttpResponseRedirect(
            _get_redirect_to(request.GET, redirect_field_name='path'))
    return HttpResponse('path parameter is needed in HTTP request')