improved handling of twitter updates

This commit is contained in:
lars 2010-05-30 15:43:42 +00:00
parent e7bbc91974
commit 0cf168b393

View file

@ -147,10 +147,15 @@ class Poll(sqlobject.SQLObject):
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'))
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:
@ -363,8 +383,9 @@ def publish_twitter_alert(text, user, passwd):
api = twitter.Api(username=user, password=passwd)
try:
api.PostUpdate(text)
except:
except HTTPError:
# twitter error, most likely because of a duplicate message
# or maybe an authentication failure
pass