Skip to content

Commit

Permalink
WIP Split person form
Browse files Browse the repository at this point in the history
  • Loading branch information
VirginiaDooley committed May 28, 2024
1 parent dc22933 commit d47174f
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 4 deletions.
1 change: 0 additions & 1 deletion ynr/apps/candidates/views/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
PersonMembershipFormsetFactory,
)
from people.models import Person
from people.splitting import PersonSplitter
from popolo.models import NotStandingValidationError

from ynr.apps.people.merging import InvalidMergeError, PersonMerger
Expand Down
6 changes: 3 additions & 3 deletions ynr/apps/elections/uk/templates/candidates/person-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<!-- Just Open Graph metadata -->
<meta property="og:type" content="article" />
<meta property="og:image" content="{{ person.get_display_image_url }}" />
{% comment %} <meta property="og:image" content="{{ person.get_display_image_url }}" /> {% endcomment %}
<meta property="og:image:height" content="80" />
<meta property="og:image:width" content="80" />
<meta property="og:site_name" content="{{ site.name }}" />
Expand All @@ -30,7 +30,7 @@
{% if settings.TWITTER_USERNAME %}
<meta name="twitter:site" content="@{{ settings.TWITTER_USERNAME }}" />
{% endif %}
<meta property="twitter:image" content="{{ person.get_display_image_url }}" />
{% comment %} <meta property="twitter:image" content="{{ person.get_display_image_url }}" /> {% endcomment %}
<meta property="twitter:image:width" content="160" />
<meta property="twitter:image:height" content="160" />
{% endblock %}
Expand All @@ -48,7 +48,7 @@
<div class="person__hero">
<div class="person__photo">

<img class="person-avatar" src="{{ person.get_display_image_url }}"/>
{% comment %} <img class="person-avatar" src="{{ person.get_display_image_url }}"/> {% endcomment %}
{% if not person.person_image and user.is_authenticated %}
<a class="upload-photo" href="{% url 'photo-upload' person.id %}">
Upload photo
Expand Down
30 changes: 30 additions & 0 deletions ynr/apps/people/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,36 @@ class UpdatePersonForm(BasePersonForm):
pass


class PersonSplitForm(UpdatePersonForm):
class Meta:
model = Person
# TO DO review these exclusions
exclude = (
"versions",
"not_standing",
"edit_limitations",
"sort_name",
)

SPLIT_CHOICES = [
("keep", "Keep on this person"),
("move", "Add to the new person"),
("both", "Keep on this person and add to a new person"),
]

split_person_choices = forms.ChoiceField(
label="What would you like to do with the information?",
choices=SPLIT_CHOICES,
widget=forms.RadioSelect,
)

# TO DO: Add a method to split the person

# TO DO Add a method to update the person with the new data

# TO DO Add a method to create a new person with the new data


class OtherNameForm(forms.ModelForm):
class Meta:
model = OtherName
Expand Down
94 changes: 94 additions & 0 deletions ynr/apps/people/templates/people/split_person.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{% extends 'base.html' %}
{% load thumbnail %}
{% load static %}
{% load pipeline %}

{% block content %}
<h1>Split {{ person.name }} into two people</h1>
<p>Choose which properties to keep on the original person, which to move to the new person, and which to keep on both.</p>

<form method="post">
{% csrf_token %}
<table>
<thead>
<tr>
<th>Keep on original?</th>
<th>Add to new?</th>
<th>Keep on original and add to new?</th>
<th>Property</th>
<th>{{person.name}}'s data</th>
</tr>
</thead>
<tbody>
<tr>
{% for radio in form.split_person_choices %}
<td for="id_{{ form.split_person_choices.html_name }}_{{ forloop.counter0 }}">{{ radio.tag }}</td>
{% endfor %}
<td>Name:</td>
<td>{{person.name}}</td>
</tr>

<tr>
{% for radio in form.split_person_choices %}
<td for="id_{{ form.split_person_choices.html_name }}_{{ forloop.counter0 }}">{{ radio.tag }}</td>
{% endfor %}
<td>Image:</td>
<td>
{% if person.image.image %}
{% thumbnail person.image.image "100x100" as thumb %}
<img src="{{ thumb.url }}" alt="{{ person.name }} thumbnail" />
{% endthumbnail %}
{% else %}
No image exists for this person.
{% endif %}
</td>
</tr>
<tr>
{% for radio in form.split_person_choices %}
<td for="id_{{ form.split_person_choices.html_name }}_{{ forloop.counter0 }}">{{ radio.tag }}</td>
{% endfor %}
<td>Other names:</td>
<td>{{person.other_names.all}}</td>
</tr>
<tr>
{% for radio in form.split_person_choices %}
<td for="id_{{ form.split_person_choices.html_name }}_{{ forloop.counter0 }}">{{ radio.tag }}</td>
{% endfor %}
<td>Gender:</td>
<td>{{person.gender}}</td>
</tr>
<tr>
{% for radio in form.split_person_choices %}
<td for="id_{{ form.split_person_choices.html_name }}_{{ forloop.counter0 }}">{{ radio.tag }}</td>
{% endfor %}
<td>Birth date:</td>
<td>{{person.birth_date}}</td>
</tr>
<tr>
{% for radio in form.split_person_choices %}
<td for="id_{{ form.split_person_choices.html_name }}_{{ forloop.counter0 }}">{{ radio.tag }}</td>
{% endfor %}
<td>Death date:</td>
<td>{{person.death_date}}</td>
</tr>
<tr>
{% for radio in form.split_person_choices %}
<td for="id_{{ form.split_person_choices.html_name }}_{{ forloop.counter0 }}">{{ radio.tag }}</td>
{% endfor %}
<td>Summary:</td>
<td>{{person.summary}}</td>
</tr>
<tr>
{% for radio in form.split_person_choices %}
<td for="id_{{ form.split_person_choices.html_name }}_{{ forloop.counter0 }}">{{ radio.tag }}</td>
{% endfor %}
<td>Biography:</td>
<td>{{person.biography}}</td>
</tr>
</tbody>
</table>
<input class="button primary small" type="submit" value="Split person" />

<a class="button secondary small" href="{% url 'person-view' person.id %}">Cancel</a>
</form>
{% endblock %}

0 comments on commit d47174f

Please sign in to comment.