def serialize_full_author(request, author): page_no = 1 if 'p' in request.GET and request.GET['p'].isdigit(): page_no = int(request.GET['p']) paginator = Paginator(author.recently_published(), core_settings.CATEGORY_LISTINGS_PAGINATE_BY) if page_no > paginator.num_pages or page_no < 1: raise Http404('Invalid page number %r' % page_no) return object_serializer.serialize(request, {'author': author, 'listings': paginator.page(page_no)})
def serialize_full_category(request, category): page_no = 1 if 'p' in request.GET and request.GET['p'].isdigit(): page_no = int(request.GET['p']) return object_serializer.serialize(request, { 'category': category, 'listings': category.app_data.ella.get_listings_page(page_no) })
def test_article_is_properly_serialized(self): object_serializer.register(Publishable, lambda r, a: 'Publishable %s' % a.id) object_serializer.register(Article, lambda r, a: 'Article %s' % a.id, FULL) art = Article(id=42) tools.assert_equals('Publishable 42', object_serializer.serialize(None, art))
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))
def serialize_listing(request, listing): return object_serializer.serialize(request, listing.publishable)
def serialize_full_category(request, category): page_no = 1 if 'p' in request.GET and request.GET['p'].isdigit(): page_no = int(request.GET['p']) return object_serializer.serialize(request, {'category': category, 'listings': category.app_data.ella.get_listings_page(page_no)})
def serialize_dict(request, d): return dict((k, object_serializer.serialize(request, v)) for k, v in d.iteritems())
def serialize_list(request, l): return [object_serializer.serialize(request, o) for o in l]
def serialize_list(l): return [object_serializer.serialize(o, 'list') for o in l]
def serialize_listing(listing): return object_serializer.serialize(listing.publishable, PARTIAL)
def serialize_dict(d): return dict((k, object_serializer.serialize(v, FULL)) for k, v in d.iteritems())
def test_article_is_properly_serialized(self): object_serializer.register(Publishable, lambda r, a: "Publishable %s" % a.id) object_serializer.register(Article, lambda r, a: "Article %s" % a.id, FULL) art = Article(id=42) tools.assert_equals("Publishable 42", object_serializer.serialize(None, art))
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) elif 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(obj, FULL), mimetype) 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))