diff --git a/app/models.py b/app/models.py index 45d8b24d..d83cb360 100644 --- a/app/models.py +++ b/app/models.py @@ -940,6 +940,16 @@ class User(UserMixin, db.Model): else: self.attitude = None + def get_num_upvotes(self): + post_votes = db.session.execute(text('SELECT COUNT(*) FROM "post_vote" WHERE user_id = :user_id AND effect > 0'), {'user_id': self.id}).scalar() + post_reply_votes = db.session.execute(text('SELECT COUNT(*) FROM "post_reply_vote" WHERE user_id = :user_id AND effect > 0'), {'user_id': self.id}).scalar() + return post_votes + post_reply_votes + + def get_num_downvotes(self): + post_votes = db.session.execute(text('SELECT COUNT(*) FROM "post_vote" WHERE user_id = :user_id AND effect < 0'), {'user_id': self.id}).scalar() + post_reply_votes = db.session.execute(text('SELECT COUNT(*) FROM "post_reply_vote" WHERE user_id = :user_id AND effect < 0'), {'user_id': self.id}).scalar() + return post_votes + post_reply_votes + def recalculate_post_stats(self, posts=True, replies=True): if posts: self.post_count = db.session.execute(text('SELECT COUNT(id) as c FROM "post" WHERE user_id = :user_id AND deleted = false'), diff --git a/app/templates/user/show_profile.html b/app/templates/user/show_profile.html index 276c0ea5..8b7cfdbd 100644 --- a/app/templates/user/show_profile.html +++ b/app/templates/user/show_profile.html @@ -109,18 +109,19 @@
{{ _('Instance') }}: {{ user.instance_domain() }}
{% if user.is_instance_admin() or (user.is_local() and user.is_admin()) %}({{ _('Admin') }}){% endif %}
{% if user.is_admin() or user.is_staff() %}{{ _('Role permissions') }}: {% if user.is_admin() %}{{ _('Admin') }}{% endif %} {% if user.is_staff() %}{{ _('Staff') }}{% endif %}
{% endif %}
+ {% if user.bot %}{{ _('Bot Account') }}
{% endif %}
+ {% if current_user.is_authenticated %}{{ _('Note') }}: {{ user.get_note(current_user) }}
{% endif %}
{{ _('Joined') }}: {{ arrow.get(user.created).humanize(locale=locale) }}
- {% if current_user.is_authenticated and current_user.is_admin() and user.last_seen %}{{ _('Active') }}: {{ arrow.get(user.last_seen).humanize(locale=locale) }}
{% endif %}
- {% if current_user.is_authenticated and current_user.is_admin() %}{{ _('Referer') }}: {{ user.referrer if user.referrer }}
{% endif %}
- {% if current_user.is_authenticated and current_user.is_admin() %}{{ _('IP and country code') }}: {{ user.ip_address if user.ip_address }}{% if user.ip_address_country %} ({{ user.ip_address_country }}){% endif %}
{% endif %}
- {% if user.bot %}
- {{ _('Bot Account') }}
- {% endif %}
- {{ _('Attitude') }}: {% if user.attitude %}{{ (user.attitude * 100) | round | int }}%{% endif %}
+ {% if current_user.is_authenticated %}{{ _('Attitude') }}: {% if user.attitude %}{{ (user.attitude * 100) | round | int }}%{% endif %}
{% endif %}
{% if current_user.is_authenticated and current_user.is_admin() and user.reputation %}{{ _('Reputation') }}: {{ user.reputation | round | int }}
{% endif %}
{{ _('Posts') }}: {{ user.post_count }}
{{ _('Comments') }}: {{ user.post_reply_count }}
- {% if current_user.is_authenticated %}{{ _('Note') }}: {{ user.get_note(current_user) }}
{% endif %}
+ {% if current_user.is_authenticated and current_user.is_admin() -%}
+ {{ _('Votes') }}: {{ user.get_num_upvotes() }} / {{ user.get_num_downvotes() }}
+ {% if user.referrer %}{{ _('Referer') }}: {{ user.referrer }}
{% endif %}
+ {% if user.ip_address %}{{ _('IP and country code') }}: {{ user.ip_address }} ({{ user.ip_address_country if user.ip_address_country }})
{% endif %}
+ {% if user.last_seen %}{{ _('Active') }}: {{ arrow.get(user.last_seen).humanize(locale=locale) }}
{% endif %}
+ {% endif -%}
{{ _('Joined') }}: {{ arrow.get(user.created).humanize(locale=locale) }}
- {% if current_user.is_authenticated and current_user.is_admin() %}{{ _('Referer') }}: {{ user.referrer if user.referrer }}
{% endif %}
- {% if current_user.is_authenticated and current_user.is_admin() %}{{ _('IP and country code') }}: {{ user.ip_address if user.ip_address }}{% if user.ip_address_country %} ({{ user.ip_address_country }}){% endif %}
{% endif %}
- {% if current_user.is_authenticated and current_user.is_admin() and user.last_seen %}{{ _('Active') }}: {{ arrow.get(user.last_seen).humanize(locale=locale) }}
{% endif %}
- {% if user.bot %}
- {{ _('Bot Account') }}
- {% endif %}
- {{ _('Attitude') }}: {% if user.attitude %}{{ (user.attitude * 100) | round | int }}%{% endif %}
+
{% if user.bot %}{{ _('Bot Account') }}
{% endif %}
+ {% if current_user.is_authenticated %}{{ _('Note') }}: {{ user.get_note(current_user) }}
{% endif %}
+ {{ _('Joined') }}: {{ arrow.get(user.created).humanize(locale=locale) }}
+ {% if current_user.is_authenticated %}{{ _('Attitude') }}: {% if user.attitude %}{{ (user.attitude * 100) | round | int }}%{% endif %}
{% endif %}
{% if current_user.is_authenticated and current_user.is_admin() and user.reputation %}{{ _('Reputation') }}: {{ user.reputation | round | int }}
{% endif %}
{{ _('Posts') }}: {{ user.post_count }}
{{ _('Comments') }}: {{ user.post_reply_count }}
- {% if current_user.is_authenticated %}{{ _('Note') }}: {{ user.get_note(current_user) }}
{% endif %}
+ {% if current_user.is_authenticated and current_user.is_admin() -%}
+ {{ _('Votes') }}: {{ user.get_num_upvotes() }} / {{ user.get_num_downvotes() }}
+ {% if user.last_seen %}{{ _('Active') }}: {{ arrow.get(user.last_seen).humanize(locale=locale) }}
{% endif %}
+ {% endif -%}