diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-11-21 22:20:45 -0500 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-11-21 22:20:45 -0500 |
commit | ee9335d17ca228778123a1968ceccb312863c022 (patch) | |
tree | 4fdfc9364478b9ae0299826e7ad8a0fead9396f0 /askbot/api.py | |
parent | e811e9d5b152c01428a954a44bbab348fbe374e8 (diff) | |
download | askbot-ee9335d17ca228778123a1968ceccb312863c022.tar.gz askbot-ee9335d17ca228778123a1968ceccb312863c022.tar.bz2 askbot-ee9335d17ca228778123a1968ceccb312863c022.zip |
added rename_tags, rename_tags_id and delete_unused_tags management commands
Diffstat (limited to 'askbot/api.py')
-rw-r--r-- | askbot/api.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/askbot/api.py b/askbot/api.py index c79f29dd..8b788016 100644 --- a/askbot/api.py +++ b/askbot/api.py @@ -4,6 +4,7 @@ in the askbot.models module, but api must become a place to manupulate the data in the askbot application so that other implementations of the data storage could be possible """ +from django.db.models import Q from askbot import models from askbot import const @@ -32,3 +33,31 @@ def get_info_on_moderation_items(user): 'seen_count': seen_count, 'new_count': new_count } + +def get_admin(seed_user_id = None): + """returns user objects with id == seed_user_id + if the user with that id is not an administrator, + the function will try to find another admin or moderator + who has the smallest user id + + if the user is not found, or there are no moderators/admins + User.DoesNotExist will be raised + + The reason this function is here and not on a manager of + the user object is because we still patch the django-auth User table + and it's probably better not to patch the manager + """ + + if seed_user_id: + user = models.User.objects.get(id = seed_user_id)#let it raise error here + if user.is_administrator() or user.is_moderator(): + return user + try: + return models.User.objects.filter( + Q(is_superuser=True) | Q(status='m') + ).order_by('id')[0] + except IndexError: + raise models.User.DoesNotExist( + """Please add a moderator or an administrator to the forum first + there don't seem to be any""" + ) |