diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2014-01-29 01:37:17 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2014-01-29 01:37:17 -0300 |
commit | 118ec452b18dbefdf5c1cf64502ceb83111c0e2d (patch) | |
tree | 84b4d01bba27a593892cee9ab6c9b8cc2e8bd399 /askbot/models/question.py | |
parent | a896781aba04d189890fde6f09f22b99ea60d08e (diff) | |
download | askbot-118ec452b18dbefdf5c1cf64502ceb83111c0e2d.tar.gz askbot-118ec452b18dbefdf5c1cf64502ceb83111c0e2d.tar.bz2 askbot-118ec452b18dbefdf5c1cf64502ceb83111c0e2d.zip |
fix_question_tags seems to work now
Diffstat (limited to 'askbot/models/question.py')
-rw-r--r-- | askbot/models/question.py | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/askbot/models/question.py b/askbot/models/question.py index 51a4cc2b..987ea434 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -132,6 +132,7 @@ class ThreadManager(BaseQuerySetManager): # TODO: Some of this code will go to Post.objects.create_new language = language or get_language() + tagnames = self.clean_tagnames(tagnames) thread = super( ThreadManager, @@ -1410,19 +1411,38 @@ class Thread(models.Model): silent=silent ) + + def clean_tagnames(self, tagnames): + """Cleans tagnames string so that the field fits the constraint of the + database. + TODO: remove this when the Thread.tagnames field is converted into + text_field + """ + original = tagnames + tagnames = tagnames.strip().split() + #see if the tagnames field fits into 125 bytes + while True: + encoded_tagnames = ' '.join(tagnames).encode('utf-8') + length = len(encoded_tagnames) + if length == 0: + return '' + elif length <= 125: + return ' '.join(tagnames) + else: + tagnames.pop() + + def retag(self, retagged_by=None, retagged_at=None, tagnames=None, silent=False): """changes thread tags""" if None in (retagged_by, retagged_at, tagnames): raise Exception('arguments retagged_at, retagged_by and tagnames are required') - if len(tagnames) > 125:#todo: remove magic number!!! - raise django_exceptions.ValidationError('tagnames value too long') + tagnames = self.clean_tagnames(tagnames) + self.tagnames = tagnames + self.save() thread_question = self._question_post() - self.tagnames = tagnames.strip() - self.save() - # Update the Question itself if silent == False: thread_question.last_edited_at = retagged_at |