[locations] Allow editing from detail page
This commit is contained in:
@ -15,4 +15,9 @@ urlpatterns = [
|
||||
views.GeoLocationDetailView.as_view(),
|
||||
name="geolocation_detail",
|
||||
),
|
||||
path(
|
||||
"locations/<slug:slug>/edit/",
|
||||
views.GeoLocationUpdateView.as_view(),
|
||||
name="geolocation_edit",
|
||||
),
|
||||
]
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
from django.db.models import Count
|
||||
from django.urls import reverse_lazy
|
||||
from django.views import generic
|
||||
from locations.models import GeoLocation
|
||||
from scrobbles.stats import get_scrobble_count_qs
|
||||
@ -26,3 +27,16 @@ class GeoLocationListView(generic.ListView):
|
||||
class GeoLocationDetailView(ChartContextMixin, generic.DetailView):
|
||||
model = GeoLocation
|
||||
slug_field = "uuid"
|
||||
|
||||
|
||||
class GeoLocationUpdateView(generic.UpdateView):
|
||||
model = GeoLocation
|
||||
fields = ["title", "base_run_time_seconds"]
|
||||
slug_field = "uuid"
|
||||
template_name = "locations/geolocation_form.html"
|
||||
success_url = reverse_lazy("locations:geolocation_list")
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy(
|
||||
"locations:geolocation_detail", kwargs={"slug": self.object.uuid}
|
||||
)
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
{% load static %}
|
||||
{% load humanize %}
|
||||
|
||||
{% block title %}{{object.title}}{% endblock %}
|
||||
{% block title %}{{object.title}} <a href="{% url 'locations:geolocation_edit' slug=object.uuid %}" class="btn btn-sm btn-outline-secondary">Edit</a>{% endblock %}
|
||||
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
|
||||
@ -43,8 +43,6 @@
|
||||
<p>{{object.summary|safe|linebreaks|truncatewords:160}}</p>
|
||||
<hr />
|
||||
{% endif %}
|
||||
<p style="float:right;">
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
||||
26
vrobbler/templates/locations/geolocation_form.html
Normal file
26
vrobbler/templates/locations/geolocation_form.html
Normal file
@ -0,0 +1,26 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Edit {{object.title|default:"Location"}}{% endblock %}
|
||||
{% block content %}
|
||||
<main class="col-md-4 ms-sm-auto col-lg-10 px-md-4">
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">Edit Location</h1>
|
||||
</div>
|
||||
|
||||
<div style="max-width: 500px; margin-top: 20px;">
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{% for field in form %}
|
||||
<div class="form-group" style="margin-bottom: 16px;">
|
||||
<label for="{{ field.id_for_label }}" style="display: block; font-weight: 600; margin-bottom: 4px;">{{ field.label }}</label>
|
||||
{{ field }}
|
||||
{% if field.errors %}
|
||||
<small class="text-danger">{{ field.errors.0 }}</small>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
<a href="{% url 'locations:geolocation_detail' slug=object.uuid %}" class="btn btn-secondary" style="margin-left: 10px;">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user