Exemplo n.º 1
0
    def __call__(self, request, **kwargs):
        # get the category
        try:
            cat = self.get_category(request, kwargs.pop('category', ''))
        except self.EmptyHomepageException:
            return self.render(request, {}, self.empty_homepage_template_name)

        # mark it as being rendered
        object_rendering.send(sender=Category, request=request, category=cat, publishable=None)
        object_rendered.send(sender=Category, request=request, category=cat, publishable=None)

        # if API enabled and active, return a serialized category
        response = render_as_api(request, cat)
        if response:
            return response

        context = self.get_context(request, cat, **kwargs)

        # custom view for category
        if custom_urls.resolver.has_custom_detail(cat):
            # custom_urls depend on the main rendered object being stored as
            # 'object' in context
            context['object'] = cat
            return custom_urls.resolver.call_custom_detail(request, context)

        template_name = cat.template
        archive_template = cat.app_data.ella.archive_template

        if archive_template and not context.get('is_title_page'):
            template_name = archive_template

        return self.render(request, context, self.get_templates(context, template_name))
Exemplo n.º 2
0
    def __call__(self, request, **kwargs):
        # get the category
        try:
            cat = self.get_category(request, kwargs.pop('category', ''))
        except self.EmptyHomepageException:
            return self.render(request, {}, self.empty_homepage_template_name)

        # mark it as being rendered
        object_rendering.send(sender=Category,
                              request=request,
                              category=cat,
                              publishable=None)
        object_rendered.send(sender=Category,
                             request=request,
                             category=cat,
                             publishable=None)

        # if API enabled and active, return a serialized category
        response = render_as_api(request, cat)
        if response:
            return response

        context = self.get_context(request, cat, **kwargs)

        template_name = cat.template
        archive_template = cat.app_data.ella.archive_template

        if archive_template and not context.get('is_title_page'):
            template_name = archive_template

        return self.render(request, context,
                           self.get_templates(context, template_name))
Exemplo n.º 3
0
    def __call__(self, request, **kwargs):
        # get the category
        try:
            cat = self.get_category(request, kwargs.pop('category', ''))
        except self.EmptyHomepageException:
            return self.render(request, {}, self.empty_homepage_template_name)

        # mark it as being rendered
        object_rendering.send(sender=Category, request=request, category=cat, publishable=None)
        object_rendered.send(sender=Category, request=request, category=cat, publishable=None)

        # if API enabled and active, return a serialized category
        response = render_as_api(request, cat)
        if response:
            return response

        context = self.get_context(request, cat, **kwargs)

        template_name = cat.template
        archive_template = cat.app_data.ella.archive_template

        if archive_template and not context.get('is_title_page'):
            template_name = archive_template

        return self.render(request, context, self.get_templates(context, template_name))
Exemplo n.º 4
0
    def __call__(self, request, category, slug, year=None, month=None, day=None, id=None, url_remainder=None):
        context = self.get_context(request, category, slug, year, month, day, id)

        obj = context['object']

        if obj.static and (slug != obj.slug or obj.category_id != context['category'].pk):
            url = obj.get_absolute_url()
            if url_remainder:
                url += url_remainder
            return redirect(url, permanent=True)

        # save existing object to preserve memory and SQL
        obj.category = context['category']

        object_rendering.send(sender=context['object'].__class__, request=request, category=context['category'], publishable=context['object'])

        # check for custom actions
        if url_remainder:
            return custom_urls.resolver.call_custom_view(request, obj, url_remainder, context)
        elif custom_urls.resolver.has_custom_detail(obj):
            return custom_urls.resolver.call_custom_detail(request, context)

        object_rendered.send(sender=context['object'].__class__, request=request, category=context['category'], publishable=context['object'])

        return self.render(request, context, self.get_templates(context))
Exemplo n.º 5
0
    def __call__(self, request, **kwargs):
        # get the category
        try:
            cat = self.get_category(request, kwargs.pop('category', ''))
        except self.EmptyHomepageException:
            return self.render(request, {}, self.empty_homepage_template_name)

        # mark it as being rendered
        object_rendering.send(sender=Category, request=request, category=cat, publishable=None)
        object_rendered.send(sender=Category, request=request, category=cat, publishable=None)

        # if API enabled and active, return a serialized category
        response = render_as_api(request, cat)
        if response:
            return response

        context = self.get_context(request, cat, **kwargs)

        # custom view for category
        if custom_urls.resolver.has_custom_detail(cat):
            # custom_urls depend on the main rendered object being stored as
            # 'object' in context
            context['object'] = cat
            return custom_urls.resolver.call_custom_detail(request, context)

        template_name = cat.template
        archive_template = cat.app_data.ella.archive_template

        if archive_template and not context.get('is_title_page'):
            template_name = archive_template

        return self.render(request, context, self.get_templates(context, template_name))
