summaryrefslogtreecommitdiffstats
path: root/askbot/models/tag.py
diff options
context:
space:
mode:
Diffstat (limited to 'askbot/models/tag.py')
-rw-r--r--askbot/models/tag.py83
1 files changed, 29 insertions, 54 deletions
diff --git a/askbot/models/tag.py b/askbot/models/tag.py
index 2c6e5e67..2f2cf1fd 100644
--- a/askbot/models/tag.py
+++ b/askbot/models/tag.py
@@ -8,6 +8,21 @@ from askbot import const
from askbot.conf import settings as askbot_settings
from askbot.utils import category_tree
+def get_global_group():
+ """Returns the global group,
+ if necessary, creates one
+ """
+ #todo: when groups are disconnected from tags,
+ #find comment as shown below in the test cases and
+ #revert the values
+ #todo: change groups to django groups
+ group_name = askbot_settings.GLOBAL_GROUP_NAME
+ from askbot.models import Group
+ try:
+ return Group.objects.get(name=group_name)
+ except Group.DoesNotExist:
+ return Group.objects.create(name=group_name, is_open=False)
+
def delete_tags(tags):
"""deletes tags in the list"""
tag_ids = [tag.id for tag in tags]
@@ -173,11 +188,7 @@ class TagManager(BaseQuerySetManager):
def get_content_tags(self):
"""temporary function that filters out the group tags"""
- return self.annotate(
- member_count = models.Count('user_memberships')
- ).filter(
- member_count = 0
- )
+ return self.all()
def create(self, name = None, created_by = None, **kwargs):
"""Creates a new tag"""
@@ -267,55 +278,12 @@ class TagManager(BaseQuerySetManager):
return created_tags
-class GroupTagQuerySet(TagQuerySet):
- """Custom query set for the group"""
-
- def get_for_user(self, user=None, private=False):
- if private:
- from askbot.models.group import get_global_group
- global_group = get_global_group()
- return self.filter(
- user_memberships__user=user
- ).exclude(id=global_group.id)
- else:
- return self.filter(user_memberships__user = user)
-
- def get_all(self):
- return self.annotate(
- member_count = models.Count('user_memberships')
- ).filter(
- member_count__gt = 0
- )
-
- def get_by_name(self, group_name = None):
- from askbot.models.group import clean_group_name
- return self.get(name = clean_group_name(group_name))
-
+def clean_group_name(name):
+ """group names allow spaces,
+ tag names do not, so we use this method
+ to replace spaces with dashes"""
+ return re.sub('\s+', '-', name.strip())
-class GroupTagManager(BaseQuerySetManager):
- """manager for group tags"""
-
- def get_query_set(self):
- return GroupTagQuerySet(self.model)
-
- def get_or_create(self, group_name = None, user = None, is_open=True):
- """creates a group tag or finds one, if exists"""
- #todo: here we might fill out the group profile
-
- #replace spaces with dashes
- from askbot.models.group import clean_group_name
- group_name = clean_group_name(group_name)
- try:
- #iexact is important!!! b/c we don't want case variants
- #of tags
- tag = self.get(name__iexact = group_name)
- except self.model.DoesNotExist:
- tag = self.model(name = group_name, created_by = user)
- tag.save()
- from askbot.models.user import GroupProfile
- group_profile = GroupProfile(group_tag = tag, is_open=is_open)
- group_profile.save()
- return tag
class Tag(models.Model):
#a couple of status constants
@@ -346,7 +314,6 @@ class Tag(models.Model):
)
objects = TagManager()
- group_tags = GroupTagManager()
class Meta:
app_label = 'askbot'
@@ -368,3 +335,11 @@ class MarkedTag(models.Model):
class Meta:
app_label = 'askbot'
+
+def get_groups():
+ from askbot.models import Group
+ return Group.objects.all()
+
+def get_group_names():
+ #todo: cache me
+ return get_groups().values_list('name', flat = True)