Edit attorney information

This commit is contained in:
Zakary Timson 2018-02-26 22:45:26 -05:00
parent 345b2e0543
commit 4c84c30285
6 changed files with 107 additions and 3 deletions

View File

@ -12,5 +12,5 @@ class MemberAdmin(admin.ModelAdmin):
list_display = ['last_name', 'first_name', 'position', 'region', 'phone_formatted', 'email', 'front_page', 'order', 'joined', 'thumbnail']
list_filter = ['region', 'position', 'front_page', 'joined']
search_fields = ['email', 'joined', 'last_name', 'first_name', 'region', 'position', 'website', 'phone', 'phone_formatted']
fields = ['image_preview', 'image', 'last_name', 'first_name', 'position', 'region', 'biography', 'phone', 'email', 'website', 'front_page', 'order', 'joined']
fields = ['image_preview', 'image', 'user', 'last_name', 'first_name', 'position', 'region', 'biography', 'phone', 'email', 'website', 'front_page', 'order', 'joined']
readonly_fields = ['image_preview']

View File

@ -8,6 +8,12 @@ from OACPL import settings
from OACPL.utils import render_to_string
class AttorneyForm(forms.ModelForm):
class Meta:
model = Attorney
fields = ['first_name', 'last_name', 'region', 'image', 'email', 'address', 'phone', 'website', 'call_to_bar', 'lso', 'biography']
class RegisterForm(forms.ModelForm):
def email_validator(self):
if User.objects.filter(email=self).exists():
@ -70,6 +76,9 @@ class RegisterForm(forms.ModelForm):
auth = User.objects.create_user(user.email, first_name=user.first_name, last_name=user.last_name, email=user.email, password=self.cleaned_data['password1'])
auth.save()
user.user = auth
user.save()
# Add user to default Group
default_group = Group.objects.filter(name='default').first()
if default_group:

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-02-27 03:16
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('charter_members', '0008_auto_20180124_0132'),
]
operations = [
migrations.AddField(
model_name='attorney',
name='user',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]

View File

@ -1,4 +1,5 @@
from django.conf import settings
from django.contrib.auth.admin import User
from django.db import models
from django.utils import timezone
@ -35,6 +36,7 @@ class Attorney(models.Model):
phone = models.CharField(max_length=10)
position = models.ForeignKey(Position, blank=True, null=True)
website = models.CharField(max_length=255, blank=True, null=True)
user = models.ForeignKey(User, null=True, blank=True)
def phone_formatted(self):
if self.phone is None or self.phone == '': return ''

View File

@ -1,4 +1,5 @@
{% extends 'base.html' %}
{% load widget_tweaks %}
{% block body %}
<div class="container-fluid">
@ -14,10 +15,75 @@
</div>
<div class="col-lg-6 pt-3 bg-light-blue">
<div class="col-lg-6">
<h2 class="d-none d-lg-inline text-dark-primary">{{ attorney.first_name }} {{ attorney.last_name }}</h2>
<h2 class="d-none d-lg-inline text-dark-primary">
{{ attorney.first_name }} {{ attorney.last_name }}
</h2>
{% if perms.charter_members.change_attorney or attorney.user == request.user %}
<a href="#" data-toggle="modal" data-target="#editModal">Edit</a>
{% endif %}
<p>{{ attorney.biography | safe }}</p>
</div>
</div>
</div>
</div>
{% if perms.charter_members.change_attorney or attorney.user == request.user %}
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit Attorney Information</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form id="edit" method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="row">
<div class="form-group col-12">
Portrait
{{ editForm.image|add_class:"form-control" }}
</div>
<div class="form-group col-6">
{{ editForm.first_name|add_class:"form-control"|attr:"placeholder:First Name" }}
</div>
<div class="form-group col-6">
{{ editForm.last_name|add_class:"form-control"|attr:"placeholder:Last Name" }}
</div>
<div class="form-group col-6">
{{ editForm.password1|add_class:"form-control"|attr:"placeholder:Password" }}
</div>
<div class="form-group col-6">
{{ editForm.password2|add_class:"form-control"|attr:"placeholder:Confirm Password" }}
</div>
<div class="form-group col-6">
{{ editForm.phone|add_class:"form-control"|attr:"placeholder:Phone Number (No Formatting)" }}
</div>
<div class="form-group col-6">
{{ editForm.email|add_class:"form-control"|attr:"placeholder:Email" }}
</div>
<div class="form-group col-8">
{{ editForm.address|add_class:"form-control"|attr:"placeholder:Address" }}
</div>
<div class="form-group col-4">
{{ editForm.region|add_class:"form-control" }}
</div>
<div class="form-group col-12">
{{ editForm.website|add_class:"form-control"|attr:"placeholder:Website" }}
</div>
<div class="form-group col-12">
{{ editForm.biography|add_class:"form-control"|attr:"placeholder:Biography" }}
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" form="edit">Save changes</button>
</div>
</div>
</div>
</div>
{% endif %}
{% endblock %}

View File

@ -2,11 +2,15 @@ from django.db.models import Count
from django.shortcuts import render
from .models import Region, Attorney
from .forms import AttorneyForm
def index(request, id):
attorney = Attorney.objects.get(id=id)
return render(request, 'attorney.html', {'attorney': attorney})
edit_form = AttorneyForm(request.POST or None, request.FILES or None, instance=attorney)
if request.method == 'POST' and edit_form.is_valid():
edit_form.save()
return render(request, 'attorney.html', {'attorney': attorney, 'editForm': edit_form})
def all(request):