Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removing the flat template_utils pluggable so it can be replaced.

  • Loading branch information...
commit dcf493379dfdc4a6d8373d2525b88b426f71e887 1 parent 1978d71
Bryan Veloso bryanveloso authored
0  applications/template_utils/__init__.py
No changes.
32 applications/template_utils/context_processors.py
... ... @@ -1,32 +0,0 @@
1   -"""
2   -A generic function for generating context processors, and a processor
3   -which adds media-specific settings to each ``RequestContext``.
4   -
5   -"""
6   -
7   -def settings_processor(*settings_list):
8   - """
9   - Generates and returns a context processor function which will read
10   - the values of all the settings passed in and return them in each
11   - ``RequestContext`` in which it is applied.
12   -
13   - For example::
14   -
15   - my_settings_processor = settings_processor('INTERNAL_IPS', 'SITE_ID')
16   -
17   - ``my_settings_processor`` would then be a valid context processor
18   - which would return the values of the settings ``INTERNAL_IPS`` and
19   - ``SITE_ID`` in each ``RequestContext`` in which it was applied.
20   -
21   - """
22   - def _processor(request):
23   - from django.conf import settings
24   - settings_dict = {}
25   - for setting_name in settings_list:
26   - settings_dict[setting_name] = getattr(settings, setting_name)
27   - return settings_dict
28   - return _processor
29   -
30   -media = settings_processor('ADMIN_MEDIA_PREFIX', 'MEDIA_URL')
31   -media.__doc__ = """A context processor which adds the values of the settings
32   -``ADMIN_MEDIA_PREFIX`` and ``MEDIA_URL`` to a ``RequestContext``."""
215 applications/template_utils/markup.py
... ... @@ -1,215 +0,0 @@
1   -"""
2   -Utilities for text-to-HTML conversion.
3   -
4   -"""
5   -
6   -
7   -def textile(text, **kwargs):
8   - """
9   - Applies Textile conversion to a string, and returns the HTML.
10   -
11   - This is simply a pass-through to the ``textile`` template filter
12   - included in ``django.contrib.markup``, which works around issues
13   - PyTextile has with Unicode strings. If you're not using Django but
14   - want to use Textile with ``MarkupFormatter``, you'll need to
15   - supply your own Textile filter.
16   -
17   - """
18   - from django.contrib.markup.templatetags.markup import textile
19   - return textile(text)
20   -
21   -def markdown(text, **kwargs):
22   - """
23   - Applies Markdown conversion to a string, and returns the HTML.
24   -
25   - """
26   - import markdown
27   - return markdown.markdown(text, **kwargs)
28   -
29   -def restructuredtext(text, **kwargs):
30   - """
31   - Applies reStructuredText conversion to a string, and returns the
32   - HTML.
33   -
34   - """
35   - from docutils import core
36   - parts = core.publish_parts(source=text,
37   - writer_name='html4css1',
38   - **kwargs)
39   - return parts['fragment']
40   -
41   -DEFAULT_MARKUP_FILTERS = {
42   - 'textile': textile,
43   - 'markdown': markdown,
44   - 'restructuredtext': restructuredtext
45   - }
46   -
47   -
48   -class MarkupFormatter(object):
49   - """
50   - Generic markup formatter which can handle multiple text-to-HTML
51   - conversion systems.
52   -
53   -
54   - Overview
55   - ========
56   -
57   - Conversion is handled by filter functions registered with an
58   - instance; a set of default filters is provided which cover
59   - Markdown, reStructuredText and Textile (though using one of these
60   - requires the appropriate module to be available on your system --
61   - e.g., using the reST filter requires you to have ``docutils``
62   - installed).
63   -
64   - New filters can be added by registering them with an instance;
65   - simply define a function which performs the conversion you want,
66   - and use the ``register`` method to add it; ``register`` expects
67   - two arguments:
68   -
69   - 1. The name to associate with the filter.
70   -
71   - 2. The actual filter function.
72   -
73   - So, for example, you might define a new filter function called
74   - ``my_filter``, and register it like so::
75   -
76   - formatter = MarkupFormatter()
77   - formatter.register('my_filter', my_filter)
78   -
79   - Instances are callable, so applying the conversion to a string is
80   - simple::
81   -
82   - my_html = formatter(my_string, filter_name='my_filter')
83   -
84   - The filter to use for conversion is determined in either of two
85   - ways:
86   -
87   - 1. If the keyword argument ``filter_name`` is supplied, it will be
88   - used as the filter name.
89   -
90   - 2. Absent an explicit argument, the filter name will be taken from
91   - the ``MARKUP_FILTER`` setting in your Django settings file (see
92   - below).
93   -
94   - Additionally, arbitrary keyword arguments can be supplied, and
95   - they will be passed on to the filter function.
96   -
97   -
98   - Reading default bahavior from a Django setting
99   - ==============================================
100   -
101   - The Django setting ``MARKUP_FILTER`` can be used to specify
102   - default behavior; if used, its value should be a 2-tuple:
103   -
104   - * The first element should be the name of a filter.
105   -
106   - * The second element should be a dictionary to use as keyword
107   - arguments for that filter.
108   -
109   - So, for example, to have the default behavior apply Markdown with
110   - safe mode enabled, you would add this to your Django settings
111   - file::
112   -
113   - MARKUP_FILTER = ('markdown', { 'safe_mode': True })
114   -
115   - The filter named in this setting does not have to be from the
116   - default set; as long as you register a filter of that name before
117   - trying to use the formatter, it will work.
118   -
119   - To have the default behavior apply no conversion whatsoever, set
120   - ``MARKUP_FILTER`` like so::
121   -
122   - MARKUP_FILTER = (None, {})
123   -
124   - When the ``filter_name`` keyword argument is supplied, the
125   - ``MARKUP_FILTER`` setting is ignored entirely -- neither a filter
126   - name nor any keyword arguments will be read from it. This means
127   - that, by always supplying ``filter_name`` explicitly, it is
128   - possible to use this formatter without configuring or even
129   - installing Django.
130   -
131   -
132   - Django and template autoescaping
133   - ================================
134   -
135   - Django's template system defaults to escaping the output of
136   - template variables, which can interfere with functions intended to
137   - return HTML. ``MarkupFormatter`` does not in any way tamper with
138   - Django's autoescaping, so pasing the results of formatting
139   - directly to a Django template will result in that text being
140   - escaped.
141   -
142   - If you need to use ``MarkupFormatter`` for items which will be
143   - passed to a Django template as variables, use the function
144   - ``django.utils.safestring.mark_safe`` to tell Django's template
145   - system not to escape that text.
146   -
147   - For convenience, a Django template filter is included (in
148   - ``templatetags/generic_markup.py``) which applies
149   - ``MarkupFormatter`` to a string and marks the result as not
150   - requiring autoescaping.
151   -
152   -
153   - Examples
154   - ========
155   -
156   - Using the default behavior, with the filter name and arguments
157   - taken from the ``MARKUP_FILTER`` setting::
158   -
159   - formatter = MarkupFormatter()
160   - my_string = 'Lorem ipsum dolor sit amet.\n\nConsectetuer adipiscing elit.'
161   - my_html = formatter(my_string)
162   -
163   - Explicitly naming the filter to use::
164   -
165   - my_html = formatter(my_string, filter_name='markdown')
166   -
167   - Passing keyword arguments::
168   -
169   - my_html = formatter(my_string, filter_name='markdown', safe_mode=True)
170   -
171   - Perform no conversion (return the text as-is)::
172   -
173   - my_html = formatter(my_string, filter_name=None)
174   -
175   - """
176   - def __init__(self):
177   - self._filters = {}
178   - for filter_name, filter_func in DEFAULT_MARKUP_FILTERS.items():
179   - self.register(filter_name, filter_func)
180   -
181   - def register(self, filter_name, filter_func):
182   - """
183   - Registers a new filter for use.
184   -
185   - """
186   - self._filters[filter_name] = filter_func
187   -
188   - def __call__(self, text, **kwargs):
189   - """
190   - Applies text-to-HTML conversion to a string, and returns the
191   - HTML.
192   -
193   - """
194   - if 'filter_name' in kwargs:
195   - filter_name = kwargs['filter_name']
196   - del kwargs['filter_name']
197   - filter_kwargs = {}
198   - else:
199   - from django.conf import settings
200   - filter_name, filter_kwargs = settings.MARKUP_FILTER
201   - if filter_name is None:
202   - return text
203   - if filter_name not in self._filters:
204   - raise ValueError("'%s' is not a registered markup filter. Registered filters are: %s." % (filter_name,
205   - ', '.join(self._filters.iterkeys())))
206   - filter_func = self._filters[filter_name]
207   - filter_kwargs.update(**kwargs)
208   - return filter_func(text, **filter_kwargs)
209   -
210   -
211   -# Unless you need to have multiple instances of MarkupFormatter lying
212   -# around, or want to subclass it, the easiest way to use it is to
213   -# import this instance.
214   -
215   -formatter = MarkupFormatter()
72 applications/template_utils/nodes.py
... ... @@ -1,72 +0,0 @@
1   -"""
2   -Subclass of ``template.Node`` for easy context updating.
3   -
4   -"""
5   -
6   -from django.db.models import get_model
7   -from django.conf import settings
8   -from django import template
9   -
10   -
11   -class ContextUpdatingNode(template.Node):
12   - """
13   - Node that updates the context with certain values.
14   -
15   - Subclasses should define ``get_content()``, which should return a
16   - dictionary to be added to the context.
17   -
18   - """
19   - def render(self, context):
20   - context.update(self.get_content(context))
21   - return ''
22   -
23   - def get_content(self, context):
24   - raise NotImplementedError
25   -
26   -
27   -class GenericContentNode(ContextUpdatingNode):
28   - """
29   - Base Node class for retrieving objects from any model.
30   -
31   - By itself, this class will retrieve a number of objects from a
32   - particular model (specified by an "app_name.model_name" string)
33   - and store them in a specified context variable (these are the
34   - ``num``, ``model`` and ``varname`` arguments to the constructor,
35   - respectively), but is also intended to be subclassed for
36   - customization.
37   -
38   - There are two ways to add extra bits to the eventual database
39   - lookup:
40   -
41   - 1. Add the setting ``GENERIC_CONTENT_LOOKUP_KWARGS`` to your
42   - settings file; this should be a dictionary whose keys are
43   - "app_name.model_name" strings corresponding to models, and whose
44   - values are dictionaries of keyword arguments which will be
45   - passed to ``filter()``.
46   -
47   - 2. Subclass and override ``_get_query_set``; all that's expected
48   - is that it will return a ``QuerySet`` which will be used to
49   - retrieve the object(s). The default ``QuerySet`` for the
50   - specified model (filtered as described above) will be available
51   - as ``self.query_set`` if you want to work with it.
52   -
53   - """
54   - def __init__(self, model, num, varname):
55   - self.num = num
56   - self.varname = varname
57   - lookup_dict = getattr(settings, 'GENERIC_CONTENT_LOOKUP_KWARGS', {})
58   - self.model = get_model(*model.split('.'))
59   - if self.model is None:
60   - raise template.TemplateSyntaxError("Generic content tag got invalid model: %s" % model)
61   - self.query_set = self.model._default_manager.filter(**lookup_dict.get(model, {}))
62   -
63   - def _get_query_set(self):
64   - return self.query_set
65   -
66   - def get_content(self, context):
67   - query_set = self._get_query_set()
68   - if self.num == 1:
69   - result = query_set[0]
70   - else:
71   - result = list(query_set[:self.num])
72   - return { self.varname: result }
0  applications/template_utils/templatetags/__init__.py
No changes.
87 applications/template_utils/templatetags/comparison.py
... ... @@ -1,87 +0,0 @@
1   -"""
2   -Tags for performing basic value comparisons in templates.
3   -
4   -"""
5   -
6   -
7   -from django import template
8   -
9   -
10   -COMPARISON_DICT = {
11   - 'less': lambda x: x < 0,
12   - 'less_or_equal': lambda x: x <= 0,
13   - 'greater_or_equal': lambda x: x >= 0,
14   - 'greater': lambda x: x > 0,
15   - }
16   -
17   -
18   -class ComparisonNode(template.Node):
19   - def __init__(self, var1, var2, comparison, nodelist_true, nodelist_false):
20   - self.var1 = template.Variable(var1)
21   - self.var2 = template.Variable(var2)
22   - self.comparison = comparison
23   - self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false
24   -
25   - def render(self, context):
26   - try:
27   - result = cmp(self.var1.resolve(context),
28   - self.var2.resolve(context))
29   - if COMPARISON_DICT[self.comparison](result):
30   - return self.nodelist_true.render(context)
31   - # If either variable fails to resolve, return nothing.
32   - except template.VariableDoesNotExist:
33   - return ''
34   - # If the types don't permit comparison, return nothing.
35   - except TypeError:
36   - return ''
37   - return self.nodelist_false.render(context)
38   -
39   -
40   -def do_comparison(parser, token):
41   - """
42   - Compares two values.
43   -
44   - Syntax::
45   -
46   - {% if_[comparison] [var1] [var2] %}
47   - ...
48   - {% else %}
49   - ...
50   - {% endif_[comparison] %}
51   -
52   - The {% else %} block is optional, and ``var1`` and ``var2`` may be
53   - variables or literal values.
54   -
55   - Supported comparisons are ``less``, ``less_or_equal``, ``greater``
56   - and ``greater_or_equal``.
57   -
58   - Examples::
59   -
60   - {% if_less some_object.id 3 %}
61   - <p>{{ some_object }} has an id less than 3.</p>
62   - {% endif_less %}
63   -
64   - {% if_greater_or_equal forloop.counter 4 %}
65   - <p>This is at least the fifth time through the loop.</p>
66   - {% else %}
67   - <p>This is one of the first four trips through the loop.</p>
68   - {% endif_greater_or_equal %}
69   -
70   - """
71   - bits = token.contents.split()
72   - if len(bits) != 3:
73   - raise template.TemplateSyntaxError("'%s' tag takes two arguments" % bits[0])
74   - end_tag = 'end' + bits[0]
75   - nodelist_true = parser.parse(('else', end_tag))
76   - token = parser.next_token()
77   - if token.contents == 'else':
78   - nodelist_false = parser.parse((end_tag,))
79   - parser.delete_first_token()
80   - else:
81   - nodelist_false = template.NodeList()
82   - comparison = bits[0].split('if_')[1]
83   - return ComparisonNode(bits[1], bits[2], comparison, nodelist_true, nodelist_false)
84   -
85   -register = template.Library()
86   -for tag_name in ('if_less', 'if_less_or_equal', 'if_greater_or_equal', 'if_greater'):
87   - register.tag(tag_name, do_comparison)
145 applications/template_utils/templatetags/feeds.py
... ... @@ -1,145 +0,0 @@
1   -"""
2   -Tags which can retrieve and parse RSS and Atom feeds, and return the
3   -results for use in templates.
4   -
5   -Based, in part, on the original idea by user baumer1122 and posted to
6   -djangosnippets at http://www.djangosnippets.org/snippets/311/
7   -
8   -"""
9   -
10   -import datetime
11   -import feedparser
12   -from django import template
13   -from django.template.loader import render_to_string
14   -
15   -from template_utils.nodes import ContextUpdatingNode
16   -
17   -
18   -class FeedIncludeNode(template.Node):
19   - def __init__(self, feed_url, template_name, num_items=None):
20   - self.feed_url = template.Variable(feed_url)
21   - self.num_items = num_items
22   - self.template_name = template_name
23   -
24   - def render(self, context):
25   - feed_url = self.feed_url.resolve(context)
26   - feed = feedparser.parse(feed_url)
27   - items = []
28   - num_items = int(self.num_items) or len(feed['entries'])
29   - for i in range(num_items):
30   - pub_date = feed['entries'][i].updated_parsed
31   - published = datetime.date(pub_date[0], pub_date[1], pub_date[2])
32   - items.append({ 'title': feed['entries'][i].title,
33   - 'summary': feed['entries'][i].summary,
34   - 'link': feed['entries'][i].link,
35   - 'date': published })
36   - return render_to_string(self.template_name, { 'items': items,
37   - 'feed': feed })
38   -
39   -
40   -class FeedParserNode(ContextUpdatingNode):
41   - def __init__(self, feed_url, varname):
42   - self.feed_url = template.Variable(feed_url)
43   - self.varname = varname
44   -
45   - def get_content(self, context):
46   - feed_url = self.feed_url.resolve(context)
47   - return { self.varname: feedparser.parse(feed_url) }
48   -
49   -
50   -def do_include_feed(parser, token):
51   - """
52   - Parse an RSS or Atom feed and render a given number of its items
53   - into HTML.
54   -
55   - It is **highly** recommended that you use `Django's template
56   - fragment caching`_ to cache the output of this tag for a
57   - reasonable amount of time (e.g., one hour); polling a feed too
58   - often is impolite, wastes bandwidth and may lead to the feed
59   - provider banning your IP address.
60   -
61   - .. _Django's template fragment caching: http://www.djangoproject.com/documentation/cache/#template-fragment-caching
62   -
63   - Arguments should be:
64   -
65   - 1. The URL of the feed to parse.
66   -
67   - 2. The number of items to render (if not supplied, renders all
68   - items in the feed).
69   -
70   - 3. The name of a template to use for rendering the results into HTML.
71   -
72   - The template used to render the results will receive two variables:
73   -
74   - ``items``
75   - A list of dictionaries representing feed items, each with
76   - 'title', 'summary', 'link' and 'date' members.
77   -
78   - ``feed``
79   - The feed itself, for pulling out arbitrary attributes.
80   -
81   - Requires the Universal Feed Parser, which can be obtained at
82   - http://feedparser.org/. See `its documentation`_ for details of the
83   - parsed feed object.
84   -
85   - .. _its documentation: http://feedparser.org/docs/
86   -
87   - Syntax::
88   -
89   - {% include_feed [feed_url] [num_items] [template_name] %}
90   -
91   - Example::
92   -
93   - {% include_feed "http://www2.ljworld.com/rss/headlines/" 10 feed_includes/ljworld_headlines.html %}
94   -
95   - """
96   - bits = token.contents.split()
97   - if len(bits) == 3:
98   - return FeedIncludeNode(feed_url=bits[1], template_name=bits[2])
99   - elif len(bits) == 4:
100   - return FeedIncludeNode(feed_url=bits[1], num_items=bits[2], template_name=bits[3])
101   - else:
102   - raise template.TemplateSyntaxError("'%s' tag takes either two or three arguments" % bits[0])
103   -
104   -def do_parse_feed(parser, token):
105   - """
106   - Parses a given feed and returns the result in a given context
107   - variable.
108   -
109   - It is **highly** recommended that you use `Django's template
110   - fragment caching`_ to cache the output of this tag for a
111   - reasonable amount of time (e.g., one hour); polling a feed too
112   - often is impolite, wastes bandwidth and may lead to the feed
113   - provider banning your IP address.
114   -
115   - .. _Django's template fragment caching: http://www.djangoproject.com/documentation/cache/#template-fragment-caching
116   -
117   - Arguments should be:
118   -
119   - 1. The URL of the feed to parse.
120   -
121   - 2. The name of a context variable in which to return the result.
122   -
123   - Requires the Universal Feed Parser, which can be obtained at
124   - http://feedparser.org/. See `its documentation`_ for details of the
125   - parsed feed object.
126   -
127   - .. _its documentation: http://feedparser.org/docs/
128   -
129   - Syntax::
130   -
131   - {% parse_feed [feed_url] as [varname] %}
132   -
133   - Example::
134   -
135   - {% parse_feed "http://www2.ljworld.com/rss/headlines/" as ljworld_feed %}
136   -
137   - """
138   - bits = token.contents.split()
139   - if len(bits) != 4:
140   - raise template.TemplateSyntaxError(u"'%s' tag takes three arguments" % bits[0])
141   - return FeedParserNode(bits[1], bits[3])
142   -
143   -register = template.Library()
144   -register.tag('include_feed', do_include_feed)
145   -register.tag('parse_feed', do_parse_feed)
157 applications/template_utils/templatetags/generic_content.py
... ... @@ -1,157 +0,0 @@
1   -"""
2   -Template tags which can do retrieval of content from any model.
3   -
4   -"""
5   -
6   -
7   -from django import template
8   -from django.db.models import get_model
9   -
10   -from template_utils.nodes import ContextUpdatingNode, GenericContentNode
11   -
12   -
13   -class RandomObjectsNode(GenericContentNode):
14   - """
15   - A subclass of ``GenericContentNode`` which overrides
16   - ``_get_query_set`` to apply random ordering.
17   -
18   - """
19   - def _get_query_set(self):
20   - return self.query_set.order_by('?')
21   -
22   -
23   -class RetrieveObjectNode(ContextUpdatingNode):
24   - """
25   - ``Node`` subclass which retrieves a single object -- by
26   - primary-key lookup -- from a given model.
27   -
28   - Because this is a primary-key lookup, it is assumed that no other
29   - filtering is needed; hence, the settings-based filtering performed
30   - by ``GenericContentNode`` is not used here.
31   -
32   - """
33   - def __init__(self, model, pk, varname):
34   - self.pk = template.Variable(pk)
35   - self.varname = varname
36   - self.model = get_model(*model.split('.'))
37   - if self.model is None:
38   - raise template.TemplateSyntaxError("Generic content tag got invalid model: %s" % model)
39   -
40   - def get_content(self, context):
41   - return { self.varname: self.model._default_manager.get(pk=self.pk.resolve(context))}
42   -
43   -
44   -def do_latest_object(parser, token):
45   - """
46   - Retrieves the latest object from a given model, in that model's
47   - default ordering, and stores it in a context variable.
48   -
49   - Syntax::
50   -
51   - {% get_latest_object [app_name].[model_name] as [varname] %}
52   -
53   - Example::
54   -
55   - {% get_latest_object comments.freecomment as latest_comment %}
56   -
57   - """
58   - bits = token.contents.split()
59   - if len(bits) != 4:
60   - raise template.TemplateSyntaxError("'%s' tag takes three arguments" % bits[0])
61   - if bits [2] != 'as':
62   - raise template.TemplateSyntaxError("second argument to '%s' tag must be 'as'" % bits[0])
63   - return GenericContentNode(bits[1], 1, bits[3])
64   -
65   -
66   -def do_latest_objects(parser, token):
67   - """
68   - Retrieves the latest ``num`` objects from a given model, in that
69   - model's default ordering, and stores them in a context variable.
70   -
71   - Syntax::
72   -
73   - {% get_latest_objects [app_name].[model_name] [num] as [varname] %}
74   -
75   - Example::
76   -
77   - {% get_latest_objects comments.freecomment 5 as latest_comments %}
78   -
79   - """
80   - bits = token.contents.split()
81   - if len(bits) != 5:
82   - raise template.TemplateSyntaxError("'%s' tag takes four arguments" % bits[0])
83   - if bits [3] != 'as':
84   - raise template.TemplateSyntaxError("third argument to '%s' tag must be 'as'" % bits[0])
85   - return GenericContentNode(bits[1], bits[2], bits[4])
86   -
87   -def do_random_object(parser, token):
88   - """
89   - Retrieves a random object from a given model, and stores it in a
90   - context variable.
91   -
92   - Syntax::
93   -
94   - {% get_random_object [app_name].[model_name] as [varname] %}
95   -
96   - Example::
97   -
98   - {% get_random_object comments.freecomment as random_comment %}
99   -
100   - """
101   - bits = token.contents.split()
102   - if len(bits) != 4:
103   - raise template.TemplateSyntaxError("'%s' tag takes three arguments" % bits[0])
104   - if bits [2] != 'as':
105   - raise template.TemplateSyntaxError("second argument to '%s' tag must be 'as'" % bits[0])
106   - return RandomObjectsNode(bits[1], 1, bits[3])
107   -
108   -
109   -def do_random_objects(parser, token):
110   - """
111   - Retrieves ``num`` random objects from a given model, and stores
112   - them in a context variable.
113   -
114   - Syntax::
115   -
116   - {% get_random_objects [app_name].[model_name] [num] as [varname] %}
117   -
118   - Example::
119   -
120   - {% get_random_objects comments.freecomment 5 as random_comments %}
121   -
122   - """
123   - bits = token.contents.split()
124   - if len(bits) != 5:
125   - raise template.TemplateSyntaxError("'%s' tag takes four arguments" % bits[0])
126   - if bits [3] != 'as':
127   - raise template.TemplateSyntaxError("third argument to '%s' tag must be 'as'" % bits[0])
128   - return RandomObjectsNode(bits[1], bits[2], bits[4])
129   -
130   -
131   -def do_retrieve_object(parser, token):
132   - """
133   - Retrieves a specific object from a given model by primary-key
134   - lookup, and stores it in a context variable.
135   -
136   - Syntax::
137   -
138   - {% retrieve_object [app_name].[model_name] [pk] as [varname] %}
139   -
140   - Example::
141   -
142   - {% retrieve_object flatpages.flatpage 12 as my_flat_page %}
143   -
144   - """
145   - bits = token.contents.split()
146   - if len(bits) != 5:
147   - raise template.TemplateSyntaxError("'%s' tag takes four arguments" % bits[0])
148   - if bits[3] != 'as':
149   - raise template.TemplateSyntaxError("third argument to '%s' tag must be 'as'" % bits[0])
150   - return RetrieveObjectNode(bits[1], bits[2], bits[4])
151   -
152   -register = template.Library()
153   -register.tag('get_latest_object', do_latest_object)
154   -register.tag('get_latest_objects', do_latest_objects)
155   -register.tag('get_random_object', do_random_object)
156   -register.tag('get_random_objects', do_random_objects)
157   -register.tag('retrieve_object', do_retrieve_object)
47 applications/template_utils/templatetags/generic_markup.py
... ... @@ -1,47 +0,0 @@
1   -"""
2   -Filters for converting plain text to HTML and enhancing the
3   -typographic appeal of text on the Web.
4   -
5   -"""
6   -
7   -
8   -from django.conf import settings
9   -from django.template import Library
10   -from django.utils.safestring import mark_safe
11   -
12   -from template_utils.markup import formatter
13   -
14   -
15   -def apply_markup(value, arg=None):
16   - """
17   - Applies text-to-HTML conversion.
18   -
19   - Takes an optional argument to specify the name of a filter to use.
20   -
21   - """
22   - if arg is not None:
23   - return mark_safe(formatter(value, filter_name=arg))
24   - return formatter(value)
25   -apply_markup.is_safe = True
26   -
27   -def smartypants(value):
28   - """
29   - Applies SmartyPants to a piece of text, applying typographic
30   - niceties.
31   -
32   - Requires the Python SmartyPants library to be installed; see
33   - http://web.chad.org/projects/smartypants.py/
34   -
35   - """
36   - try:
37   - from smartypants import smartyPants
38   - except ImportError:
39   - if settings.DEBUG:
40   - raise template.TemplateSyntaxError("Error in smartypants filter: the Python smartypants module is not installed or could not be imported")
41   - return value
42   - else:
43   - return smartyPants(value)
44   -
45   -register = Library()
46   -register.filter(apply_markup)
47   -register.filter(smartypants)
11 manage.py
... ... @@ -0,0 +1,11 @@
  1 +#!/usr/bin/env python
  2 +from django.core.management import execute_manager
  3 +try:
  4 + import settings # Assumed to be in the same directory.
  5 +except ImportError:
  6 + import sys
  7 + sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
  8 + sys.exit(1)
  9 +
  10 +if __name__ == "__main__":
  11 + execute_manager(settings)

0 comments on commit dcf4933

Please sign in to comment.
Something went wrong with that request. Please try again.