improved handling of twitter updates
This commit is contained in:
parent
e7bbc91974
commit
0cf168b393
1 changed files with 41 additions and 20 deletions
|
@ -146,11 +146,16 @@ class Poll(sqlobject.SQLObject):
|
|||
poll_setting[0].value = validated_value
|
||||
elif poll_setting.count() == 0:
|
||||
PollSetting(poll_id=self.id, key=key, value=validated_value)
|
||||
if (key == 'public') and (value > 0):
|
||||
publish_twitter_alert( \
|
||||
config.get('misc','twitter_alert_prefix')+' '+self.title[0:79]+' http://wortschlucker.de/'+self.hash_key, \
|
||||
config.get('misc','twitter_alert_user'), \
|
||||
config.get('misc','twitter_alert_password'))
|
||||
if (key == 'public') and (value > 0):
|
||||
self.announce_via_twitter()
|
||||
|
||||
def announce_via_twitter(self):
|
||||
complete_url = self.get_url(absolute=True)
|
||||
title = "%s %s %s" % (config.get('misc', 'twitter_alert_prefix'),
|
||||
self.title[:79], complete_url)
|
||||
username = config.get('misc', 'twitter_alert_user')
|
||||
password = config.get('misc', 'twitter_alert_password')
|
||||
publish_twitter_alert(title, username, password)
|
||||
|
||||
def get_num_of_submitters(self):
|
||||
all_submitters = [submission.submitter for submission in ContentSubmission.selectBy(poll_id=self.id)]
|
||||
|
@ -175,20 +180,20 @@ class Poll(sqlobject.SQLObject):
|
|||
setting.destroySelf()
|
||||
self.destroySelf()
|
||||
|
||||
def get_url(self):
|
||||
return "%s%s" % (BASE_DICT["base_url"], self.hash_key)
|
||||
def get_url(self, absolute=False):
|
||||
return get_url_string("%s%s" % (BASE_DICT["base_url"], self.hash_key), absolute)
|
||||
|
||||
def get_submit_url(self):
|
||||
return "%s%s/submit" % (BASE_DICT["base_url"], self.hash_key)
|
||||
def get_submit_url(self, absolute=False):
|
||||
return get_url_string("%s%s/submit" % (BASE_DICT["base_url"], self.hash_key), absolute)
|
||||
|
||||
def get_admin_url(self):
|
||||
return "%s%s" % (BASE_DICT["base_url"], self.admin_hash_key)
|
||||
def get_admin_url(self, absolute=False):
|
||||
return get_url_string("%s%s" % (BASE_DICT["base_url"], self.admin_hash_key), absolute)
|
||||
|
||||
def get_edit_url(self):
|
||||
return "%s%s/admin" % (BASE_DICT["base_url"], self.admin_hash_key)
|
||||
def get_edit_url(self, absolute=False):
|
||||
return get_url_string("%s%s/admin" % (BASE_DICT["base_url"], self.admin_hash_key), absolute)
|
||||
|
||||
def get_delete_url(self):
|
||||
return "%s%s/delete" % (BASE_DICT["base_url"], self.admin_hash_key)
|
||||
def get_delete_url(self, absolute=False):
|
||||
return get_url_string("%s%s/delete" % (BASE_DICT["base_url"], self.admin_hash_key), absolute)
|
||||
|
||||
def get_creation_time_string(self):
|
||||
return str(self.timestamp_creation)
|
||||
|
@ -295,6 +300,21 @@ def get_default_values(**kwargs):
|
|||
value_dict[key] = value
|
||||
return value_dict
|
||||
|
||||
def get_url_string(url, absolute=False):
|
||||
""" return the URL as it is or turn it into an absolute URL
|
||||
|
||||
@value url: the given URL
|
||||
@type url: str
|
||||
@value absolute: should the URL be absolute or relative?
|
||||
@type absolute: bool
|
||||
@returns: the relative or absolute URL
|
||||
@rtype: str
|
||||
"""
|
||||
if absolute:
|
||||
return config.get('hosting', 'full_base_url') + url
|
||||
else:
|
||||
return url
|
||||
|
||||
def render(filename, input_data=None, **values):
|
||||
stream = loader.load(filename).generate(**values)
|
||||
if not input_data is None:
|
||||
|
@ -362,10 +382,11 @@ def get_new_hash_key(length=16, charset=None):
|
|||
def publish_twitter_alert(text, user, passwd):
|
||||
api = twitter.Api(username=user, password=passwd)
|
||||
try:
|
||||
api.PostUpdate(text)
|
||||
except:
|
||||
#twitter error, most likely because of a duplicate message
|
||||
pass
|
||||
api.PostUpdate(text)
|
||||
except HTTPError:
|
||||
# twitter error, most likely because of a duplicate message
|
||||
# or maybe an authentication failure
|
||||
pass
|
||||
|
||||
|
||||
@bobo.query('/new')
|
||||
|
@ -632,7 +653,7 @@ def show_one_poll(poll_hash=None, add_related=None, del_related=None):
|
|||
else:
|
||||
return bobo.redirect(BASE_DICT["base_url"])
|
||||
|
||||
@bobo.query('/node/:pagename')
|
||||
@bobo.query('/node/:pagename')
|
||||
def show_static_nodes(pagename=None):
|
||||
""" meant for serving hand-changed, automatically styled content. """
|
||||
value_dict = get_default_values()
|
||||
|
|
Loading…
Reference in a new issue