浏览代码

[locations] Add locations to dashboard

Colin Powell 1 月之前
父节点
当前提交
92c0c668b3

+ 1 - 1
vrobbler/apps/locations/models.py

@@ -36,7 +36,7 @@ class GeoLocation(ScrobblableMixin):
 
     def get_absolute_url(self):
         return reverse(
-            "locations:geo_location_detail", kwargs={"slug": self.uuid}
+            "locations:geolocation_detail", kwargs={"slug": self.uuid}
         )
 
     @classmethod

+ 2 - 2
vrobbler/apps/locations/urls.py

@@ -8,11 +8,11 @@ urlpatterns = [
     path(
         "locations/",
         views.GeoLocationListView.as_view(),
-        name="geo_locations_list",
+        name="geolocation_list",
     ),
     path(
         "locations/<slug:slug>/",
         views.GeoLocationDetailView.as_view(),
-        name="geo_location_detail",
+        name="geolocation_detail",
     ),
 ]

+ 7 - 0
vrobbler/apps/scrobbles/models.py

@@ -655,6 +655,13 @@ class Scrobble(TimeStampedModel):
                 (scrobble.elapsed_time)
             )
 
+        # Remove any locations without titles
+        if "GeoLocation" in scrobbles_by_type.keys():
+            for loc_scrobble in scrobbles_by_type["GeoLocation"]:
+                if not loc_scrobble.media_obj.title:
+                    scrobbles_by_type["GeoLocation"].remove(loc_scrobble)
+                    scrobbles_by_type["GeoLocation_count"] -= 1
+
         return scrobbles_by_type
 
     @classmethod

+ 1 - 7
vrobbler/templates/locations/geolocation_list.html

@@ -67,13 +67,7 @@
                     </tr>
                 </thead>
                 <tbody>
-                    {% for location in object_list %}
-                    <tr>
-                        <td>{{location.scrobble_set.count}}</td>
-                        <td>{{location.title}}</td>
-                        <td><a href="{{location.get_absolute_url}}">{{location.lat}}x{{location.lon}}</a></td>
-                    </tr>
-                    {% endfor %}
+                    {% include "_scrobblable_list.html" %}
                 </tbody>
             </table>
         </div>

+ 9 - 0
vrobbler/templates/scrobbles/_last_scrobbles.html

@@ -126,5 +126,14 @@
         <p>No books today</p>
         {% endif %}
 
+        <h3><a href="{% url 'locations:geolocation_list' %}">Locations</a></h3>
+        {% if GeoLocation %}
+        {% with scrobbles=GeoLocation count=GeoLocation_count time=GeoLocation_time %}
+        {% include "scrobbles/_scrobble_table.html" %}
+        {% endwith %}
+        {% else %}
+        <p>No locations visited today</p>
+        {% endif %}
+
     </div>
 </div>