forked from github/pelican
Fixed page_name call to adapt to the link structure provided by the
Settings file. Also updated the documentation accordingly. Update documentation to cover new page_name behavior Fixed page_name to adapt to the links provided by the Settings file. Includes documentation updates as well. Updated terms to maintain better syntax and consistancy Added docstring to _from_settings() to clarify the get_page_name argument that was added. Explains why/when this argument is used. Revert contents.py back to commit 2f29c51 Re-added docstring to _get_settings method, but this time not deleting things I shouldn't Corrected readability change that was altered during revert.
This commit is contained in:
parent
e89b32511d
commit
41fdfa63b1
4 changed files with 31 additions and 22 deletions
|
|
@ -183,15 +183,23 @@ class URLWrapper(object):
|
|||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
def _from_settings(self, key):
|
||||
def _from_settings(self, key, get_page_name=False):
|
||||
"""Returns URL information as defined in settings.
|
||||
When get_page_name=True returns URL without anything after {slug}
|
||||
e.g. if in settings: CATEGORY_URL="cat/{slug}.html" this returns "cat/{slug}"
|
||||
Useful for pagination."""
|
||||
setting = "%s_%s" % (self.__class__.__name__.upper(), key)
|
||||
value = self.settings[setting]
|
||||
if not isinstance(value, basestring):
|
||||
logger.warning(u'%s is set to %s' % (setting, value))
|
||||
return value
|
||||
else:
|
||||
return unicode(value).format(**self.as_dict())
|
||||
if get_page_name:
|
||||
return unicode(value[:value.find('{slug}') + len('{slug}')]).format(**self.as_dict())
|
||||
else:
|
||||
return unicode(value).format(**self.as_dict())
|
||||
|
||||
page_name = property(functools.partial(_from_settings, key='URL', get_page_name=True))
|
||||
url = property(functools.partial(_from_settings, key='URL'))
|
||||
save_as = property(functools.partial(_from_settings, key='SAVE_AS'))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue