From 468fb338f186cc231ce12b5bc5f8733a63030851 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 18 May 2023 22:42:07 +0200 Subject: [PATCH 01/14] ADD: Api endpoint for search suggestions --- .gitignore | 1 + api/__init__.py | 0 api/urls.py | 6 ++++++ api/views.py | 10 ++++++++++ core/admin.py | 2 -- core/serializers.py | 7 +++++++ core/urls.py | 3 +-- ragnarok/settings.py | 2 +- ragnarok/urls.py | 6 +++--- 9 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 api/__init__.py create mode 100644 api/urls.py create mode 100644 api/views.py create mode 100644 core/serializers.py diff --git a/.gitignore b/.gitignore index 56a7f43..f0c88a9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ db.sqlite3 videos/ channel_archiver/yt-dlp-archive.txt channel_archiver/UnusualVideos* +*__pycache__* \ No newline at end of file diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/urls.py b/api/urls.py new file mode 100644 index 0000000..1e2d1e6 --- /dev/null +++ b/api/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.query) +] \ No newline at end of file diff --git a/api/views.py b/api/views.py new file mode 100644 index 0000000..9ddaf6e --- /dev/null +++ b/api/views.py @@ -0,0 +1,10 @@ +from rest_framework.response import Response +from rest_framework.decorators import api_view +from core.models import Video +from core.serializers import VideoSerializer + +@api_view(['GET']) +def query(request): + videos = Video.objects.all() + serializer = VideoSerializer(videos, many=True) + return Response(serializer.data) \ No newline at end of file diff --git a/core/admin.py b/core/admin.py index 63d2e8a..ddce0fa 100644 --- a/core/admin.py +++ b/core/admin.py @@ -1,6 +1,4 @@ from django.contrib import admin - - from .models import Video @admin.register(Video) diff --git a/core/serializers.py b/core/serializers.py new file mode 100644 index 0000000..5452b30 --- /dev/null +++ b/core/serializers.py @@ -0,0 +1,7 @@ +from rest_framework import serializers +from .models import Video + +class VideoSerializer(serializers.ModelSerializer): + class Meta: + model = Video + fields = ['id', 'name'] \ No newline at end of file diff --git a/core/urls.py b/core/urls.py index b3b572f..6cec69f 100644 --- a/core/urls.py +++ b/core/urls.py @@ -1,11 +1,10 @@ from django.urls import path from . import views - urlpatterns = [ path('', views.core, name='core'), path('status/', views.status, name='status'), path('about/', views.about, name='about'), path('random/', views.random, name='random'), path('view/', views.view, name='view'), - ] +] diff --git a/ragnarok/settings.py b/ragnarok/settings.py index b1ed7a6..1392dd1 100644 --- a/ragnarok/settings.py +++ b/ragnarok/settings.py @@ -40,7 +40,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', - 'sage_stream', + #'sage_stream', 'core' ] diff --git a/ragnarok/urls.py b/ragnarok/urls.py index accda0b..6f8cdc5 100644 --- a/ragnarok/urls.py +++ b/ragnarok/urls.py @@ -22,9 +22,9 @@ urlpatterns = [ path('admin/', admin.site.urls), path('auth/', include('django.contrib.auth.urls')), path('', include('core.urls')), - path('/', include('core.urls')), - path('status/', include('core.urls')), - path('api/', include('sage_stream.api.urls')), + #path('/', include('core.urls')), + #path('status/', include('core.urls')), + path('api/', include('api.urls')), ] if settings.DEBUG: From 95d5aa699221b8086772ca3e6f04bf04a5be64af Mon Sep 17 00:00:00 2001 From: david Date: Fri, 19 May 2023 01:06:50 +0200 Subject: [PATCH 02/14] Api endpoint for video search with querying implemented --- .gitignore | 3 ++- api/urls.py | 2 +- api/views.py | 8 +++++--- core/__pycache__/__init__.cpython-38.pyc | Bin 122 -> 0 bytes core/__pycache__/admin.cpython-38.pyc | Bin 606 -> 0 bytes core/__pycache__/apps.cpython-38.pyc | Bin 395 -> 0 bytes core/__pycache__/models.cpython-38.pyc | Bin 879 -> 0 bytes core/__pycache__/urls.cpython-38.pyc | Bin 412 -> 0 bytes core/__pycache__/views.cpython-38.pyc | Bin 1460 -> 0 bytes .../__pycache__/0001_initial.cpython-38.pyc | Bin 709 -> 0 bytes ...umbnail_alter_video_created_at.cpython-38.pyc | Bin 784 -> 0 bytes ...deo_file_alter_video_thumbnail.cpython-38.pyc | Bin 663 -> 0 bytes .../__pycache__/__init__.cpython-38.pyc | Bin 133 -> 0 bytes ragnarok/__pycache__/__init__.cpython-38.pyc | Bin 126 -> 0 bytes ragnarok/__pycache__/settings.cpython-38.pyc | Bin 2594 -> 0 bytes ragnarok/__pycache__/urls.cpython-38.pyc | Bin 1259 -> 0 bytes ragnarok/__pycache__/wsgi.cpython-38.pyc | Bin 531 -> 0 bytes 17 files changed, 8 insertions(+), 5 deletions(-) delete mode 100644 core/__pycache__/__init__.cpython-38.pyc delete mode 100644 core/__pycache__/admin.cpython-38.pyc delete mode 100644 core/__pycache__/apps.cpython-38.pyc delete mode 100644 core/__pycache__/models.cpython-38.pyc delete mode 100644 core/__pycache__/urls.cpython-38.pyc delete mode 100644 core/__pycache__/views.cpython-38.pyc delete mode 100644 core/migrations/__pycache__/0001_initial.cpython-38.pyc delete mode 100644 core/migrations/__pycache__/0002_video_thumbnail_alter_video_created_at.cpython-38.pyc delete mode 100644 core/migrations/__pycache__/0003_alter_video_file_alter_video_thumbnail.cpython-38.pyc delete mode 100644 core/migrations/__pycache__/__init__.cpython-38.pyc delete mode 100644 ragnarok/__pycache__/__init__.cpython-38.pyc delete mode 100644 ragnarok/__pycache__/settings.cpython-38.pyc delete mode 100644 ragnarok/__pycache__/urls.cpython-38.pyc delete mode 100644 ragnarok/__pycache__/wsgi.cpython-38.pyc diff --git a/.gitignore b/.gitignore index f0c88a9..1d65383 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ db.sqlite3 videos/ channel_archiver/yt-dlp-archive.txt channel_archiver/UnusualVideos* -*__pycache__* \ No newline at end of file +*__pycache__* +*.pyc \ No newline at end of file diff --git a/api/urls.py b/api/urls.py index 1e2d1e6..951aa81 100644 --- a/api/urls.py +++ b/api/urls.py @@ -2,5 +2,5 @@ from django.urls import path from . import views urlpatterns = [ - path('', views.query) + path('', views.videoAPI), ] \ No newline at end of file diff --git a/api/views.py b/api/views.py index 9ddaf6e..d3ecbec 100644 --- a/api/views.py +++ b/api/views.py @@ -2,9 +2,11 @@ from rest_framework.response import Response from rest_framework.decorators import api_view from core.models import Video from core.serializers import VideoSerializer +from django.db.models import Q @api_view(['GET']) -def query(request): - videos = Video.objects.all() +def videoAPI(request): + q = request.GET.get('q', '') + videos = Video.objects.filter(Q(id__contains=q) | Q(name__contains=q)) serializer = VideoSerializer(videos, many=True) - return Response(serializer.data) \ No newline at end of file + return Response(serializer.data) diff --git a/core/__pycache__/__init__.cpython-38.pyc b/core/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 79d0b5fccaf117b7627b5fbeec9339f784795f9e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 122 zcmWIL<>g`kf<<3HCxht6AOaaM0yz#qT+9L_QW%06G#UL?G8BP?5yUTf{i6K*68)mY r^t{BP{A~T?{GwF-`1s7c%#!$cy@JYH95%W6DWy57b|8(PftUdR2I(2+ diff --git a/core/__pycache__/admin.cpython-38.pyc b/core/__pycache__/admin.cpython-38.pyc deleted file mode 100644 index 8f8ad87df812e1d7ae15dff4aab7cfc25a46a5ef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 606 zcmZuuv2N5r5S`t%9m~2PL<|21f@bKH7eAXKxUO(rPpu_6SraRBtAT$&6dJ=Ouc(4{I&4^HO+xAzG4rL z7#cW-55-q?u2%3(Z<15Ek=Bx->S?Z{UObQKr=wVKa{x#k(`;C&ed;91B_Mx diff --git a/core/__pycache__/apps.cpython-38.pyc b/core/__pycache__/apps.cpython-38.pyc deleted file mode 100644 index 1939d17577321bf8fa93cc6547d34a58c7bcab6e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 395 zcmYjNJx{|h5Vhk}DrvhQHiX2QCHVsgwN!$w3u4J)nVb^^oH#hi04t3A3O4?dS0-lE zg^9bS5FySbh@pLKfAV*HzbHAh5R)Z(ca8uIxM4NVIA=Eu0uXNugyydz z3n08@@#Gs>Eav`b)wXNf6jhm1<hl!)cxg2(l0as)RmTTc^kQmos=! zO=%OjPihO=bjej!u7=)TSK5FNbEIzKiJwZ@s9HegoJ`Kw3JIA04HJDy1 zoR`HYK)p}q=ngyhJx!gped<)%C}$s2`XNL@6G)?@bOci#@?B*U3qRX0N=z4! X8gc)1$7qH%KfM?iyrg4v#GQ*j%C%l$ diff --git a/core/__pycache__/models.cpython-38.pyc b/core/__pycache__/models.cpython-38.pyc deleted file mode 100644 index 2f41b9433b41084ad46a36596c7d968c1ad97e3f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 879 zcmZuvy^_-~5SA=E{)v;j8)_aPP4WT^0|RqZ7YYJ}8lhyB!#UYLWEn_?F4ta92_=t& zS}I(0x zl5s}KGXf048v>!Cn{dx~1knpJ8T`N+GNEoz)}VBQR$_}%?dnRceCT-G0lmguMK}e* z1I0EWPzY`*j}-en_(FJ$dkMl(2yX+P{^e!p4OPAwL4*}!q&0vTX~p}1pFjfX4dJJd zA+@24UKOC~1#%i*o1&CvE3VXb7r*n{&1@35w7u4~1Yv6zR;|{U8iQKPR@;BrqjbGY zr$_98as~mSv0c`oO)r#{#&$v)>z|$0QF{Fc+>9~Z#X?|)5dP#2h0xuo@9_|sPtHt=QR9y{L%(=L zmp*Q7eO@RH=B)D<>VxfkR2k)P>3N~mVPlOZPwktwTvoEsZuC@IwZJFTAHe(ptg7Gh zY-JRNKuFtlYwmf#JH>j-Gw;-o&}h7u(3~c8?7v{l4mUG!DQskQSx;fvbIuQbYYW|& c4mG;)Pr9r4AB;;L^f&s@OWpV@&uPwn0mnASd;kCd diff --git a/core/__pycache__/urls.cpython-38.pyc b/core/__pycache__/urls.cpython-38.pyc deleted file mode 100644 index 835d60ffcda92887e45fc7e9bc6cc8ed0bbb0692..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 412 zcmYk2y-ou$49AmR?xVe4;T0IWG&`y)RwM)iVyVOs>d;MOv4 zO>e+a{_#(CV#iNaHDPGCchB&^8T%smZ)1cT-0l?x81RO*e9bw75hTs1P1Xr#nuE~E zUO)=jM}m|irBDnsM#^9^P>Gbobf5~UfEm#?U60}7kcs>vWBPaYxm6vQ7UO59ujn1QtUG^Q!zv2G`}ri6 zuvgvIEP`#E9brwIk_eKFq#&VrSQ?ovQDTYN*reCCbDzx4C_wUkC9N@DhAz0E8f7=T g`luy!E~&uc@E(h0YaldwMIUr@Ys#l$#)tLu3sm%G;Q#;t diff --git a/core/__pycache__/views.cpython-38.pyc b/core/__pycache__/views.cpython-38.pyc deleted file mode 100644 index 1437c5f712c42ef615b22fe66264aecec0d5c638..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1460 zcmZWp&5q+l5bo->9mo0E>FAeonZEi&O{Q3mTU3%wkmO_W7m4$ICu&SEb|WjE`}j*Nd}St7eK z!M!VcvX6UD4&)H`zPu+#xDRCXElcm;pjUPcF4Afvl}^D8%W6?<&b4|~7g|Zw^q*V1 z{YIH>wJ{3MF{<&^+@c(QUr1F==Ro%y2SJK)eu>k3go|Y>IPfdB2P+zcD0u@2k4f>n zc!w2mDKL~^y6etzqsB|SE?sm%_nMo3aHN6m;4Q9G%~t5uIFXm77N|rkM|SWO+68o^+88VgV~~Kphx;8Q|Vaw{Y9_jLmIrS^^}V z0Ow_a86f~^a+1OOsL&5+p$}b%$yg{S7RtIP-)@o0uK%o3W?I>=ex(~cSwf%FELj$d zB{Jr`kopmQ4uuQ7xBn%%4TyXg^2Xo+1bhS>hWL!&5!dgdc20!99ps6U?i2no3Os^-!>QkT}~s%;w!K}?|~CAHWI6+>@EP>oLn zXmXqm-AJymF4fp9D{besH9mIt_^6&&8>@@iIIrz;EETq6ZYymxHJs}mjh6W9(Uec$ zA6bu@cD$~nDox7=V!Ur$UkZ=W`#;HukJooi{3(7~m+CV@ZYXA`*B2+mR4$7p~6ElEXlTCto_ z@`?b1;4^_h(QWW4$OGW7Njmt2xg=#SsdQmwr%m0uVP!y-?b?U#ON`(gwS9+1k(>g_ z8PGf^NY2$@JM=A7xQ&1Uhrxku7z|bTE&fi>3o(*F1o43)N)U}OZ{$(IVGK-Dm>hzF z=3|&5wFfS~_|IwS25&Vep=tWfT&5Ej z3E`Uv;SwQmQM=OnVSK3u7dXVxoxDWGOI@8{Vj6Wi)emAHVu{}TnPt|PF0-u-mtb0aS|1@>G=hI zX0Qab$hY$x!Y$<;FR9> zB^hJ|2UY~Y*SrW(RMZhd993fw5W#30z!>7KpiE4egfa=H)uhU*DWqEtlWn*TiaQ{P zN9L0A0|8q>sPEJl9%d#oEQt2YPE&+{8y0?9O*{D)q+>D1%n^VOY@JjW%b4kC^ zMuF_iaxQ2rKZQPP-fJX3lk$D9w7&f)1AQ2yk@N@GUIXh4@q9xNB{r; diff --git a/core/migrations/__pycache__/0003_alter_video_file_alter_video_thumbnail.cpython-38.pyc b/core/migrations/__pycache__/0003_alter_video_file_alter_video_thumbnail.cpython-38.pyc deleted file mode 100644 index 25548469914142d14f9feb1d89d2d4a08fff7fbc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 663 zcmZ8f&2H2%5O!>5H;Gz_1HJG7m7+?`3a$v1%W~RE2zv3wa(AX7ixV$Sf&^E%_TE?E zm3-yID^x--PXD%@$fNo5%=e9Rw!dF6lJ{2%R-Ccl(b*MA&Iz6VkQ6XTENc^$v|RCo zy<@;Z{A3_7*@z!P36LLHnf{?#R`O7^P3_IlxULVg)&bgn9aFoKk#j<)Uy?$m5@3o$ zQYT8F+@x^;&Ng$9kizVe!~F6to;{7%TxF0GfFk6pyU7GYuAN79v{)=&>aPu;)5E8+ zJ?~6owXp;G+vwV(84$D?R65lKdC^$>_TkHV4b%VX9_h6xT8xbyJLoZ?= zUlOLt4~5&}?S6kT|D3Xux?WY@xuNo=?u>VztH{54c#DcQ@#+!tNb^zP9{KV1n~(p% zj86Z8R3`X8naYIIxA%9)x}NGzOBr(5n67rma6VC(U{A>hh&R>&^$XeSn`OL-?E1+0 GnfMRWG_*(n diff --git a/core/migrations/__pycache__/__init__.cpython-38.pyc b/core/migrations/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index ffc280fd14f3d74dfc741f8ca2dc3ca4ad823fbb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 133 zcmWIL<>g`kf<<3HCxht6AOaaM0yz#qT+9L_QW%06G#UL?G8BP?5yUSo{i6K*68)mY z^t{BP{A~T?{GwF-+|2Z%#FEVXykhg`kf@^!gxK0Y%qvm`!Vub}c4hfQvNN@-529Z2(MAZ7pnenlIO diff --git a/ragnarok/__pycache__/settings.cpython-38.pyc b/ragnarok/__pycache__/settings.cpython-38.pyc deleted file mode 100644 index d64f6daef0d1542b3dbe3ae6645ec30bb6a0c5ee..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2594 zcmb7GTXWM!6t-l=x5ObN+{48bC>V$Ygejd)p;2rlcqfxYLXB}OPR!SPZ zcBa3A2Y74$L4V7>_NjlMoia@6k$j2kFjHzro85EHch1>w&sn*h&*u{G`C0iM{hCiC zev1~9pDZla;Grolkw6J8fjGoloXu-I7tNDaQcGeU3qNviX5J=xsa{G;BSFic87+%a zT~5oPG|HeX%Ar{_hw^A1o$6+_S+syoqeZlY&Y-jCTsN)Fq4QcEUBGE{aXHcD&)`@%z`t$y#B~br=kF1SNGyCG62Q4V z-|y3}Bni1D6$dd!8JMmuVMhXolJEA3Nu^Q7(!jmHhYOv+vI-WVe!=Y=@5pcv1j58C z92i!B>Hmr4;m$;$-=mr;a!lAV{Jna(KBR#-6q|vESFAN_$6GPHI}g^(dmXoU-P}2P zqW8@G)!^x?;OUNQn~&Dq!yCKyqaC+%bAPSZV%**E%)pOmx{mLWT`{ILT$+{!{$98| zC5#~0@%^Jdrs4T1CB>8i(I*u)D2y&3E=?nRI2toL5US04nEHChGi-e5di&aJ1ktJQ zVZ&yE38xvZ4B<9G$ijz)hsBr);vb1>LlRXCe-Dc;=wy65k8;FJT9TWK`FEg(&4TlC=MsK zDfVPPYVE+sDzS-WM4j<+VBvb0t&tD*R-BzPr2>qu;NFd1AZslh@^9T0?F8m1*1BVtJ5m0@%s+;$PR zsJKqL(17j+!4`VQNyTd{t?Tes&~=vX!`*9rLy@-U2TB~1W-&W%hf97 za#h)un+lt2HX1Fx-K>@x^$nJ7DYdPt+)`Awu&r)ZBKvBkBu90}vSqm?M`2ZVL2kF6 z>szv_Za11`{iR&3fU*JQnyft~~s*&Qj5=r9tK` z@LYrDVOl~TOVUlN`O{Kmt(qU5=*F9l9O0|RQ;+#?5A8nxH>{V4X2SmtXu z!N9`L;HO1`{se1&FbAFbSA6wo4=wyu@u&;yBpOV7>0Z ziGP6uH~ytuIq@&-fOvLWEg&JyRie)?pWpl5XS*l;zH7nwJ$e^^aV+bno>WH%CePrJ z-{BQoffd_vEwx!KsM#9V(>ikkhc$wRnLBBdwStzxjkL`=LC3bJ6E|sX=FYkoHNY*} zh}##o!5zTv5_c=OSHXS2Ynn4@20hxE^~E>Zqa8qN@T|w{Uu%!7pcikvwY(eTW6iPz znPf!p59s9R724(5IGGfJsDx*(dpxD+eIe4EC`Cmk-=j2<3JG2)D)j=16h~(X{Um*~ z&jn&!P?Th2E|^Jy@{|%uk)(9!A{bMpayi5}=8^Q{8ObI*7kow|~wQ5*jn~A<&18jj4=9Spz*+ScT*ze{ZnWxu4Mh63a+M9Xd%8aY9;3- z2&BOFXfECK(0FO(aADVC zJA7^UO5~EeWlXuY+S8OzFc`S1G|&N)ci?&MFSs3+XO|5Uvn2CsrK24$TT3>4X-ldU zG$R2wrGk?b&6|de=M7S*DW2b1iiIAPNKSnnH5E#0-ihE8n#rY&=PjL}ka+HpJi+r@ zl1ykQm7s+A5HUQ@4*GB+3q~^)3eMFVZ=-C5A;iKkSo^z{fJN4djzm-Q9hoRvI@X#;Em`jJG8nk>2+0pY&qXAFu+=RF!OsmRV66 zVet#AEzY6vS(*+!gXueITxnHwWb0q4u-$Z z4)_eOJaP%O#+wR^=U1*&JpC8vL595~JS)NH&0oGDBRoI)@P61o%}2*)XMSpO4sXzPM${%c^)Xb@MNVVD`Ep#gKKGI3LP*DWzmE*7D||kOYOs> s4a%RyHmh8^`xo3IdcG$6|7ZZS`X+SWu10zomrh(ay7o?&?$XEf0bm@ZZvX%Q From 19dc4b5b64026a1c48e2bea1026ab759f2d4255e Mon Sep 17 00:00:00 2001 From: david Date: Fri, 19 May 2023 01:33:35 +0200 Subject: [PATCH 03/14] Refactoring --- api/views.py | 2 +- core/views.py | 6 +----- ragnarok/urls.py | 2 -- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/api/views.py b/api/views.py index d3ecbec..7474215 100644 --- a/api/views.py +++ b/api/views.py @@ -1,8 +1,8 @@ +from django.db.models import Q from rest_framework.response import Response from rest_framework.decorators import api_view from core.models import Video from core.serializers import VideoSerializer -from django.db.models import Q @api_view(['GET']) def videoAPI(request): diff --git a/core/views.py b/core/views.py index 0e43982..3800c1e 100644 --- a/core/views.py +++ b/core/views.py @@ -1,9 +1,6 @@ from django.shortcuts import render -from django.contrib.auth.decorators import login_required -from django.http import HttpResponse from django.shortcuts import redirect from core.models import Video -import random # Create your views here. @@ -11,10 +8,9 @@ def core(request): videos = Video.objects.all() return render(request, 'base.html', {'videos': videos[::-1]}) - def random(request): videos = Video.objects.all().order_by("?") - ran = videos.first(); + ran = videos.first() return redirect('/view/'+str(ran.id)) def status(request): diff --git a/ragnarok/urls.py b/ragnarok/urls.py index 6f8cdc5..56cedde 100644 --- a/ragnarok/urls.py +++ b/ragnarok/urls.py @@ -22,8 +22,6 @@ urlpatterns = [ path('admin/', admin.site.urls), path('auth/', include('django.contrib.auth.urls')), path('', include('core.urls')), - #path('/', include('core.urls')), - #path('status/', include('core.urls')), path('api/', include('api.urls')), ] From 1206528e423fd45525acd898273707ccb84a0cda Mon Sep 17 00:00:00 2001 From: david Date: Fri, 19 May 2023 02:11:02 +0200 Subject: [PATCH 04/14] Repo cleanup --- .gitignore | 6 +++--- .vscode/settings.json | 6 ------ 2 files changed, 3 insertions(+), 9 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 1d65383..a667458 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ +.vscode/ +__pycache__/ db.sqlite3 videos/ channel_archiver/yt-dlp-archive.txt -channel_archiver/UnusualVideos* -*__pycache__* -*.pyc \ No newline at end of file +channel_archiver/UnusualVideos* \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 834369a..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "[python]": { - "editor.defaultFormatter": "ms-python.python" - }, - "python.formatting.provider": "none" -} \ No newline at end of file From 9f6727d26422256102c0878434d734f3b2f50aee Mon Sep 17 00:00:00 2001 From: david Date: Fri, 19 May 2023 02:39:23 +0200 Subject: [PATCH 05/14] Added API Documentation --- api/README | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 api/README diff --git a/api/README b/api/README new file mode 100644 index 0000000..057fcf1 --- /dev/null +++ b/api/README @@ -0,0 +1,7 @@ +# API +## VideoAPI + +| Method | URL | Action | +|-|-|-| +| `GET`| `/api` | Get all videos | +| `GET`| `/api?q=` | Get all videos containing `` | From bd28751013a4931e4fcb00ce04c27982e4156f18 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 19 May 2023 02:41:25 +0200 Subject: [PATCH 06/14] =?UTF-8?q?=E2=80=9Eapi/README.md=E2=80=9C=20=C3=A4n?= =?UTF-8?q?dern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/{README => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename api/{README => README.md} (100%) diff --git a/api/README b/api/README.md similarity index 100% rename from api/README rename to api/README.md From c4af1d18081892b6e7a5f0c146ef9bdf1252fccd Mon Sep 17 00:00:00 2001 From: david Date: Fri, 19 May 2023 15:31:05 +0200 Subject: [PATCH 07/14] Added limit parameter to VideoAPI search and improved documentation --- api/README.md | 31 +++++++++++++++++++++++++------ api/views.py | 7 ++++++- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/api/README.md b/api/README.md index 057fcf1..cb1174b 100644 --- a/api/README.md +++ b/api/README.md @@ -1,7 +1,26 @@ -# API -## VideoAPI +# VideoAPI + +## Search +`GET \api?param=value` + +### Parameters +| Param | Value | +|-|-| +| `q` | The search query string. | +| `limit` | A limit on the number of objects to be returned. Default is 6. | + +### Response +``` +[ + { + "id": 1, + "name": "Video 1" + }, + {...} +] +``` + +### Examples +> `GET /api?q=foo&limit=3` will return the first 3 videos with "foo" in their name. + -| Method | URL | Action | -|-|-|-| -| `GET`| `/api` | Get all videos | -| `GET`| `/api?q=` | Get all videos containing `` | diff --git a/api/views.py b/api/views.py index 7474215..db931e7 100644 --- a/api/views.py +++ b/api/views.py @@ -7,6 +7,11 @@ from core.serializers import VideoSerializer @api_view(['GET']) def videoAPI(request): q = request.GET.get('q', '') - videos = Video.objects.filter(Q(id__contains=q) | Q(name__contains=q)) + l = request.GET.get('limit', '') + try: + l = int(l) + videos = Video.objects.filter(Q(id__contains=q) | Q(name__contains=q))[:l] + except: + videos = Video.objects.filter(Q(id__contains=q) | Q(name__contains=q)) serializer = VideoSerializer(videos, many=True) return Response(serializer.data) From 76fee9b57ac5303583b4dd5969367d44032b962f Mon Sep 17 00:00:00 2001 From: david Date: Fri, 19 May 2023 17:03:06 +0200 Subject: [PATCH 08/14] Fixed some small errors --- api/README.md | 6 ++---- api/views.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/api/README.md b/api/README.md index cb1174b..eded595 100644 --- a/api/README.md +++ b/api/README.md @@ -1,7 +1,7 @@ # VideoAPI ## Search -`GET \api?param=value` +`GET /api/?param=value` ### Parameters | Param | Value | @@ -21,6 +21,4 @@ ``` ### Examples -> `GET /api?q=foo&limit=3` will return the first 3 videos with "foo" in their name. - - +> `GET /api/?q=foo&limit=3` will return the first 3 videos with "foo" in their name. diff --git a/api/views.py b/api/views.py index db931e7..5c20c50 100644 --- a/api/views.py +++ b/api/views.py @@ -7,7 +7,7 @@ from core.serializers import VideoSerializer @api_view(['GET']) def videoAPI(request): q = request.GET.get('q', '') - l = request.GET.get('limit', '') + l = request.GET.get('limit', '6') try: l = int(l) videos = Video.objects.filter(Q(id__contains=q) | Q(name__contains=q))[:l] From 21ee1703022ffcb55aadd01a6cf0c39500705167 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 19 May 2023 18:17:55 +0200 Subject: [PATCH 09/14] Groundwork in base.html and searchsuggestions.js --- core/templates/base.html | 4 +++- static/dist/js/searchsuggestions.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 static/dist/js/searchsuggestions.js diff --git a/core/templates/base.html b/core/templates/base.html index c81382d..1e0b380 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -56,7 +56,8 @@ + aria-label="Search" + id="searchinput">
+ diff --git a/static/dist/js/searchsuggestions.js b/static/dist/js/searchsuggestions.js index 5db7484..04035dd 100644 --- a/static/dist/js/searchsuggestions.js +++ b/static/dist/js/searchsuggestions.js @@ -1,13 +1,27 @@ +/* const searchinput = document.querySelector("#searchinput"); +const searchsuggestions = document.querySelector("#searchsuggestions"); searchinput.addEventListener("input", (e) => { q(e.target.value); }); async function q(s) { try { - const response = await fetch("http://localhost:8000/api/?q=" + s); + const response = await fetch("/api/?q=" + s); const result = await response.json(); console.log("Success: " + JSON.stringify(result)); + setSuggestions(searchsuggestions, result); } catch(error) { console.log("Error: " + error); } -} \ No newline at end of file +} +function setSuggestions(o, s) { + const newSuggestions = []; + for (const vid of s) { + const newSugg = document.createElement("a"); + newSugg.setAttribute("href", "/view/" + vid.id); + newSugg.insertAdjacentText("afterbegin", vid.name + " " + vid.id); + newSuggestions.push(newSugg); + } + o.replaceChildren(...newSuggestions); +} +*/ From bf51819cbc7787434eb68d756c04a6ec183b3fc8 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 20 May 2023 00:34:10 +0200 Subject: [PATCH 11/14] sage_stream back in business --- api/urls.py | 5 +++-- api/views.py | 2 +- ragnarok/settings.py | 2 +- ragnarok/urls.py | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/api/urls.py b/api/urls.py index 951aa81..ad6ea78 100644 --- a/api/urls.py +++ b/api/urls.py @@ -1,6 +1,7 @@ -from django.urls import path +from django.urls import path, include from . import views urlpatterns = [ - path('', views.videoAPI), + path('search/', views.searchAPI), + path('', include('sage_stream.api.urls')), ] \ No newline at end of file diff --git a/api/views.py b/api/views.py index 5c20c50..200f5db 100644 --- a/api/views.py +++ b/api/views.py @@ -5,7 +5,7 @@ from core.models import Video from core.serializers import VideoSerializer @api_view(['GET']) -def videoAPI(request): +def searchAPI(request): q = request.GET.get('q', '') l = request.GET.get('limit', '6') try: diff --git a/ragnarok/settings.py b/ragnarok/settings.py index 1392dd1..b1ed7a6 100644 --- a/ragnarok/settings.py +++ b/ragnarok/settings.py @@ -40,7 +40,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', - #'sage_stream', + 'sage_stream', 'core' ] diff --git a/ragnarok/urls.py b/ragnarok/urls.py index 56cedde..06e2710 100644 --- a/ragnarok/urls.py +++ b/ragnarok/urls.py @@ -23,6 +23,7 @@ urlpatterns = [ path('auth/', include('django.contrib.auth.urls')), path('', include('core.urls')), path('api/', include('api.urls')), + #path('api/', include('sage_stream.api.urls')), ] if settings.DEBUG: From 4d60016ef40e6bb88249e1f783c9a1c568a23ab9 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 20 May 2023 02:11:33 +0200 Subject: [PATCH 12/14] god save me --- core/templates/base.html | 14 +++++++------- ragnarok/urls.py | 1 - static/dist/js/searchsuggestions.js | 25 ++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/core/templates/base.html b/core/templates/base.html index 421d8e5..2f70854 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -12,8 +12,7 @@ - +
@@ -52,16 +51,17 @@
+ +
- + aria-label="Search">