mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
feat(people): Add first user data fields
To support choices in CharFields, Django choices enums have been backported by bringing in the source file from Django 3.0.3 See #1
This commit is contained in:
@@ -12,11 +12,11 @@ class PersonForm(forms.ModelForm):
|
||||
"""
|
||||
class Meta:
|
||||
model = models.Person
|
||||
fields = [
|
||||
'name',
|
||||
'core_member',
|
||||
exclude = [
|
||||
'user',
|
||||
'relationship_targets',
|
||||
]
|
||||
|
||||
|
||||
|
||||
class RelationshipForm(forms.ModelForm):
|
||||
"""
|
||||
|
||||
23
people/migrations/0009_add_first_person_fields.py
Normal file
23
people/migrations/0009_add_first_person_fields.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 2.2.10 on 2020-02-21 16:49
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('people', '0008_order_answer_by_question'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='person',
|
||||
name='age_group',
|
||||
field=models.CharField(blank=True, choices=[('<=25', '25 or under'), ('26-30', '26-30'), ('31-35', '31-35'), ('36-40', '36-40'), ('41-45', '41-45'), ('46-50', '46-50'), ('51-55', '51-55'), ('56-60', '56-60'), ('>=61', '61 or older'), ('N', 'Prefer not to say')], max_length=5),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='person',
|
||||
name='gender',
|
||||
field=models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female'), ('O', 'Other'), ('N', 'Prefer not to say')], max_length=1),
|
||||
),
|
||||
]
|
||||
@@ -4,6 +4,9 @@ from django.conf import settings
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from backports.db.models.enums import TextChoices
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
@@ -38,7 +41,36 @@ class Person(models.Model):
|
||||
through='Relationship',
|
||||
through_fields=('source', 'target'),
|
||||
symmetrical=False)
|
||||
|
||||
###############################################################
|
||||
# Data collected for analysis of community makeup and structure
|
||||
|
||||
class GenderChoices(TextChoices):
|
||||
MALE = 'M', _('Male')
|
||||
FEMALE = 'F', _('Female')
|
||||
OTHER = 'O', _('Other')
|
||||
PREFER_NOT_TO_SAY = 'N', _('Prefer not to say')
|
||||
|
||||
gender = models.CharField(max_length=1,
|
||||
choices=GenderChoices.choices,
|
||||
blank=True, null=False)
|
||||
|
||||
class AgeGroupChoices(TextChoices):
|
||||
LTE_25 = '<=25', _('25 or under')
|
||||
BETWEEN_26_30 = '26-30', _('26-30')
|
||||
BETWEEN_31_35 = '31-35', _('31-35')
|
||||
BETWEEN_36_40 = '36-40', _('36-40')
|
||||
BETWEEN_41_45 = '41-45', _('41-45')
|
||||
BETWEEN_46_50 = '46-50', _('46-50')
|
||||
BETWEEN_51_55 = '51-55', _('51-55')
|
||||
BETWEEN_56_60 = '56-60', _('56-60')
|
||||
GTE_61 = '>=61', _('61 or older')
|
||||
PREFER_NOT_TO_SAY = 'N', _('Prefer not to say')
|
||||
|
||||
age_group = models.CharField(max_length=5,
|
||||
choices=AgeGroupChoices.choices,
|
||||
blank=True, null=False)
|
||||
|
||||
@property
|
||||
def relationships(self):
|
||||
return self.relationships_as_source.all().union(
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<a class="btn btn-success"
|
||||
href="{% url 'people:person.update' pk=person.pk %}">Update</a>
|
||||
|
||||
<hr>
|
||||
|
||||
<h2>Relationships As Source</h2>
|
||||
|
||||
30
people/templates/people/person/update.html
Normal file
30
people/templates/people/person/update.html
Normal file
@@ -0,0 +1,30 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url 'people:person.list' %}">People</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url 'people:person.detail' pk=person.pk %}">{{ person }}</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Update</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<hr>
|
||||
|
||||
<form class="form"
|
||||
method="POST">
|
||||
{% csrf_token %}
|
||||
|
||||
{% load bootstrap4 %}
|
||||
{% bootstrap_form form %}
|
||||
|
||||
{% buttons %}
|
||||
<button class="btn btn-success" type="submit">Submit</button>
|
||||
{% endbuttons %}
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
@@ -22,6 +22,10 @@ urlpatterns = [
|
||||
views.ProfileView.as_view(),
|
||||
name='person.detail'),
|
||||
|
||||
path('people/<int:pk>/update',
|
||||
views.PersonUpdateView.as_view(),
|
||||
name='person.update'),
|
||||
|
||||
path('people/<int:person_pk>/relationships/create',
|
||||
views.RelationshipCreateView.as_view(),
|
||||
name='person.relationship.create'),
|
||||
|
||||
@@ -3,7 +3,7 @@ Views for displaying or manipulating models in the 'people' app.
|
||||
"""
|
||||
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.views.generic import CreateView, DetailView, ListView
|
||||
from django.views.generic import CreateView, DetailView, ListView, UpdateView
|
||||
|
||||
from . import forms, models
|
||||
|
||||
@@ -51,6 +51,15 @@ class ProfileView(DetailView):
|
||||
|
||||
except AttributeError:
|
||||
return self.request.user.person
|
||||
|
||||
|
||||
class PersonUpdateView(UpdateView):
|
||||
"""
|
||||
View for updating a :class:`Person` record.
|
||||
"""
|
||||
model = models.Person
|
||||
template_name = 'people/person/update.html'
|
||||
form_class = forms.PersonForm
|
||||
|
||||
|
||||
class RelationshipDetailView(DetailView):
|
||||
|
||||
Reference in New Issue
Block a user