2010-01-15 20:55:30 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# ScribeEngine - Open Source Blog Software #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2010 Raoul Snyman #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
Helper functions
|
|
|
|
|
|
|
|
Consists of functions to typically be used within templates, but also
|
|
|
|
available to Controllers. This module is available to both as 'h'.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from webhelpers.html import escape, HTML, literal, url_escape
|
|
|
|
from webhelpers.date import distance_of_time_in_words
|
2010-01-31 13:45:20 +00:00
|
|
|
from pylons import session, url as url_for
|
2010-01-15 20:55:30 +00:00
|
|
|
from pylons.controllers.util import redirect_to
|
|
|
|
|
|
|
|
class Flash(object):
|
2010-01-16 23:19:42 +00:00
|
|
|
def set_message(self, message_text, message_type, message_head=None):
|
2010-01-15 20:55:30 +00:00
|
|
|
session[u'flash.text'] = message_text
|
|
|
|
session[u'flash.type'] = message_type
|
2010-01-16 23:19:42 +00:00
|
|
|
session[u'flash.head'] = message_head
|
2010-01-15 20:55:30 +00:00
|
|
|
session.save()
|
|
|
|
|
|
|
|
def has_message(self):
|
2010-01-16 23:19:42 +00:00
|
|
|
return session.get(u'flash.text')
|
|
|
|
|
|
|
|
def has_header(self):
|
|
|
|
return session.get(u'flash.head')
|
2010-01-15 20:55:30 +00:00
|
|
|
|
|
|
|
def get_message_text(self):
|
|
|
|
message_text = session.pop(u'flash.text', None)
|
|
|
|
if not message_text:
|
|
|
|
return None
|
|
|
|
session.save()
|
|
|
|
return message_text
|
|
|
|
|
|
|
|
def get_message_type(self):
|
|
|
|
message_type = session.pop(u'flash.type', None)
|
|
|
|
if not message_type:
|
|
|
|
return None
|
|
|
|
session.save()
|
|
|
|
return message_type
|
|
|
|
|
|
|
|
|
2010-01-27 07:26:47 +00:00
|
|
|
def teaser(text):
|
2010-01-15 20:55:30 +00:00
|
|
|
position = text.find(u'</p>')
|
|
|
|
if position > 0:
|
2010-01-22 11:09:20 +00:00
|
|
|
return text[:position + 4]
|
2010-01-15 20:55:30 +00:00
|
|
|
elif len(text) > 300:
|
|
|
|
text = text[:297]
|
|
|
|
position = len(text) - 1
|
|
|
|
while position > 0 and text[position] not in [u'<', u'>']:
|
|
|
|
position -= 1
|
|
|
|
if position != 0 and text[position + 1] == u'/':
|
|
|
|
position -= 1
|
|
|
|
while position > 0 and text[position] not in [u'<']:
|
|
|
|
position -= 1
|
|
|
|
if position != 0 and text[position] == u'<':
|
|
|
|
text = text[:position]
|
|
|
|
return text
|
|
|
|
|
2010-01-18 22:29:50 +00:00
|
|
|
def url_for_post(post):
|
|
|
|
#TODO: this is hard coded.
|
|
|
|
return url_for(
|
2010-01-22 11:09:20 +00:00
|
|
|
controller='blog',
|
2010-01-18 22:29:50 +00:00
|
|
|
action='view',
|
2010-01-22 11:09:20 +00:00
|
|
|
year=post.created.strftime('%Y'),
|
|
|
|
month=post.created.strftime('%m'),
|
|
|
|
day=post.created.strftime('%d'),
|
2010-01-18 22:29:50 +00:00
|
|
|
url=post.url
|
|
|
|
)
|
2010-01-18 20:16:46 +00:00
|
|
|
|
2010-01-15 20:55:30 +00:00
|
|
|
flash = Flash()
|