Exemplo n.º 6
0
    def __call__(self, request, category, slug, year=None, month=None, day=None, id=None, url_remainder=None):
        try:
            context = self.get_context(request, category, slug, year, month, day, id)
        except self.WrongUrl as e:
            message, obj = e.args
            url = obj.get_absolute_url()
            if url_remainder:
                url += url_remainder
            return redirect(url, permanent=True)

        obj = context['object']

        object_rendering.send(sender=context['object'].__class__, request=request, category=context['category'], publishable=context['object'])

        # check for custom actions
        if url_remainder:
            return custom_urls.resolver.call_custom_view(request, obj, url_remainder, context)
        response = render_as_api(request, obj)
        if response:
            return response

        if custom_urls.resolver.has_custom_detail(obj):
            return custom_urls.resolver.call_custom_detail(request, context)

        object_rendered.send(sender=context['object'].__class__, request=request, category=context['category'], publishable=context['object'])

        return self.render(request, context, self.get_templates(context))
Exemplo n.º 7
0
Arquivo: views.py Projeto: horakz/ella
 def __call__(self, request, **kwargs):
     try:
         context = self.get_context(request, **kwargs)
         template_name = context['category'].template
         if core_settings.ARCHIVE_TEMPLATE and not context.get('is_title_page'):
             template_name = self.template_name
         object_rendering.send(sender=Category, request=request, category=context['category'], publishable=None)
         object_rendered.send(sender=Category, request=request, category=context['category'], publishable=None)
         return self.render(request, context, self.get_templates(context, template_name))
     except self.EmptyHomepageException:
         return self.render(request, {}, self.empty_homepage_template_name)
Exemplo n.º 8
0
 def __call__(self, request, **kwargs):
     try:
         context = self.get_context(request, **kwargs)
         cat = context['category']
         template_name = cat.template
         archive_template = cat.app_data.get('ella', {}).get('archive_template', core_settings.ARCHIVE_TEMPLATE)
         if archive_template and not context.get('is_title_page'):
             template_name = archive_template
         object_rendering.send(sender=Category, request=request, category=cat, publishable=None)
         object_rendered.send(sender=Category, request=request, category=cat, publishable=None)
         return self.render(request, context, self.get_templates(context, template_name))
     except self.EmptyHomepageException:
         return self.render(request, {}, self.empty_homepage_template_name)
Exemplo n.º 9
0
def detail(request, category, url_remainder=''):
    path = category.split('/')

    # construct all possible tree_paths and get their IDs from redis
    part = []
    pipe = redis.pipeline()
    for p in path:
        part.append(p)
        pipe.get(REDIS_KEY % '/'.join(part))
    ids = pipe.execute()

    # no IDs -> 404
    if not any(ids):
        raise Http404()
    # get the last ID == the most specific wiki object
    id = filter(None, ids)[-1]
    wiki = get_cached_object(Wiki, pk=id)

    if not (wiki.is_published() or wiki_settings.IS_MODERATOR_FUNC(request.user)):
        # future publish, render if accessed by moderator
        raise Http404()

    # treat the rest as part of custom_urls part
    leftover = category[len(wiki.tree_path):]

    object_rendering.send(sender=Wiki, request=request, category=wiki.category, publishable=wiki)
    context = {
        'category': wiki.category,
        'object': wiki,
        'content_type': wiki.content_type,
    }

    # custom urls
    if leftover or url_remainder:
        url_remainder = ('%s/%s' % (leftover, url_remainder)). strip('/') + '/'
        return custom_urls.resolver.call_custom_view(request, wiki, url_remainder, context)

    # ella API
    response = render_as_api(request, wiki)
    if response:
        return response

    # custom detail
    if custom_urls.resolver.has_custom_detail(wiki):
        return custom_urls.resolver.call_custom_detail(request, context)

    object_rendered.send(sender=Wiki, request=request, category=wiki.category, publishable=wiki)

    return TemplateResponse(request, get_templates_from_publishable('object.html', wiki), context)
Exemplo n.º 10
0
class ObjectDetail(EllaCoreView):
    """
    Renders a page for publishable.  If ``url_remainder`` is specified, tries to
    locate custom view via :meth:`DetailDispatcher.call_view`. If
    :meth:`DetailDispatcher.has_custom_detail` returns ``True``, calls
    :meth:`DetailDispatcher.call_custom_detail`. Otherwise renders a template
    with context containing:

    * object: ``Publishable`` instance representing the URL accessed
    * category: ``Category`` of the ``object``
    * content_type_name: slugified plural verbose name of the publishable's content type
    * content_type: ``ContentType`` of the publishable

    The template is chosen based on the object in question (the first one that matches is used):

    * ``page/category/<tree_path>/content_type/<app>.<model>/<slug>/object.html``
    * ``page/category/<tree_path>/content_type/<app>.<model>/object.html``
    * ``page/category/<tree_path>/object.html``
    * ``page/content_type/<app>.<model>/object.html``
    * ``page/object.html``

    :param request: ``HttpRequest`` from Django
    :param category: ``Category.tree_path`` (empty if home category)
    :param year month day: date matching the `publish_from` field of the `Publishable` object
    :param slug: slug of the `Publishable`
    :param url_remainder: url after the object's url, used to locate custom views in `custom_urls.resolver`

    :raises Http404: if the URL is not valid and/or doesn't correspond to any valid `Publishable`
    """
    template_name = 'object.html'

    class WrongUrl(Http404): pass

    def __call__(self, request, category, slug, year=None, month=None, day=None, id=None, url_remainder=None):
        try:
            context = self.get_context(request, category, slug, year, month, day, id)
        except self.WrongUrl, e:
            message, obj = e.args
            url = obj.get_absolute_url()
            if url_remainder:
                url += url_remainder
            return redirect(url, permanent=True)

        obj = context['object']

        object_rendering.send(sender=context['object'].__class__, request=request, category=context['category'], publishable=context['object'])

        # check for custom actions
        if url_remainder:
            return custom_urls.resolver.call_custom_view(request, obj, url_remainder, context)
        response = render_as_api(request, obj)
        if response:
            return response

        if custom_urls.resolver.has_custom_detail(obj):
            return custom_urls.resolver.call_custom_detail(request, context)

        object_rendered.send(sender=context['object'].__class__, request=request, category=context['category'], publishable=context['object'])

        return self.render(request, context, self.get_templates(context))
Exemplo n.º 11
0
Arquivo: views.py Projeto: Pheox/ella
    def __call__(self, request, **kwargs):
        try:
            context = self.get_context(request, **kwargs)
        except self.EmptyHomepageException:
            return self.render(request, {}, self.empty_homepage_template_name)

        cat = context['category']
        template_name = cat.template
        archive_template = cat.app_data.ella.archive_template

        if archive_template and not context.get('is_title_page'):
            template_name = archive_template

        object_rendering.send(sender=Category, request=request, category=cat, publishable=None)
        object_rendered.send(sender=Category, request=request, category=cat, publishable=None)

        return self.render(request, context, self.get_templates(context, template_name))
Exemplo n.º 12
0
Arquivo: views.py Projeto: Pheox/ella
    def __call__(self, request, **kwargs):
        try:
            context = self.get_context(request, **kwargs)
        except self.EmptyHomepageException:
            return self.render(request, {}, self.empty_homepage_template_name)

        cat = context["category"]
        template_name = cat.template
        archive_template = cat.app_data.ella.archive_template

        if archive_template and not context.get("is_title_page"):
            template_name = archive_template

        object_rendering.send(sender=Category, request=request, category=cat, publishable=None)
        object_rendered.send(sender=Category, request=request, category=cat, publishable=None)

        return self.render(request, context, self.get_templates(context, template_name))
Exemplo n.º 13
0
    def __call__(self, request, category, content_type, slug, year=None, month=None, day=None, id=None, url_remainder=None):
        context = self.get_context(request, category, content_type, slug, year, month, day, id)

        obj = context['object']

        if obj.static and slug != obj.slug:
            return redirect(obj.get_absolute_url(), permanent=True)

        object_rendering.send(sender=context['object'].__class__, request=request, category=context['category'], publishable=context['object'])

        # check for custom actions
        if url_remainder:
            return custom_urls.resolver.call_custom_view(request, obj, url_remainder, context)
        elif custom_urls.resolver.has_custom_detail(obj):
            return custom_urls.resolver.call_custom_detail(request, context)

        object_rendered.send(sender=context['object'].__class__, request=request, category=context['category'], publishable=context['object'])

        return self.render(request, context, self.get_templates(context))
Exemplo n.º 14
0
    def __call__(self, request, **kwargs):
        try:
            context = self.get_context(request, **kwargs)
        except self.EmptyHomepageException:
            return self.render(request, {}, self.empty_homepage_template_name)

        cat = context['category']
        template_name = cat.template
        archive_template = cat.app_data.ella.archive_template

        if archive_template and not context.get('is_title_page'):
            template_name = archive_template

        object_rendering.send(sender=Category, request=request, category=cat, publishable=None)
        object_rendered.send(sender=Category, request=request, category=cat, publishable=None)

        if api_settings.ENABLED:
            for mimetype in (a.split(';')[0] for a in request.META.get('HTTP_ACCEPT', '').split(',')):
                if response_serializer.serializable(mimetype):
                    return response_serializer.serialize(object_serializer.serialize({'category': cat, 'listings': context.get('page', None)}, FULL), mimetype)

        return self.render(request, context, self.get_templates(context, template_name))