Skip to content

Commit

Permalink
Fix tests, style merge form
Browse files Browse the repository at this point in the history
  • Loading branch information
hancush committed May 8, 2024
1 parent 6740231 commit ef28c99
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 23 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ docker-compose run --rm app python make nightly
docker-compose run --rm app python manage.py make_search_index
```

To enable candidate merging for local development, create an admin user (`python manage.py createsuperuser`) and turn on database caching by adding `DJANGO_CACHE_BACKEND: "db.DatabaseCache"` to the environment block in `docker-compose.yml`. (django-select2 requires a persistent cache.) _This step is not necessary if you do not need to test merge functionality._

Finally, run the app:

```bash
Expand Down
5 changes: 3 additions & 2 deletions camp_fin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@

# Caching

cache_backend = "dummy.DummyCache" if DEBUG is True else "db.DatabaseCache"
cache_backend = "db.DatabaseCache"
cache_backend = os.getenv(
"DJANGO_CACHE_BACKEND", "dummy.DummyCache" if DEBUG else "db.DatabaseCache"
)
CACHES = {
"default": {
"BACKEND": f"django.core.cache.backends.{cache_backend}",
Expand Down
4 changes: 4 additions & 0 deletions camp_fin/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,7 @@ h4 small {
#redaction-form td {
padding: 10px;
}

.alert-info .select2-selection__choice {
color: #000;
}
47 changes: 30 additions & 17 deletions camp_fin/templates/camp_fin/candidate-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,36 @@ <h3>Related stories</h3>
{% endif %}
</div>
</div>
<div class="row">
<div class="col-md-12">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit">
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
{{ form.media.js }}
</div></div>
{% if user.is_authenticated %}
<div class="row">
<div class="col-md-8">
<div class="alert alert-info" role="alert">
<h4>
Merge records about <strong>{{ candidate.full_name }}</strong>
</h4>

{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}

<form method="post">
<p>Use the search box below to find one or more candidate records to merge with the current candidate record, <strong>{{ candidate.full_name }}</strong>. Merging will consolidate all related committees, candidacies, and transactions under the current candidate <strong>and cannot be undone</strong>. You can look up records to merge by candidate name or slug, e.g., <em>John Smith</em> or <em>john-smith-hvP0y</em>.</p>
<p>
{{ form.alias_objects }}
</p>
{% csrf_token %}
<div align="center"><input type="submit" class="btn btn-primary" style="width: unset!important;"></div>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
{{ form.media.js }}
</div>
</div>
</div>
{% endif %}
<div class="row">
<div class="col-xs-12">
<a href="{% url 'bulk-contributions-list' %}?candidate_id={{ candidate.id }}" class="btn btn-default"
Expand Down
14 changes: 10 additions & 4 deletions camp_fin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,10 +1314,6 @@ class CandidateMergeForm(forms.Form):
model=Candidate,
search_fields=["full_name__icontains", "slug__iexact"],
),
choices=[
(choice, name)
for choice, name in Candidate.objects.values_list("id", "full_name")
],
)


Expand All @@ -1326,6 +1322,16 @@ class CandidateDetail(FormView, CommitteeDetailBaseView):
model = Candidate
form_class = CandidateMergeForm

def get_form(self, form_class=None):
form = super().get_form(form_class=form_class)
form.fields["alias_objects"].choices = [
(choice, name)
for choice, name in Candidate.objects.exclude(
slug=self.object.slug
).values_list("id", "full_name")
]
return form

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
DJANGO_SECRET_KEY: "local secret key"
DJANGO_MANAGEPY_MIGRATE: "on"
DJANGO_DEBUG: "True"
DJANGO_CACHE_BACKEND: "db.DatabaseCache"
env_file:
- .env
entrypoint: /app/docker-entrypoint.sh
Expand Down
4 changes: 4 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ if [ "$DJANGO_MANAGEPY_MIGRATE" = 'on' ]; then
python manage.py migrate --noinput
fi

if [ "$DJANGO_CACHE_BACKEND" = 'db.DatabaseCache' ]; then
python manage.py createcachetable
fi

exec "$@"

0 comments on commit ef28c99

Please sign in to comment.