mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 11:26:56 -08:00
show number of cast votes in user profile
This commit is contained in:
parent
468a083dfa
commit
89714608ad
3 changed files with 27 additions and 17 deletions
|
@ -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'),
|
||||
|
|
|
@ -109,18 +109,19 @@
|
|||
<p class="small">{{ _('Instance') }}: <a href="{{ url_for('instance.instance_overview', instance_domain=user.instance_domain()) }}">{{ user.instance_domain() }}</a>
|
||||
{% if user.is_instance_admin() or (user.is_local() and user.is_admin()) %}<span class="red">({{ _('Admin') }})</span>{% endif %}<br />
|
||||
{% if user.is_admin() or user.is_staff() %}{{ _('Role permissions') }}: {% if user.is_admin() %}{{ _('Admin') }}{% endif %} {% if user.is_staff() %}{{ _('Staff') }}{% endif %}<br />{% endif %}
|
||||
{% if user.bot %}{{ _('Bot Account') }}<br />{% endif %}
|
||||
{% if current_user.is_authenticated %}{{ _('Note') }}: {{ user.get_note(current_user) }}<br />{% endif %}
|
||||
{{ _('Joined') }}: {{ arrow.get(user.created).humanize(locale=locale) }}<br />
|
||||
{% if current_user.is_authenticated and current_user.is_admin() and user.last_seen %}{{ _('Active') }}: {{ arrow.get(user.last_seen).humanize(locale=locale) }}<br />{% endif %}
|
||||
{% if current_user.is_authenticated and current_user.is_admin() %}{{ _('Referer') }}: <span title="{{ _('Which website linked to PieFed when the user initially registered.') }}">{{ user.referrer if user.referrer }}</span><br />{% endif %}
|
||||
{% if current_user.is_authenticated and current_user.is_admin() %}{{ _('IP and country code') }}: <span title="{{ _('IP address of last interaction.') }}">{{ user.ip_address if user.ip_address }}{% if user.ip_address_country %} ({{ user.ip_address_country }}){% endif %}</span><br />{% endif %}
|
||||
{% if user.bot %}
|
||||
{{ _('Bot Account') }}<br />
|
||||
{% endif %}
|
||||
{{ _('Attitude') }}: <span title="{{ _('Ratio of upvotes cast to downvotes cast. Higher is more positive.') }}">{% if user.attitude %}{{ (user.attitude * 100) | round | int }}%{% endif %}</span><br />
|
||||
{% if current_user.is_authenticated %}{{ _('Attitude') }}: <span title="{{ _('Ratio of upvotes cast to downvotes cast. Higher is more positive.') }}">{% if user.attitude %}{{ (user.attitude * 100) | round | int }}%{% endif %}</span><br />{% endif %}
|
||||
{% if current_user.is_authenticated and current_user.is_admin() and user.reputation %}{{ _('Reputation') }}: <span title="{{ _('Reputation: The Karma of the account. Total up votes minus down votes they got.') }}">{{ user.reputation | round | int }}</span><br />{% endif %}
|
||||
{{ _('Posts') }}: {{ user.post_count }}<br />
|
||||
{{ _('Comments') }}: {{ user.post_reply_count }}<br />
|
||||
{% if current_user.is_authenticated %}{{ _('Note') }}: {{ user.get_note(current_user) }}<br />{% endif %}
|
||||
{% if current_user.is_authenticated and current_user.is_admin() -%}
|
||||
{{ _('Votes') }}: {{ user.get_num_upvotes() }} / {{ user.get_num_downvotes() }}<br />
|
||||
{% if user.referrer %}{{ _('Referer') }}: <span title="{{ _('Which website linked to PieFed when the user initially registered.') }}">{{ user.referrer }}</span><br />{% endif %}
|
||||
{% if user.ip_address %}{{ _('IP and country code') }}: <span title="{{ _('IP address of last interaction.') }}">{{ user.ip_address }} ({{ user.ip_address_country if user.ip_address_country }})</span><br />{% endif %}
|
||||
{% if user.last_seen %}{{ _('Active') }}: {{ arrow.get(user.last_seen).humanize(locale=locale) }}<br />{% endif %}
|
||||
{% endif -%}
|
||||
</p>
|
||||
<div class="profile_bio">
|
||||
{{ user.about_html|safe }}
|
||||
|
|
|
@ -16,18 +16,17 @@
|
|||
</div>
|
||||
<div class="row">
|
||||
<div class="col-auto">
|
||||
<p> {{ _('Joined') }}: {{ arrow.get(user.created).humanize(locale=locale) }}<br />
|
||||
{% if current_user.is_authenticated and current_user.is_admin() %}{{ _('Referer') }}: <span title="{{ _('Which website linked to PieFed when the user initially registered.') }}">{{ user.referrer if user.referrer }}</span><br />{% endif %}
|
||||
{% if current_user.is_authenticated and current_user.is_admin() %}{{ _('IP and country code') }}: <span title="{{ _('IP address of last interaction.') }}">{{ user.ip_address if user.ip_address }}{% if user.ip_address_country %} ({{ user.ip_address_country }}){% endif %}</span><br />{% endif %}
|
||||
{% if current_user.is_authenticated and current_user.is_admin() and user.last_seen %}{{ _('Active') }}: {{ arrow.get(user.last_seen).humanize(locale=locale) }}<br />{% endif %}
|
||||
{% if user.bot %}
|
||||
{{ _('Bot Account') }}<br />
|
||||
{% endif %}
|
||||
{{ _('Attitude') }}: <span title="{{ _('Ratio of upvotes cast to downvotes cast. Higher is more positive.') }}">{% if user.attitude %}{{ (user.attitude * 100) | round | int }}%{% endif %}</span><br />
|
||||
<p>{% if user.bot %}{{ _('Bot Account') }}<br />{% endif %}
|
||||
{% if current_user.is_authenticated %}{{ _('Note') }}: {{ user.get_note(current_user) }}<br />{% endif %}
|
||||
{{ _('Joined') }}: {{ arrow.get(user.created).humanize(locale=locale) }}<br />
|
||||
{% if current_user.is_authenticated %}{{ _('Attitude') }}: <span title="{{ _('Ratio of upvotes cast to downvotes cast. Higher is more positive.') }}">{% if user.attitude %}{{ (user.attitude * 100) | round | int }}%{% endif %}</span><br />{% endif %}
|
||||
{% if current_user.is_authenticated and current_user.is_admin() and user.reputation %}{{ _('Reputation') }}: <span title="{{ _('Reputation: The Karma of the account. Total up votes minus down votes they got.') }}">{{ user.reputation | round | int }}</span><br />{% endif %}
|
||||
{{ _('Posts') }}: {{ user.post_count }}<br />
|
||||
{{ _('Comments') }}: {{ user.post_reply_count }}<br />
|
||||
{% if current_user.is_authenticated %}{{ _('Note') }}: {{ user.get_note(current_user) }}<br />{% endif %}
|
||||
{% if current_user.is_authenticated and current_user.is_admin() -%}
|
||||
{{ _('Votes') }}: {{ user.get_num_upvotes() }} / {{ user.get_num_downvotes() }}<br />
|
||||
{% if user.last_seen %}{{ _('Active') }}: {{ arrow.get(user.last_seen).humanize(locale=locale) }}<br />{% endif %}
|
||||
{% endif -%}
|
||||
</p>
|
||||
<div class="profile_bio">
|
||||
{{ user.about_html|safe }}
|
||||
|
|
Loading…
Reference in a new issue