mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Added retry for the Reddit flair, also some better error checking
This commit is contained in:
@@ -83,11 +83,22 @@ def queue_account_updates(update_delay=604800, batch_size=50):
|
|||||||
update_account.delay(username=acc.pk)
|
update_account.delay(username=acc.pk)
|
||||||
|
|
||||||
|
|
||||||
@task(ignore_result=True)
|
class update_user_flair(Task):
|
||||||
def update_user_flair(username, character_name):
|
"""
|
||||||
try:
|
Updates a user's flair on Reddit
|
||||||
ib = Flair(username=settings.REDDIT_USER, password=settings.REDDIT_PASSWORD)
|
"""
|
||||||
ib.set_flair(settings.REDDIT_SUBREDDIT, username, character_name, '')
|
|
||||||
except LoginError, exc:
|
default_retry_delay = 5 * 60 # retry in 5 minutes
|
||||||
logger.error("Error logging into Reddit")
|
ignore_result = True
|
||||||
|
|
||||||
|
def run(self, username, character_name, **kwargs):
|
||||||
|
try:
|
||||||
|
ib = Flair(username=settings.REDDIT_USER, password=settings.REDDIT_PASSWORD)
|
||||||
|
ib.set_flair(settings.REDDIT_SUBREDDIT, username, character_name, '')
|
||||||
|
except (HTTPError, URLError), exc:
|
||||||
|
logger.error("Error updating flair, queueing for retry")
|
||||||
|
update_user_flair.retry(args=[username, character_name], kwargs=kwargs, exc=exc)
|
||||||
|
pass
|
||||||
|
except LoginError, exc:
|
||||||
|
logger.error("Error logging into Reddit")
|
||||||
|
|
||||||
|
|||||||
@@ -293,18 +293,22 @@ def primarychar_change(request):
|
|||||||
@login_required
|
@login_required
|
||||||
def toggle_reddit_tagging(request):
|
def toggle_reddit_tagging(request):
|
||||||
profile = request.user.get_profile()
|
profile = request.user.get_profile()
|
||||||
profile.tag_reddit_accounts = not profile.tag_reddit_accounts
|
if profile.primary_character:
|
||||||
profile.save()
|
profile.tag_reddit_accounts = not profile.tag_reddit_accounts
|
||||||
if profile.tag_reddit_accounts:
|
profile.save()
|
||||||
tag = 'Enabled'
|
if profile.tag_reddit_accounts:
|
||||||
else:
|
tag = 'Enabled'
|
||||||
tag = 'Disabled'
|
else:
|
||||||
messages.add_message(request, messages.INFO, "Reddit account tagging is now %s" % tag)
|
tag = 'Disabled'
|
||||||
|
messages.add_message(request, messages.INFO, "Reddit account tagging is now %s" % tag)
|
||||||
|
|
||||||
if profile.tag_reddit_accounts:
|
if profile.tag_reddit_accounts:
|
||||||
name = profile.primary_character.name
|
name = profile.primary_character.name
|
||||||
|
else:
|
||||||
|
name = ''
|
||||||
|
for acc in request.user.redditaccount_set.all():
|
||||||
|
update_user_flair.delay(acc.username, name)
|
||||||
else:
|
else:
|
||||||
name = ''
|
messages.add_message(request, messages.ERROR, "You need to set a primary character before using this feature!")
|
||||||
for acc in request.user.redditaccount_set.all():
|
|
||||||
update_user_flair.delay(acc.username, name)
|
|
||||||
return redirect('sso.views.profile')
|
return redirect('sso.views.profile')
|
||||||
|
|||||||
Reference in New Issue
Block a user