Permalink
Browse files

You can now pass a context_variable with a integer to fetch a specifi…

…c object.
  • Loading branch information...
1 parent 8b0a637 commit ce73d89a90cf3bd5e1b1c27a200df2889e35f99f @bartTC committed Mar 20, 2009
Showing with 12 additions and 6 deletions.
  1. +6 −2 README
  2. +3 −3 django_generic_flatblocks/templatetags/generic_flatblocks.py
  3. +3 −1 example_project/templates/example.html
View
8 README
@@ -57,8 +57,8 @@ The arguments in detail:
This will fetch the auth.User with the primary key 1 and renders this model
object with the template "path/to/template.html". In this case, the
- ``generic_object`` in ``None``. Basically this is a ``{% include %}`` Tag on
- model level.
+ ``generic_object`` in ``None``. Basically this is a ``{% include %}`` tag on
+ model level. This can also be a context variable.
- *for* **"applabel.modelname"** (required): The *for* argument defines, what
content-node (model) will be used to store and display the content. The
@@ -155,6 +155,10 @@ example::
Changelog
=========
+**v0.2.1** (2009-03-20)
+ You can now pass a context_variable with a integer to fetch a specific
+ object.
+
**v0.2.0** (2009-03-20)
Added the ability to pass an integer as slug. This will cause that the
templatetag fetches the specific *for* model with the primary key named
@@ -25,8 +25,8 @@ def generate_slug(self, slug, context):
"""
# If the user passed a integer as slug, use it as a primary key in
# self.get_content_object()
- if slug.isdigit():
- return slug
+ if not ',' in slug and isinstance(self.resolve(slug, context), int):
+ return self.resolve(slug, context)
return slugify('_'.join([self.resolve(i, context) for i in slug.split(',')]))
def generate_admin_link(self, related_object, context):
@@ -48,7 +48,7 @@ def get_content_object(self, related_model, slug):
# If the user passed a Integer as a slug, assume that we should fetch
# this specific object
- if slug.isdigit():
+ if isinstance(slug, int):
related_object = related_model._default_manager.get(pk=slug)
print related_object
return None, related_object
@@ -46,7 +46,9 @@
will fetch the model instance with the primary key you named in slug.
Basically this is a {% include %} tag on model level.
{% endcomment %}
- {% gblock 1 for "auth.user" with "current_user.html" %}
+ {% with 1 as admin_user %}
+ {% gblock admin_user for "auth.user" with "current_user.html" %}
+ {% endwith %}
<hr/>
{% comment %}

0 comments on commit ce73d89

Please sign in to comment.