diff options
-rw-r--r-- | askbot/doc/source/askbot/layout.html | 8 | ||||
-rw-r--r-- | askbot/doc/source/download.rst | 6 | ||||
-rw-r--r-- | askbot/doc/source/management-commands.rst | 7 | ||||
-rw-r--r-- | askbot/feed.py | 6 | ||||
-rw-r--r-- | askbot/management/commands/get_tag_stats.py | 147 | ||||
-rw-r--r-- | askbot/models/question.py | 15 | ||||
-rwxr-xr-x | askbot/skins/default/media/style/style.css | 2 |
7 files changed, 179 insertions, 12 deletions
diff --git a/askbot/doc/source/askbot/layout.html b/askbot/doc/source/askbot/layout.html index fadbe537..507f3fcb 100644 --- a/askbot/doc/source/askbot/layout.html +++ b/askbot/doc/source/askbot/layout.html @@ -4,11 +4,11 @@ <ul> <li class="first"><a href="/">Home (forum)</a></li> <span class="sep">|</span> - <li><a href="/doc/about.html">About</a></li> - <span class="sep">|</span> + {#<li><a href="/doc/about.html">About</a></li> + <span class="sep">|</span>#} <li><a href="/doc/index.html">Documentation</a></li> - <span class="sep">|</span> - <li><a href="/doc/download.html">Download</a></li> + {#<span class="sep">|</span> + <li><a href="/doc/download.html">Download</a></li>#} </ul> </div> {% endblock %} diff --git a/askbot/doc/source/download.rst b/askbot/doc/source/download.rst new file mode 100644 index 00000000..d6172fec --- /dev/null +++ b/askbot/doc/source/download.rst @@ -0,0 +1,6 @@ +=============== +Download Askbot +=============== + +The entire source code for the Askbot Q & A forum can be downloaded +at the Python Package index diff --git a/askbot/doc/source/management-commands.rst b/askbot/doc/source/management-commands.rst index 0e2002b4..e9a34cc3 100644 --- a/askbot/doc/source/management-commands.rst +++ b/askbot/doc/source/management-commands.rst @@ -39,6 +39,13 @@ The bulk of the management commands fall into this group and will probably be th | `dump_forum [--dump-name | Save forum contents into a file. `--dump-name` parameter is | | some_name`] | optional | +---------------------------------+-------------------------------------------------------------+ +| `get_tag_stats [-u|-t] [-e]` | Print tag subscription statistics, per tag (option -t) | +| | or per user (option -u), if option -e is given, empty | +| | records will be shown too (longer versions of the options | +| | are: --per-tag-subscription-counts for -t, | +| | --per-user-tag-subscription-counts for -u, and --print-empty| +| | for -e). | ++---------------------------------+-------------------------------------------------------------+ | `load_forum <file_name>` | Load forum data from a file saved by the `dump_forum` | | | command | +---------------------------------+-------------------------------------------------------------+ diff --git a/askbot/feed.py b/askbot/feed.py index 71a85b86..23416677 100644 --- a/askbot/feed.py +++ b/askbot/feed.py @@ -45,6 +45,12 @@ class RssLastestQuestionsFeed(Feed): """ return item.added_at + def item_guid(self, item): + """returns url without the slug + because the slug can change + """ + return self.link + item.get_absolute_url(no_slug = True) + def items(self, item): """get questions for the feed """ diff --git a/askbot/management/commands/get_tag_stats.py b/askbot/management/commands/get_tag_stats.py new file mode 100644 index 00000000..7bbae904 --- /dev/null +++ b/askbot/management/commands/get_tag_stats.py @@ -0,0 +1,147 @@ +import sys +import optparse +from django.core.management.base import BaseCommand, CommandError +from askbot import models + +def get_tag_lines(tag_marks, width = 25): + output = list() + line = '' + for mark in tag_marks: + name = mark.tag.name + if line == '': + line = name + elif len(line) + len(name) + 1 > width: + output.append(line) + line = name + else: + line += ' ' + name + output.append(line) + return output + +def get_empty_lines(num_lines): + output = list() + for idx in xrange(num_lines): + output.append('') + return output + +def pad_list(the_list, length): + if len(the_list) < length: + the_list.extend(get_empty_lines(length - len(the_list))) + +def format_table_row(*cols, **kwargs): + max_len = max(map(len, cols)) + for col in cols: + pad_list(col, max_len) + + output = list() + for idx in xrange(max_len): + bits = list() + for col in cols: + bits.append(col[idx]) + line = kwargs['format_string'] % tuple(bits) + output.append(line) + + return output + + +class Command(BaseCommand): + help = """Dumps askbot forum data into the file for the later use with "load_forum". +The extension ".json" will be added automatically.""" + + option_list = BaseCommand.option_list + ( + optparse.make_option( + '-t', + '--sub-counts', + action = 'store_true', + default = False, + dest = 'sub_counts', + help = 'Print tag subscription statistics, for all tags, listed alphabetically' + ), + optparse.make_option( + '-u', + '--user-sub-counts', + action = 'store_true', + default = False, + dest = 'user_sub_counts', + help = 'Print tag subscription data per user, with users listed alphabetically' + ), + optparse.make_option( + '-e', + '--print-empty', + action = 'store_true', + default = False, + dest = 'print_empty', + help = 'Print empty records too (with zero counts)' + ), + ) + def handle(self, *args, **options): + if not(options['sub_counts'] ^ options['user_sub_counts']): + raise CommandError('Please use either -u or -t (but not both)') + + print '' + if options['sub_counts']: + self.print_sub_counts(options['print_empty']) + + if options['user_sub_counts']: + self.print_user_sub_counts(options['print_empty']) + print '' + + def print_user_sub_counts(self, print_empty): + """prints list of users and what tags they follow/ignore + """ + users = models.User.objects.all().order_by('username') + item_count = 0 + for user in users: + tag_marks = user.tag_selections + followed_tags = tag_marks.filter(reason='good') + ignored_tags = tag_marks.filter(reason='bad') + followed_count = followed_tags.count() + ignored_count = ignored_tags.count() + if followed_count == 0 and ignored_count == 0 and print_empty == False: + continue + if item_count == 0: + print '%-28s %25s %25s' % ('User (id)', 'Interesting tags', 'Ignored tags') + print '%-28s %25s %25s' % ('=========', '================', '============') + followed_lines = get_tag_lines(followed_tags, width = 25) + ignored_lines = get_tag_lines(ignored_tags, width = 25) + user_string = '%s (%d)' % (user.username, user.id) + output_lines = format_table_row( + [user.username,], + followed_lines, + ignored_lines, + format_string = '%-28s %25s %25s' + ) + item_count += 1 + for line in output_lines: + print line + print '' + + self.print_postamble(item_count) + + def print_sub_counts(self, print_empty): + """prints subscription counts for + each tag (ignored and favorite counts) + """ + tags = models.Tag.objects.all().order_by('name') + item_count = 0 + for tag in tags: + tag_marks = tag.user_selections + follow_count = tag_marks.filter(reason='good').count() + ignore_count = tag_marks.filter(reason='bad').count() + if follow_count + ignore_count == 0 and print_empty == False: + continue + if item_count == 0: + print '%-32s %12s %12s' % ('Tag name', 'Interesting', 'Ignored') + print '%-32s %12s %12s' % ('========', '===========', '=======') + print '%-32s %12d %12d' % (tag.name, follow_count, ignore_count) + item_count += 1 + + self.print_postamble(item_count) + + def print_postamble(self, item_count): + print '' + if item_count == 0: + print 'Did not find anything' + else: + print '%d records shown' % item_count + print 'Since -e option was not selected, empty records were hidden' diff --git a/askbot/models/question.py b/askbot/models/question.py index 2a2a36f0..0f4a0027 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -537,9 +537,9 @@ class Question(content.Content, DeletableContent): self.tagnames = tagnames if silent == False: self.last_edited_at = retagged_at - self.last_activity_at = retagged_at + #self.last_activity_at = retagged_at self.last_edited_by = retagged_by - self.last_activity_by = retagged_by + #self.last_activity_by = retagged_by self.save() # Update the Question's tag associations @@ -640,11 +640,12 @@ class Question(content.Content, DeletableContent): def tagname_meta_generator(self): return u','.join([unicode(tag) for tag in self.get_tag_names()]) - def get_absolute_url(self): - return '%s%s' % ( - reverse('question', args=[self.id]), - django_urlquote(slugify(self.title)) - ) + def get_absolute_url(self, no_slug = False): + url = reverse('question', args=[self.id]) + if no_slug == True: + return url + else: + return url + django_urlquote(slugify(self.title)) def has_favorite_by_user(self, user): if not user.is_authenticated(): diff --git a/askbot/skins/default/media/style/style.css b/askbot/skins/default/media/style/style.css index c73998d3..8a3dedf1 100755 --- a/askbot/skins/default/media/style/style.css +++ b/askbot/skins/default/media/style/style.css @@ -149,7 +149,7 @@ blockquote { #CAFull { float: left; - padding: 0 5px; + padding: 0 5px 10px 5px; width: 950px; } |