mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-11-06 07:28:53 -05:00
adds date on Search options
This commit is contained in:
parent
341fdc9663
commit
95c84928ff
@ -23,7 +23,10 @@ class MediaSerializer(serializers.ModelSerializer):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_thumbnail_url(self, obj):
|
def get_thumbnail_url(self, obj):
|
||||||
return self.context["request"].build_absolute_uri(obj.thumbnail_url)
|
if obj.thumbnail_url:
|
||||||
|
return self.context["request"].build_absolute_uri(obj.thumbnail_url)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_author_profile(self, obj):
|
def get_author_profile(self, obj):
|
||||||
return self.context["request"].build_absolute_uri(obj.author_profile())
|
return self.context["request"].build_absolute_uri(obj.author_profile())
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
from datetime import datetime, timedelta
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -713,6 +714,7 @@ class MediaSearch(APIView):
|
|||||||
media_type = params.get("media_type", "").strip()
|
media_type = params.get("media_type", "").strip()
|
||||||
|
|
||||||
author = params.get("author", "").strip()
|
author = params.get("author", "").strip()
|
||||||
|
upload_date = params.get('upload_date', '').strip()
|
||||||
|
|
||||||
sort_by_options = ["title", "add_date", "edit_date", "views", "likes"]
|
sort_by_options = ["title", "add_date", "edit_date", "views", "likes"]
|
||||||
if sort_by not in sort_by_options:
|
if sort_by not in sort_by_options:
|
||||||
@ -760,6 +762,24 @@ class MediaSearch(APIView):
|
|||||||
if author:
|
if author:
|
||||||
media = media.filter(user__username=author)
|
media = media.filter(user__username=author)
|
||||||
|
|
||||||
|
if upload_date:
|
||||||
|
gte = lte = None
|
||||||
|
if upload_date == 'today':
|
||||||
|
gte = datetime.now().date()
|
||||||
|
if upload_date == 'this_week':
|
||||||
|
gte = datetime.now() - timedelta(days=7)
|
||||||
|
if upload_date == 'this_month':
|
||||||
|
year = datetime.now().date().year
|
||||||
|
month = datetime.now().date().month
|
||||||
|
gte = datetime(year,month,1)
|
||||||
|
if upload_date == 'this_year':
|
||||||
|
year = datetime.now().date().year
|
||||||
|
gte = datetime(year,1,1)
|
||||||
|
if lte:
|
||||||
|
media = media.filter(add_date__lte=lte)
|
||||||
|
if gte:
|
||||||
|
media = media.filter(add_date__gte=gte)
|
||||||
|
|
||||||
media = media.order_by(f"{ordering}{sort_by}")
|
media = media.order_by(f"{ordering}{sort_by}")
|
||||||
|
|
||||||
if self.request.query_params.get("show", "").strip() == "titles":
|
if self.request.query_params.get("show", "").strip() == "titles":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user