added group membership and post count display to topics

This commit is contained in:
Tian Mi UROP 2013-07-08 16:08:50 +00:00
parent 868ffd5678
commit 612cbd88f1
3 changed files with 46 additions and 3 deletions

View file

@ -79,6 +79,23 @@
<dd class="postavatar">
<a href="{% url profile_detail post.user.username %}"><img src="{% image_url post.user '90x90' %}" width="90" height="90"></a>
</dd>
{{ group_titles|dict_lookup:post.user }}
<br>
{% if post.user.forum_profile.post_count > 1000 %}
{% trans "1000+ posts" %}
{% elif post.user.forum_profile.post_count > 500 %}
{% trans "500+ posts" %}
{% elif post.user.forum_profile.post_count > 100 %}
{% trans "100+ posts" %}
{% elif post.user.forum_profile.post_count == 1 %}
{% trans "1 post" %}
{% else %}
{{ post.user.forum_profile.post_count }} {% trans " posts" %}
{% endif %}
{% if moderator %}
{% if post.user.forum_profile.location %}
<dd class="moderator-only">{% trans "From:" %} {{ post.user.forum_profile.location }}</dd>

View file

@ -289,4 +289,8 @@ def set_theme_style(user):
static_url=settings.STATIC_URL,
theme=selected_theme
)
@register.filter
def dict_lookup(dictionary, key):
return dictionary.get(key)

View file

@ -35,7 +35,6 @@ from djangobb_forum.util import build_form, paginate, set_language, smiles, conv
def index(request, full=True):
users_cached = cache.get('djangobb_users_online', {})
users_online = users_cached and User.objects.filter(id__in=users_cached.keys()) or []
@ -393,7 +392,7 @@ def show_topic(request, topic_id, full=True):
# without specifying, following query wouldn't select related properly
posts = topic.posts.select_related('user__userprofile',
'user__forum_profile',
'updated_by').all()
'updated_by', 'user__groups', 'user').all()
edit_start = timezone.now() - timedelta(minutes=1)
edit_end = timezone.now()
editable = posts.filter(created__range=(edit_start, edit_end)).filter(user_id=request.user.id)
@ -432,6 +431,24 @@ def show_topic(request, topic_id, full=True):
**post_form_kwargs
)
group_titles = {}
for post in posts:
if post.user.is_superuser:
group_titles[post.user] = "Scratch Team"
else:
temp_names = [x.name for x in post.user.groups.all()]
if "Forum Moderators" in temp_names:
group_titles[post.user] = "Forum Moderator"
elif "Scratchers" in temp_names:
group_titles[post.user] = "Scratcher"
elif "New Scratchers" in temp_names:
group_titles[post.user] = "New to Scratch"
else:
group_titles[post.user] = "Ungrouped"
# handle poll, if exists
poll_form = None
polls = topic.poll_set.all()
@ -480,7 +497,8 @@ def show_topic(request, topic_id, full=True):
'poll_form': poll_form,
'editable': editable,
'can_edit': can_edit,
'can_close': can_close
'can_close': can_close,
'group_titles': group_titles,
})
else:
return render(request, 'djangobb_forum/mobile/topic.html', {'categories': Category.objects.all(),
@ -490,7 +508,11 @@ def show_topic(request, topic_id, full=True):
'poll_form': poll_form,
'reply_form': reply_form,
})
def show_unread_posts(request, topic_id, full=True):
post = None
user = request.user