diff --git a/vrobbler/apps/scrobbles/urls.py b/vrobbler/apps/scrobbles/urls.py index 74af584..49aa73a 100644 --- a/vrobbler/apps/scrobbles/urls.py +++ b/vrobbler/apps/scrobbles/urls.py @@ -22,6 +22,16 @@ urlpatterns = [ views.EmbeddableTopBooksWidget.as_view(), name="embeddable-top-books", ), + path( + "widget/top-trails///", + views.EmbeddableTopTrailsWidget.as_view(), + name="embeddable-top-trails", + ), + path( + "widget/top-foods///", + views.EmbeddableTopFoodsWidget.as_view(), + name="embeddable-top-foods", + ), path( "manual/lookup/", views.ManualScrobbleView.as_view(), diff --git a/vrobbler/apps/scrobbles/views.py b/vrobbler/apps/scrobbles/views.py index 5d1a82f..79e9610 100644 --- a/vrobbler/apps/scrobbles/views.py +++ b/vrobbler/apps/scrobbles/views.py @@ -14,8 +14,8 @@ from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.db.models import Count, Max, Q from django.db.models.query import QuerySet from rest_framework.authentication import TokenAuthentication -from rest_framework.authtoken.views import ObtainAuthToken from rest_framework.authtoken.models import Token +from rest_framework.authtoken.views import ObtainAuthToken from rest_framework.permissions import IsAuthenticated @@ -1202,3 +1202,25 @@ class EmbeddableTopBooksWidget(BaseEmbeddableWidget): if not hasattr(item, "name") and hasattr(item, "title"): item.name = item.title return items + + +class EmbeddableTopTrailsWidget(BaseEmbeddableWidget): + media_type = "Trails" + count_label = "visits" + no_data_message = "No trails visited" + + def get_items(self, user, start_date): + from trails.models import Trail + + return super().get_items(user, start_date, Trail) + + +class EmbeddableTopFoodsWidget(BaseEmbeddableWidget): + media_type = "Foods" + count_label = "meals" + no_data_message = "No foods logged" + + def get_items(self, user, start_date): + from foods.models import Food + + return super().get_items(user, start_date, Food)