summaryrefslogtreecommitdiffstats
path: root/askbot/models
diff options
context:
space:
mode:
Diffstat (limited to 'askbot/models')
-rw-r--r--askbot/models/__init__.py5
-rw-r--r--askbot/models/answer.py7
-rw-r--r--askbot/models/base.py6
-rw-r--r--askbot/models/question.py26
4 files changed, 36 insertions, 8 deletions
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index 10a76018..9958c2ed 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -35,6 +35,9 @@ from askbot.startup_tests import run_startup_tests
run_startup_tests()
+def get_model(model_name):
+ return models.get_model('askbot', model_name)
+
User.add_to_class(
'status',
models.CharField(
@@ -1936,4 +1939,6 @@ __all__ = [
#'AuthKeyUserAssociation',
'User',
+
+ 'get_model'
]
diff --git a/askbot/models/answer.py b/askbot/models/answer.py
index 9f48e720..f025a0b7 100644
--- a/askbot/models/answer.py
+++ b/askbot/models/answer.py
@@ -9,7 +9,8 @@ from askbot.models import content
from askbot.models.question import Question
from askbot import const
from askbot.utils.slug import slugify
-
+from askbot.utils import markup
+from askbot.utils.html import sanitize_html
class AnswerManager(models.Manager):
def create_new(
@@ -206,6 +207,10 @@ class AnswerRevision(ContentRevision):
def get_question_title(self):
return self.answer.question.title
+ def as_html(self):
+ markdowner = markup.get_parser()
+ return sanitize_html(markdowner.convert(self.text))
+
class Meta(ContentRevision.Meta):
db_table = u'answer_revision'
ordering = ('-revision',)
diff --git a/askbot/models/base.py b/askbot/models/base.py
index c54d344d..dcd94ab9 100644
--- a/askbot/models/base.py
+++ b/askbot/models/base.py
@@ -193,6 +193,12 @@ class ContentRevision(models.Model):
abstract = True
app_label = 'askbot'
+ def as_html(self):
+ """should return html representation of
+ the revision
+ """
+ raise NotImplementedError()
+
class AnonymousContent(models.Model):
"""
diff --git a/askbot/models/question.py b/askbot/models/question.py
index 82fa60d1..5f914bd5 100644
--- a/askbot/models/question.py
+++ b/askbot/models/question.py
@@ -17,6 +17,8 @@ from askbot.models import content
from askbot import const
from askbot.utils.lists import LazyList
from askbot.utils.slug import slugify
+from askbot.utils import markup
+from askbot.utils.html import sanitize_html
#todo: too bad keys are duplicated see const sort methods
QUESTION_ORDER_BY_MAP = {
@@ -47,6 +49,7 @@ class QuestionManager(models.Manager):
#summary field is denormalized in .save() call
)
if question.wiki:
+ #DATED COMMENT
#todo: this is confusing - last_edited_at field
#is used as an indicator whether question has been edited
#in template askbot/skins/default/templates/post_contributor_info.html
@@ -314,9 +317,6 @@ class Question(content.Content, DeletableContent):
return LazyList(get_data)
- def get_tag_names(self):
- return self.tagnames.split(' ')
-
def get_similarity(self, other_question = None):
"""return number of tags in the other question
that overlap with the current question (self)
@@ -521,18 +521,18 @@ class Question(content.Content, DeletableContent):
if initial_addition:
tags = Tag.objects.get_or_create_multiple(
- self.tagname_list(),
+ self.get_tag_names(),
self.author
)
self.tags.add(*tags)
Tag.objects.update_use_counts(tags)
- def tagname_list(self):
+ def get_tag_names(self):
"""Creates a list of Tag names from the ``tagnames`` attribute."""
- return [name for name in self.tagnames.split(u' ')]
+ return self.tagnames.split(u' ')
def tagname_meta_generator(self):
- return u','.join([unicode(tag) for tag in self.tagname_list()])
+ return u','.join([unicode(tag) for tag in self.get_tag_names()])
def get_absolute_url(self):
return '%s%s' % (
@@ -660,6 +660,9 @@ class FavoriteQuestion(models.Model):
def __unicode__(self):
return '[%s] favorited at %s' %(self.user, self.added_at)
+QUESTION_REVISION_TEMPLATE = ('<h3>%(title)s</h3>\n'
+ '<div class="text">%(html)s</div>\n'
+ '<div class="tags">%(tags)s</div>')
class QuestionRevision(ContentRevision):
"""A revision of a Question."""
question = models.ForeignKey(Question, related_name='revisions')
@@ -677,6 +680,15 @@ class QuestionRevision(ContentRevision):
#print 'in QuestionRevision.get_absolute_url()'
return reverse('question_revisions', args=[self.question.id])
+ def as_html(self):
+ markdowner = markup.get_parser()
+ return QUESTION_REVISION_TEMPLATE % {
+ 'title': self.title,
+ 'html': sanitize_html(markdowner.convert(self.text)),
+ 'tags': ' '.join(['<a class="post-tag">%s</a>' % tag
+ for tag in self.tagnames.split(' ')]),
+ }
+
def save(self, **kwargs):
"""Looks up the next available revision number."""
if not self.revision: