[widgets] Add food and trails widgets
This commit is contained in:
@ -22,6 +22,16 @@ urlpatterns = [
|
|||||||
views.EmbeddableTopBooksWidget.as_view(),
|
views.EmbeddableTopBooksWidget.as_view(),
|
||||||
name="embeddable-top-books",
|
name="embeddable-top-books",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"widget/top-trails/<str:period>/<int:user_id>/",
|
||||||
|
views.EmbeddableTopTrailsWidget.as_view(),
|
||||||
|
name="embeddable-top-trails",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"widget/top-foods/<str:period>/<int:user_id>/",
|
||||||
|
views.EmbeddableTopFoodsWidget.as_view(),
|
||||||
|
name="embeddable-top-foods",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"manual/lookup/",
|
"manual/lookup/",
|
||||||
views.ManualScrobbleView.as_view(),
|
views.ManualScrobbleView.as_view(),
|
||||||
|
|||||||
@ -14,8 +14,8 @@ from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
|
|||||||
from django.db.models import Count, Max, Q
|
from django.db.models import Count, Max, Q
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from rest_framework.authentication import TokenAuthentication
|
from rest_framework.authentication import TokenAuthentication
|
||||||
from rest_framework.authtoken.views import ObtainAuthToken
|
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
|
from rest_framework.authtoken.views import ObtainAuthToken
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
|
||||||
|
|
||||||
@ -1202,3 +1202,25 @@ class EmbeddableTopBooksWidget(BaseEmbeddableWidget):
|
|||||||
if not hasattr(item, "name") and hasattr(item, "title"):
|
if not hasattr(item, "name") and hasattr(item, "title"):
|
||||||
item.name = item.title
|
item.name = item.title
|
||||||
return items
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user