core: add user settings and user delete
This commit is contained in:
14
passbook/core/forms/user.py
Normal file
14
passbook/core/forms/user.py
Normal file
@ -0,0 +1,14 @@
|
||||
"""passbook core user forms"""
|
||||
|
||||
from django import forms
|
||||
|
||||
from passbook.core.models import User
|
||||
|
||||
|
||||
class UserDetailForm(forms.ModelForm):
|
||||
"""Update User Details"""
|
||||
|
||||
class Meta:
|
||||
|
||||
model = User
|
||||
fields = ['username', 'first_name', 'last_name', 'email']
|
@ -7,6 +7,5 @@ from django.core.signals import Signal
|
||||
# from passbook.core.models import Invitation, User
|
||||
|
||||
user_signed_up = Signal(providing_args=['request', 'user'])
|
||||
# TODO: Send this signal in admin interface
|
||||
invitation_created = Signal(providing_args=['request', 'invitation'])
|
||||
invitation_used = Signal(providing_args=['request', 'invitation', 'user'])
|
||||
|
20
passbook/core/templates/generic/delete.html
Normal file
20
passbook/core/templates/generic/delete.html
Normal file
@ -0,0 +1,20 @@
|
||||
{% extends "administration/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utils %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
{% block above_form %}
|
||||
<h1>{% trans 'Delete' %}</h1>
|
||||
{% endblock %}
|
||||
<div class="">
|
||||
<form method="post" class="form-horizontal">
|
||||
{% csrf_token %}
|
||||
<p>Are you sure you want to delete "{{ object }}"?</p>
|
||||
<a href="{% back %}" class="btn btn-default">{% trans 'Back' %}</a>
|
||||
<input type="submit" class="btn btn-danger" value="{% trans 'Delete' %}" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
@ -38,13 +38,7 @@
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a href="#0">Link</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#0">Another link</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#0">Something else here</a>
|
||||
<a href="{% url 'passbook_core:user-settings' %}">{% trans 'User Settings' %}</a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li>
|
||||
@ -55,7 +49,7 @@
|
||||
</ul>
|
||||
{% is_active_app 'passbook_admin' as is_admin %}
|
||||
<ul class="nav navbar-nav navbar-primary {% if is_admin == 'active' %}persistent-secondary{% endif %}">
|
||||
<li class="{% is_active_app 'passbook_core' %}">
|
||||
<li class="{% is_active 'passbook_core:overview' %}">
|
||||
<a href="{% url 'passbook_core:overview' %}">{% trans 'Overview' %}</a>
|
||||
</li>
|
||||
<li class="{% is_active_app 'passbook_admin' %}">
|
||||
|
52
passbook/core/templates/partials/form.html
Normal file
52
passbook/core/templates/partials/form.html
Normal file
@ -0,0 +1,52 @@
|
||||
{% load utils %}
|
||||
|
||||
{% csrf_token %}
|
||||
{% for field in form %}
|
||||
<div class="form-group">
|
||||
{% if field.field.widget|fieldtype == 'RadioSelect' %}
|
||||
<label class="col-sm-2 control-label" {% if field.field.required %}class="required"{% endif %} for="{{ field.name }}-{{ forloop.counter0 }}">
|
||||
{{ field.label }}
|
||||
</label>
|
||||
{% for c in field %}
|
||||
<div class="radio col-sm-10">
|
||||
<input type="radio" id="{{ field.name }}-{{ forloop.counter0 }}" name="{% if wizard %}{{ wizard.steps.current }}-{% endif %}{{ field.name }}" value="{{ c.data.value }}" {% if c.data.selected %} checked {% endif %}>
|
||||
<label class="col-sm-2 control-label" for="{{ field.name }}-{{ forloop.counter0 }}">{{ c.choice_label }}</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% elif field.field.widget|fieldtype == 'Select' %}
|
||||
<label class="col-sm-2 control-label" {% if field.field.required %}class="required"{% endif %} for="{{ field.name }}-{{ forloop.counter0 }}">
|
||||
{{ field.label }}
|
||||
</label>
|
||||
<div class="select col-sm-10">
|
||||
{{ field }}
|
||||
</div>
|
||||
{% elif field.field.widget|fieldtype == 'CheckboxInput' %}
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
{{ field }} {{ field.label }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<label class="col-sm-2 control-label" {% if field.field.required %}class="required"{% endif %} for="{{ field.name }}-{{ forloop.counter0 }}">
|
||||
{{ field.label }}
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
{{ field|css_class:'form-control' }}
|
||||
{% if field.help_text %}
|
||||
<span>
|
||||
{{ field.help_text }}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% for error in field.errors %}
|
||||
<hr>
|
||||
<div class="alert alert-danger">
|
||||
<span class="pficon pficon-error-circle-o"></span>
|
||||
<strong>{{ error }}</strong>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
24
passbook/core/templates/user/base.html
Normal file
24
passbook/core/templates/user/base.html
Normal file
@ -0,0 +1,24 @@
|
||||
{% extends "overview/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load is_active %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="col-md-3 ">
|
||||
<div class="nav-category">
|
||||
<h2>{% trans 'User Profile'%}</h2>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<li class="{% is_active 'passbook_core:user-settings' %}"><a href="{% url 'passbook_core:user-settings' %}"><i class="fa fa-desktop"></i>{% trans 'Details' %}</a></li>
|
||||
<li><a href="#"><i class="fa fa-cog"></i>System Services</a></li>
|
||||
<li><a href="#"><i class="fa fa-file-text-o"></i>Journal</a></li>
|
||||
<li><a href="#"><i class="fa fa-cloud"></i>Storage</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
{% block page %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
13
passbook/core/templates/user/settings.html
Normal file
13
passbook/core/templates/user/settings.html
Normal file
@ -0,0 +1,13 @@
|
||||
{% extends "user/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
{% block page %}
|
||||
<h1>{% trans 'Update details' %}</h1>
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
{% csrf_token %}
|
||||
{% include 'partials/form.html' %}
|
||||
<input class="btn btn-primary" type="submit" value="{% trans 'Update' %}">
|
||||
<a class="btn btn-danger" href="{% url 'passbook_core:user-delete' %}?back={{ request.get_full_path }}">{% trans 'Delete user' %}</a>
|
||||
</form>
|
||||
{% endblock %}
|
@ -6,7 +6,7 @@ from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from passbook.core.views import authentication, overview
|
||||
from passbook.core.views import authentication, overview, user
|
||||
from passbook.lib.utils.reflection import get_apps
|
||||
|
||||
LOGGER = getLogger(__name__)
|
||||
@ -14,9 +14,14 @@ admin.autodiscover()
|
||||
admin.site.login = RedirectView.as_view(pattern_name='passbook_core:auth-login')
|
||||
|
||||
core_urls = [
|
||||
# Authentication views
|
||||
path('auth/login/', authentication.LoginView.as_view(), name='auth-login'),
|
||||
path('auth/logout/', authentication.LogoutView.as_view(), name='auth-logout'),
|
||||
path('auth/sign_up/', authentication.SignUpView.as_view(), name='auth-sign-up'),
|
||||
# User views
|
||||
path('user/', user.UserSettingsView.as_view(), name='user-settings'),
|
||||
path('user/delete/', user.UserDeleteView.as_view(), name='user-delete'),
|
||||
# Overview
|
||||
path('', overview.OverviewView.as_view(), name='overview'),
|
||||
]
|
||||
|
||||
|
@ -211,20 +211,8 @@ class SignUpView(UserPassesTestMixin, FormView):
|
||||
sender=SignUpView,
|
||||
user=new_user,
|
||||
request=request)
|
||||
# try:
|
||||
# TODO: Create signal for signup
|
||||
# on_user_sign_up.send(
|
||||
# sender=None,
|
||||
# user=new_user,
|
||||
# request=request,
|
||||
# password=data.get('password'),
|
||||
# needs_confirmation=needs_confirmation)
|
||||
# TODO: Implement Verification, via email or others
|
||||
# if needs_confirmation:
|
||||
# Create Account Confirmation UUID
|
||||
# AccountConfirmation.objects.create(user=new_user)
|
||||
# except SignalException as exception:
|
||||
# LOGGER.warning("Failed to sign up user %s", exception, exc_info=exception)
|
||||
# new_user.delete()
|
||||
# raise
|
||||
# TODO: Implement Verification, via email or others
|
||||
# if needs_confirmation:
|
||||
# Create Account Confirmation UUID
|
||||
# AccountConfirmation.objects.create(user=new_user)
|
||||
return new_user
|
||||
|
30
passbook/core/views/user.py
Normal file
30
passbook/core/views/user.py
Normal file
@ -0,0 +1,30 @@
|
||||
"""passbook core user views"""
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import logout
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import DeleteView, UpdateView
|
||||
|
||||
from passbook.core.forms.user import UserDetailForm
|
||||
|
||||
|
||||
class UserSettingsView(UpdateView):
|
||||
"""Update User settings"""
|
||||
template_name = 'user/settings.html'
|
||||
form_class = UserDetailForm
|
||||
|
||||
def get_object(self):
|
||||
return self.request.user
|
||||
|
||||
class UserDeleteView(DeleteView):
|
||||
"""Delete user account"""
|
||||
|
||||
template_name = 'generic/delete.html'
|
||||
|
||||
def get_object(self):
|
||||
return self.request.user
|
||||
|
||||
def get_success_url(self):
|
||||
messages.success(self.request, _('Successfully deleted user.'))
|
||||
logout(self.request)
|
||||
return reverse('passbook_core:auth-login')
|
Reference in New Issue
Block a user