mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Migrate permanencies and add user stats view
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
<div>{{ profile.get_display_name() }}</div>
|
||||
<div class="tools">
|
||||
<a href="{{ url('core:user_profile', user_id=profile.id) }}">{% trans %}Infos{% endtrans %}</a>
|
||||
<a href="{{ url('core:user_stats', user_id=profile.id) }}">{% trans %}Stats{% endtrans %}</a>
|
||||
{% if can_edit(profile, request.user) or user.id == profile.id %}
|
||||
<a href="{{ url('core:user_edit', user_id=profile.id) }}">{% trans %}Edit{% endtrans %}</a>
|
||||
{% endif %}
|
||||
|
18
core/templates/core/user_stats.jinja
Normal file
18
core/templates/core/user_stats.jinja
Normal file
@ -0,0 +1,18 @@
|
||||
{% extends "core/user_base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s stats{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block infos %}
|
||||
{% if profile.permanencies %}
|
||||
<div>
|
||||
<h3>Permanencies</h3>
|
||||
<p>
|
||||
{{ total_time }}
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
@ -31,6 +31,7 @@ urlpatterns = [
|
||||
url(r'^user/(?P<user_id>[0-9]+)/groups$', UserUpdateGroupView.as_view(), name='user_groups'),
|
||||
url(r'^user/tools/$', UserToolsView.as_view(), name='user_tools'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/account$', UserAccountView.as_view(), name='user_account'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/stats$', UserStatsView.as_view(), name='user_stats'),
|
||||
|
||||
# File views
|
||||
# url(r'^file/add/(?P<popup>popup)?$', FileCreateView.as_view(), name='file_new'),
|
||||
|
@ -10,6 +10,8 @@ from django.forms.models import modelform_factory
|
||||
from django.forms import CheckboxSelectMultiple
|
||||
from django.template.response import TemplateResponse
|
||||
from django.conf import settings
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
|
||||
@ -121,6 +123,20 @@ class UserView(CanViewMixin, DetailView):
|
||||
context_object_name = "profile"
|
||||
template_name = "core/user_detail.jinja"
|
||||
|
||||
class UserStatsView(CanViewMixin, DetailView):
|
||||
"""
|
||||
Display a user's stats
|
||||
"""
|
||||
model = User
|
||||
pk_url_kwarg = "user_id"
|
||||
context_object_name = "profile"
|
||||
template_name = "core/user_stats.jinja"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(UserStatsView, self).get_context_data(**kwargs)
|
||||
kwargs['total_time'] = sum([p.end-p.start for p in self.object.permanencies.all()], timedelta())
|
||||
return kwargs
|
||||
|
||||
class UserMiniView(CanViewMixin, DetailView):
|
||||
"""
|
||||
Display a user's profile
|
||||
|
Reference in New Issue
Block a user