mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-12-23 16:02:25 +00:00
Add view for aliases
This commit is contained in:
parent
f1cedc902e
commit
f77351b444
@ -15,6 +15,7 @@ urlpatterns = [
|
|||||||
path('user/', views.UserListView.as_view(), name="user_list"),
|
path('user/', views.UserListView.as_view(), name="user_list"),
|
||||||
path('user/<int:pk>', views.UserDetailView.as_view(), name="user_detail"),
|
path('user/<int:pk>', views.UserDetailView.as_view(), name="user_detail"),
|
||||||
path('user/<int:pk>/update', views.UserUpdateView.as_view(), name="user_update_profile"),
|
path('user/<int:pk>/update', views.UserUpdateView.as_view(), name="user_update_profile"),
|
||||||
|
path('user/<int:pk>/aliases', views.AliasView.as_view(), name="user_alias"),
|
||||||
path('manage-auth-token/', views.ManageAuthTokens.as_view(), name='auth_token'),
|
path('manage-auth-token/', views.ManageAuthTokens.as_view(), name='auth_token'),
|
||||||
|
|
||||||
# API for the user autocompleter
|
# API for the user autocompleter
|
||||||
|
@ -6,14 +6,17 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
|||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic import CreateView, DetailView, UpdateView, TemplateView
|
from django.views.generic import CreateView, DetailView, UpdateView, TemplateView
|
||||||
|
from django.views.generic.edit import FormMixin
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django_tables2.views import SingleTableView
|
from django_tables2.views import SingleTableView
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
|
|
||||||
from note.models import Alias, NoteUser
|
from note.models import Alias, NoteUser
|
||||||
from note.models.transactions import Transaction
|
from note.models.transactions import Transaction
|
||||||
from note.tables import HistoryTable
|
from note.tables import HistoryTable, AliasTable
|
||||||
|
from note.forms import AliasForm
|
||||||
|
|
||||||
from .models import Profile, Club, Membership
|
from .models import Profile, Club, Membership
|
||||||
from .forms import SignUpForm, ProfileForm, ClubForm, MembershipForm, MemberFormSet, FormSetHelper
|
from .forms import SignUpForm, ProfileForm, ClubForm, MembershipForm, MemberFormSet, FormSetHelper
|
||||||
@ -153,6 +156,36 @@ class UserListView(LoginRequiredMixin, SingleTableView):
|
|||||||
context["filter"] = self.filter
|
context["filter"] = self.filter
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
class AliasView(LoginRequiredMixin,FormMixin,DetailView):
|
||||||
|
model = User
|
||||||
|
template_name = 'member/user_alias.html'
|
||||||
|
context_object_name = 'user_object'
|
||||||
|
form_class = AliasForm
|
||||||
|
|
||||||
|
def get_context_data(self,**kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context["aliases"] = AliasTable(context['user_object'].note.alias_set.all())
|
||||||
|
context["alias_form"] = AliasForm()
|
||||||
|
return context
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse_lazy('member:user_alias', kwargs={'pk': self.object.id})
|
||||||
|
|
||||||
|
def post(self,request,*args,**kwargs):
|
||||||
|
self.object = self.get_object()
|
||||||
|
form = self.get_form()
|
||||||
|
if form.is_valid():
|
||||||
|
return self.form_valid(form)
|
||||||
|
else:
|
||||||
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
alias = form.save(commit=False)
|
||||||
|
alias.note = self.object.note
|
||||||
|
alias.save()
|
||||||
|
alias.note.save()
|
||||||
|
print(alias,alias.pk)
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
class ManageAuthTokens(LoginRequiredMixin, TemplateView):
|
class ManageAuthTokens(LoginRequiredMixin, TemplateView):
|
||||||
"""
|
"""
|
||||||
|
@ -6,6 +6,12 @@ from django import forms
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from .models import Transaction, TransactionTemplate, TemplateTransaction
|
from .models import Transaction, TransactionTemplate, TemplateTransaction
|
||||||
|
from .models import Alias
|
||||||
|
|
||||||
|
class AliasForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Alias
|
||||||
|
fields = ("name",)
|
||||||
|
|
||||||
|
|
||||||
class TransactionTemplateForm(forms.ModelForm):
|
class TransactionTemplateForm(forms.ModelForm):
|
||||||
|
@ -5,7 +5,7 @@ import django_tables2 as tables
|
|||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
|
|
||||||
from .models.transactions import Transaction
|
from .models.transactions import Transaction
|
||||||
|
from .models.notes import Alias
|
||||||
|
|
||||||
class HistoryTable(tables.Table):
|
class HistoryTable(tables.Table):
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -24,3 +24,16 @@ class HistoryTable(tables.Table):
|
|||||||
queryset = queryset.annotate(total=F('amount') * F('quantity')) \
|
queryset = queryset.annotate(total=F('amount') * F('quantity')) \
|
||||||
.order_by(('-' if is_descending else '') + 'total')
|
.order_by(('-' if is_descending else '') + 'total')
|
||||||
return (queryset, True)
|
return (queryset, True)
|
||||||
|
|
||||||
|
class AliasTable(tables.Table):
|
||||||
|
class Meta:
|
||||||
|
attrs = {
|
||||||
|
'class':
|
||||||
|
'table table condensed table-striped table-hover'
|
||||||
|
}
|
||||||
|
model = Alias
|
||||||
|
fields = ('name',)
|
||||||
|
template_name = 'django_tables2/bootstrap4.html'
|
||||||
|
|
||||||
|
delete = tables.LinkColumn('member:user_alias_delete', args=[A('id')], attrs={
|
||||||
|
'a': {'class': 'btn'} })
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<dt class="col-xl-6">{% trans 'balance'|capfirst %}</dt>
|
<dt class="col-xl-6">{% trans 'balance'|capfirst %}</dt>
|
||||||
<dd class="col-xl-6">{{ object.note.balance | pretty_money }}</dd>
|
<dd class="col-xl-6">{{ object.note.balance | pretty_money }}</dd>
|
||||||
|
|
||||||
<dt class="col-xl-6">{% trans 'aliases'|capfirst %}</dt>
|
<dt class="col-xl-6"> <a href="{% url 'member:user_alias' object.pk %}">{% trans 'aliases'|capfirst %}</a></dt>
|
||||||
<dd class="col-xl-6">{{ object.note.alias_set.all|join:", " }}</dd>
|
<dd class="col-xl-6">{{ object.note.alias_set.all|join:", " }}</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
|
65
templates/member/user_alias.html
Normal file
65
templates/member/user_alias.html
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% load i18n static pretty_money django_tables2 crispy_forms_tags %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row mt-4">
|
||||||
|
<div class="col-md-3 mb-4">
|
||||||
|
<div class="card bg-light shadow">
|
||||||
|
<img src="{{ object.note.display_image }}" class="card-img-top" alt="">
|
||||||
|
<div class="card-body">
|
||||||
|
<dl class="row">
|
||||||
|
<dt class="col-xl-6">{% trans 'name'|capfirst %}, {% trans 'first name' %}</dt>
|
||||||
|
<dd class="col-xl-6">{{ object.last_name }} {{ object.first_name }}</dd>
|
||||||
|
|
||||||
|
<dt class="col-xl-6">{% trans 'username'|capfirst %}</dt>
|
||||||
|
<dd class="col-xl-6">{{ object.username }}</dd>
|
||||||
|
|
||||||
|
<dt class="col-xl-6">{% trans 'password'|capfirst %}</dt>
|
||||||
|
<dd class="col-xl-6">
|
||||||
|
<a class="small" href="{% url 'password_change' %}">
|
||||||
|
{% trans 'Change password' %}
|
||||||
|
</a>
|
||||||
|
</dd>
|
||||||
|
|
||||||
|
<dt class="col-xl-6">{% trans 'section'|capfirst %}</dt>
|
||||||
|
<dd class="col-xl-6">{{ object.profile.section }}</dd>
|
||||||
|
|
||||||
|
<dt class="col-xl-6">{% trans 'address'|capfirst %}</dt>
|
||||||
|
<dd class="col-xl-6">{{ object.profile.address }}</dd>
|
||||||
|
|
||||||
|
<dt class="col-xl-6">{% trans 'balance'|capfirst %}</dt>
|
||||||
|
<dd class="col-xl-6">{{ object.note.balance | pretty_money }}</dd>
|
||||||
|
|
||||||
|
<dt class="col-xl-6">{% trans 'aliases'|capfirst %}</dt>
|
||||||
|
<dd class="col-xl-6">{{ object.note.alias_set.all|join:", " }}</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
{% if object.pk == user.pk %}
|
||||||
|
<a class="small" href="{% url 'member:auth_token' %}">{% trans 'Manage auth token' %}</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="card-footer text-center">
|
||||||
|
<a class="btn btn-primary btn-sm" href="{% url 'member:user_update_profile' object.pk %}">{% trans 'Update Profile' %}</a>
|
||||||
|
<a class="btn btn-primary btn-sm" href="{% url 'member:user_detail' object.pk %}">{% trans 'View Profile' %}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-9">
|
||||||
|
<div class="d-flex justify-content-center">
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ alias_form |crispy }}
|
||||||
|
<button class="btn btn-primary" type="submit">
|
||||||
|
{% trans "Add alias" %}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="card bg-light shadow">
|
||||||
|
<div class="card-body">
|
||||||
|
{% render_table aliases %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user