mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Add basic account view for user and refactor user tool bar
This commit is contained in:
23
core/migrations/0004_preferences.py
Normal file
23
core/migrations/0004_preferences.py
Normal file
@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0003_auto_20160705_2304'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Preferences',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
||||
('show_my_stats', models.BooleanField(verbose_name='define if we show a users stats', default=False, help_text='Show your account statistics to others')),
|
||||
('user', models.OneToOneField(related_name='preferences', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
@ -280,6 +280,14 @@ class AnonymousUser(AuthAnonymousUser):
|
||||
def get_display_name(self):
|
||||
return _("Visitor")
|
||||
|
||||
class Preferences(models.Model):
|
||||
user = models.OneToOneField(User, related_name="preferences")
|
||||
show_my_stats = models.BooleanField(
|
||||
_('define if we show a users stats'),
|
||||
default=False,
|
||||
help_text=_('Show your account statistics to others'),
|
||||
)
|
||||
|
||||
class LockError(Exception):
|
||||
"""There was a lock error on the object"""
|
||||
pass
|
||||
|
29
core/templates/core/user_base.jinja
Normal file
29
core/templates/core/user_base.jinja
Normal file
@ -0,0 +1,29 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block content %}
|
||||
<div>{{ profile.get_display_name() }}</div>
|
||||
<div class="tool-bar">
|
||||
<a href="{{ url('core:user_profile', user_id=profile.id) }}">Infos</a>
|
||||
{% if can_edit(profile, request.user) or user.id == profile.id %}
|
||||
<a href="{{ url('core:user_edit', user_id=profile.id) }}">Edit</a>
|
||||
{% endif %}
|
||||
{% if can_edit_prop(profile, request.user) %}
|
||||
<a href="{{ url('core:user_prop', user_id=profile.id) }}">Props</a>
|
||||
{% endif %}
|
||||
{% if (profile == request.user
|
||||
or request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name'])
|
||||
or request.user.is_in_group(settings.SITH_GROUPS['root']['name'])) %}
|
||||
<a href="{{ url('core:user_account', user_id=profile.id) }}">Account</a>
|
||||
{% endif %}
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{% block infos %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -1,22 +1,12 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
{% extends "core/user_base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{{ profile.get_display_name() }}'s profile
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="edit-bar">
|
||||
{% if can_edit(profile, request.user) or user.id == profile.id %}
|
||||
<a href="{{ url('core:user_edit', user_id=profile.id) }}">Edit</a>
|
||||
{% endif %}
|
||||
{% if can_edit_prop(profile, request.user) %}
|
||||
<a href="{{ url('core:user_prop', user_id=profile.id) }}">Props</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% block infos %}
|
||||
<h3>User Profile</h3>
|
||||
|
||||
<hr>
|
||||
<div class="user_profile">
|
||||
<h4>{{ profile.get_full_name() }}</h4>
|
||||
<p>{{ profile.nick_name }}</p>
|
||||
@ -24,6 +14,7 @@
|
||||
</div>
|
||||
|
||||
{% if user.membership.filter(end_date=None).exists() %}
|
||||
{# if the user is member of a club, he can view the subscription state #}
|
||||
<p>
|
||||
{% if get_subscriber(profile).is_subscribed() %}
|
||||
User is subscriber until {{ get_subscriber(profile).subscriptions.last().subscription_end }}
|
||||
|
@ -1,6 +1,7 @@
|
||||
from django.conf.urls import url, include
|
||||
|
||||
from core.views import *
|
||||
from counter.views import UserAccountView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', index, name='index'),
|
||||
@ -28,6 +29,7 @@ urlpatterns = [
|
||||
url(r'^user/(?P<user_id>[0-9]+)/edit$', UserUpdateProfileView.as_view(), name='user_edit'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/prop$', UserUpdatePropView.as_view(), name='user_prop'),
|
||||
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'),
|
||||
|
||||
# Page views
|
||||
url(r'^page/$', PageListView.as_view(), name='page_list'),
|
||||
|
@ -2,6 +2,7 @@
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.contrib.auth import logout as auth_logout, views
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
|
||||
from django.views.generic.edit import UpdateView
|
||||
from django.views.generic import ListView, DetailView, TemplateView
|
||||
import logging
|
||||
|
Reference in New Issue
Block a user