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
|
poll_setting[0].value = validated_value
|
||||||
elif poll_setting.count() == 0:
|
elif poll_setting.count() == 0:
|
||||||
PollSetting(poll_id=self.id, key=key, value=validated_value)
|
PollSetting(poll_id=self.id, key=key, value=validated_value)
|
||||||
if (key == 'public') and (value > 0):
|
if (key == 'public') and (value > 0):
|
||||||
publish_twitter_alert( \
|
self.announce_via_twitter()
|
||||||
config.get('misc','twitter_alert_prefix')+' '+self.title[0:79]+' http://wortschlucker.de/'+self.hash_key, \
|
|
||||||
config.get('misc','twitter_alert_user'), \
|
def announce_via_twitter(self):
|
||||||
config.get('misc','twitter_alert_password'))
|
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):
|
def get_num_of_submitters(self):
|
||||||
all_submitters = [submission.submitter for submission in ContentSubmission.selectBy(poll_id=self.id)]
|
all_submitters = [submission.submitter for submission in ContentSubmission.selectBy(poll_id=self.id)]
|
||||||
|
@ -175,20 +180,20 @@ class Poll(sqlobject.SQLObject):
|
||||||
setting.destroySelf()
|
setting.destroySelf()
|
||||||
self.destroySelf()
|
self.destroySelf()
|
||||||
|
|
||||||
def get_url(self):
|
def get_url(self, absolute=False):
|
||||||
return "%s%s" % (BASE_DICT["base_url"], self.hash_key)
|
return get_url_string("%s%s" % (BASE_DICT["base_url"], self.hash_key), absolute)
|
||||||
|
|
||||||
def get_submit_url(self):
|
def get_submit_url(self, absolute=False):
|
||||||
return "%s%s/submit" % (BASE_DICT["base_url"], self.hash_key)
|
return get_url_string("%s%s/submit" % (BASE_DICT["base_url"], self.hash_key), absolute)
|
||||||
|
|
||||||
def get_admin_url(self):
|
def get_admin_url(self, absolute=False):
|
||||||
return "%s%s" % (BASE_DICT["base_url"], self.admin_hash_key)
|
return get_url_string("%s%s" % (BASE_DICT["base_url"], self.admin_hash_key), absolute)
|
||||||
|
|
||||||
def get_edit_url(self):
|
def get_edit_url(self, absolute=False):
|
||||||
return "%s%s/admin" % (BASE_DICT["base_url"], self.admin_hash_key)
|
return get_url_string("%s%s/admin" % (BASE_DICT["base_url"], self.admin_hash_key), absolute)
|
||||||
|
|
||||||
def get_delete_url(self):
|
def get_delete_url(self, absolute=False):
|
||||||
return "%s%s/delete" % (BASE_DICT["base_url"], self.admin_hash_key)
|
return get_url_string("%s%s/delete" % (BASE_DICT["base_url"], self.admin_hash_key), absolute)
|
||||||
|
|
||||||
def get_creation_time_string(self):
|
def get_creation_time_string(self):
|
||||||
return str(self.timestamp_creation)
|
return str(self.timestamp_creation)
|
||||||
|
@ -295,6 +300,21 @@ def get_default_values(**kwargs):
|
||||||
value_dict[key] = value
|
value_dict[key] = value
|
||||||
return value_dict
|
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):
|
def render(filename, input_data=None, **values):
|
||||||
stream = loader.load(filename).generate(**values)
|
stream = loader.load(filename).generate(**values)
|
||||||
if not input_data is None:
|
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):
|
def publish_twitter_alert(text, user, passwd):
|
||||||
api = twitter.Api(username=user, password=passwd)
|
api = twitter.Api(username=user, password=passwd)
|
||||||
try:
|
try:
|
||||||
api.PostUpdate(text)
|
api.PostUpdate(text)
|
||||||
except:
|
except HTTPError:
|
||||||
#twitter error, most likely because of a duplicate message
|
# twitter error, most likely because of a duplicate message
|
||||||
pass
|
# or maybe an authentication failure
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@bobo.query('/new')
|
@bobo.query('/new')
|
||||||
|
@ -632,7 +653,7 @@ def show_one_poll(poll_hash=None, add_related=None, del_related=None):
|
||||||
else:
|
else:
|
||||||
return bobo.redirect(BASE_DICT["base_url"])
|
return bobo.redirect(BASE_DICT["base_url"])
|
||||||
|
|
||||||
@bobo.query('/node/:pagename')
|
@bobo.query('/node/:pagename')
|
||||||
def show_static_nodes(pagename=None):
|
def show_static_nodes(pagename=None):
|
||||||
""" meant for serving hand-changed, automatically styled content. """
|
""" meant for serving hand-changed, automatically styled content. """
|
||||||
value_dict = get_default_values()
|
value_dict = get_default_values()
|
||||||
|
|
Loading…
Reference in a new issue