User.name and fullname instead of username

This commit is contained in:
Oleg Lavrovsky 2023-11-28 23:25:53 +01:00
parent 911d936b02
commit b1207e2cc7
No known key found for this signature in database
GPG Key ID: 31E523030632FF4B
9 changed files with 20 additions and 14 deletions

View File

@ -29,7 +29,7 @@ def event_to_data_package(event, author=None, host_url='', full_content=False):
contributors = [] contributors = []
if author and not author.is_anonymous and author.is_admin: if author and not author.is_anonymous and author.is_admin:
contributors.append({ contributors.append({
"title": author.username, "title": author.name,
"path": author.webpage_url or '', "path": author.webpage_url or '',
"role": "author" "role": "author"
}) })

View File

@ -17,7 +17,7 @@ def user_activation_message(user, act_hash):
msg = EmailMessage(from_email=from_email) msg = EmailMessage(from_email=from_email)
msg.subject = 'Your dribdat account' msg.subject = 'Your dribdat account'
msg.body = \ msg.body = \
"Hello %s,\n" % user.username \ "Hello %s,\n" % user.name \
+ "Thanks for signing up at %s\n\n" % base_url \ + "Thanks for signing up at %s\n\n" % base_url \
+ "Tap here to activate your account:\n\n%s" % act_url + "Tap here to activate your account:\n\n%s" % act_url
logging.debug(act_url) logging.debug(act_url)

View File

@ -65,7 +65,7 @@
</td> </td>
<td>{{ project.category.name }}</td> <td>{{ project.category.name }}</td>
<td>{{ project.created_at|format_date }} <td>{{ project.created_at|format_date }}
<small><br>{{ project.user.username }}</small></td> <small><br>{{ project.user.name }}</small></td>
<td>{{ project.updated_at|since_date }}</td> <td>{{ project.updated_at|since_date }}</td>
<td><div class="btn-group"> <td><div class="btn-group">
<a href="{{ url_for('admin.project_view', project_id=project.id) }}" class="btn btn-warning"> <a href="{{ url_for('admin.project_view', project_id=project.id) }}" class="btn btn-warning">

View File

@ -4,7 +4,7 @@
{% if user.carddata %} {% if user.carddata %}
<img src="{{user.carddata}}"/> <img src="{{user.carddata}}"/>
{% endif %} {% endif %}
<span>{{ user.username }}</span> <span>{{ user.name }}</span>
<div class="team-roles"> <div class="team-roles">
{% for role in user.roles %} {% for role in user.roles %}
{% if role.name %} {% if role.name %}

View File

@ -32,7 +32,7 @@
Or contact one of the organisers on this site:</p> Or contact one of the organisers on this site:</p>
<p class="organisers font-weight-bold"> <p class="organisers font-weight-bold">
{% for user in orgs %} {% for user in orgs %}
&nbsp;🕴️<a href="{{ url_for('public.user', username=user.username) }}">{{ user.username }}</a> &nbsp;🕴️<a href="{{ url_for('public.user', username=user.username) }}">{{ user.name }}</a>
{% endfor %} {% endfor %}
</p> </p>
</div><!-- /organiser --> </div><!-- /organiser -->

View File

@ -58,7 +58,7 @@
~ ~
<a class="userlink" <a class="userlink"
href="{{ url_for('public.user', username=s.user.username )}}"> href="{{ url_for('public.user', username=s.user.username )}}">
{{ s.user.username }}</a> {{ s.user.name }}</a>
{% endif %} {% endif %}
</div> </div>
{% if s.ref_url %} {% if s.ref_url %}

View File

@ -43,7 +43,7 @@
<li>Updated: <span>{{ project.updated_at|format_date }}</span> ({{project.score}}% complete)</li> <li>Updated: <span>{{ project.updated_at|format_date }}</span> ({{project.score}}% complete)</li>
<li>Created: <span>{{ project.created_at|format_date }}</span> <li>Created: <span>{{ project.created_at|format_date }}</span>
{% if project.user %} {% if project.user %}
by <a href="{{project.user.webpage_url}}">{{ project.user.username }}</a> by <a href="{{project.user.webpage_url}}">{{ project.user.name }}</a>
{% endif %}</li> {% endif %}</li>
{% if project.category_id %} {% if project.category_id %}
<li>Category: <b>{{ project.category.name }}</b></li> <li>Category: <b>{{ project.category.name }}</b></li>
@ -108,7 +108,7 @@
<li>Updated: <span>{{ project.updated_at|format_date }}</span></li> <li>Updated: <span>{{ project.updated_at|format_date }}</span></li>
<li>Created: <span>{{ project.created_at|format_date }}</span> <li>Created: <span>{{ project.created_at|format_date }}</span>
{% if project.user %} {% if project.user %}
by <a href="{{project.user.webpage_url}}">{{ project.user.username }}</a> by <a href="{{project.user.webpage_url}}">{{ project.user.name }}</a>
{% endif %}</li> {% endif %}</li>
{% if project.category_id %} {% if project.category_id %}
<li>Category: <b>{{ project.category.name }}</b></li> <li>Category: <b>{{ project.category.name }}</b></li>

View File

@ -116,11 +116,13 @@ class User(UserMixin, PkModel):
"""Get JSON representation.""" """Get JSON representation."""
return { return {
'id': self.id, 'id': self.id,
'name': self.name,
'email': self.email, 'email': self.email,
'sso_id': self.sso_id, 'sso_id': self.sso_id,
'active': self.active, 'active': self.active,
'is_admin': self.is_admin, 'is_admin': self.is_admin,
'username': self.username, 'username': self.username,
'fullname': self.fullname,
'webpage_url': self.webpage_url, 'webpage_url': self.webpage_url,
'roles': ",".join([r.name for r in self.roles]), 'roles': ",".join([r.name for r in self.roles]),
'cardtype': self.cardtype, 'cardtype': self.cardtype,
@ -208,19 +210,24 @@ class User(UserMixin, PkModel):
).order_by(Project.id.desc()).all() ).order_by(Project.id.desc()).all()
return projects return projects
def latest_posts(self, max=None): def latest_posts(self, max=None, only_posts=True):
"""Retrieve the latest content from the user.""" """Retrieve the latest content from the user."""
activities = Activity.query.filter_by( activities = Activity.query.filter_by(user_id=self.id)
user_id=self.id, action='post' if only_posts:
).order_by(Activity.timestamp.desc()) activities = activities.filter_by(action='post')
activities = activities.order_by(Activity.timestamp.desc())
if max is not None: if max is not None:
activities = activities.limit(max) activities = activities.limit(max)
posts = [] posts = []
for a in activities.all(): for a in activities.all():
if not a.project.is_hidden: if a.project and not a.project.is_hidden:
posts.append(a.data) posts.append(a.data)
return posts return posts
@property
def name(self):
return self.fullname or self.username
@property @property
def last_active(self): def last_active(self):
"""Retrieve last user activity.""" """Retrieve last user activity."""

View File

@ -13,7 +13,6 @@ class BaseFactory(SQLAlchemyModelFactory):
class Meta: class Meta:
"""Factory configuration.""" """Factory configuration."""
abstract = True abstract = True
sqlalchemy_session = db.session sqlalchemy_session = db.session