diff --git a/vrobbler/apps/locations/urls.py b/vrobbler/apps/locations/urls.py index d84054e..e547b03 100644 --- a/vrobbler/apps/locations/urls.py +++ b/vrobbler/apps/locations/urls.py @@ -15,4 +15,9 @@ urlpatterns = [ views.GeoLocationDetailView.as_view(), name="geolocation_detail", ), + path( + "locations//edit/", + views.GeoLocationUpdateView.as_view(), + name="geolocation_edit", + ), ] diff --git a/vrobbler/apps/locations/views.py b/vrobbler/apps/locations/views.py index b348cfb..bd09eb2 100644 --- a/vrobbler/apps/locations/views.py +++ b/vrobbler/apps/locations/views.py @@ -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} + ) diff --git a/vrobbler/templates/locations/geolocation_detail.html b/vrobbler/templates/locations/geolocation_detail.html index e5dc8e8..cf631a2 100644 --- a/vrobbler/templates/locations/geolocation_detail.html +++ b/vrobbler/templates/locations/geolocation_detail.html @@ -3,7 +3,7 @@ {% load static %} {% load humanize %} -{% block title %}{{object.title}}{% endblock %} +{% block title %}{{object.title}} Edit{% endblock %} {% block head_extra %} {{object.summary|safe|linebreaks|truncatewords:160}}


{% endif %} -

-

diff --git a/vrobbler/templates/locations/geolocation_form.html b/vrobbler/templates/locations/geolocation_form.html new file mode 100644 index 0000000..3f65d4f --- /dev/null +++ b/vrobbler/templates/locations/geolocation_form.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} +{% block title %}Edit {{object.title|default:"Location"}}{% endblock %} +{% block content %} +
+
+

Edit Location

+
+ +
+
+ {% csrf_token %} + {% for field in form %} +
+ + {{ field }} + {% if field.errors %} + {{ field.errors.0 }} + {% endif %} +
+ {% endfor %} + + Cancel +
+
+
+{% endblock %} \ No newline at end of file