Redirects now use DB

This commit is contained in:
Zergling_man 2022-02-27 23:23:26 +11:00
parent f008d0030a
commit 6c567292e5
6 changed files with 22 additions and 33 deletions

View File

@ -6,5 +6,4 @@ from .models import Page,Contact,Update,Redirect
admin.site.register(Page) admin.site.register(Page)
admin.site.register(Contact) admin.site.register(Contact)
admin.site.register(Update) admin.site.register(Update)
admin.site.register(Redirect) admin.site.register(Redirect)
#dum

View File

@ -1,4 +1,4 @@
from .models import Page from .models import Page,Redirect
class AutoPageConverter: class AutoPageConverter:
regex='.*' regex='.*'
@ -9,4 +9,15 @@ class AutoPageConverter:
return p return p
def to_url(self,value): def to_url(self,value):
if not isinstance(value,Page): raise ValueError('Given value is not a Page') if not isinstance(value,Page): raise ValueError('Given value is not a Page')
return p.url return p.url
class RedirectConverter:
regex='.*'
def to_python(self,value):
try: r=Redirect.objects.get(match=value)
except Page.DoesNotExist: raise ValueError(f'No such redirect {value}')
if not r: raise ValueError(f'No such redirect {value}')
return r
def to_url(self,value):
if not isinstance(value,Redirect): raise ValueError('Given value is not a Redirect')
return p.match

View File

@ -40,4 +40,7 @@ class Update(models.Model):
class Redirect(models.Model): class Redirect(models.Model):
match=models.CharField(max_length=200) match=models.CharField(max_length=200)
output=models.CharField(max_length=500) output=models.CharField(max_length=500)
def __str__(self):
return self.match

View File

@ -1,22 +0,0 @@
adobe: https://www.patreon.com/posts/26834357
faplog: https://docs.google.com/spreadsheets/d/1sIh5evj1Janf_fdefbrksGLyHO_uMMDOjHJReA0P0fw/edit
fpdam: https://docs.google.com/document/d/1XSKSC9PYxAE1ys2u5ALD3wDBaps6LQgGe-GtyAju3q8/edit?usp=sharing
fpdb: https://docs.google.com/spreadsheets/d/1iJd8dBMbAKfwbfcWNnE-tElu4amJdtz4iMxWCxwKNY8/edit
fuckmeyourself: https://gelbooru.com/index.php?page=post&s=view&id=4608040
hitspark: https://images.squarespace-cdn.com/content/v1/5728734545bf2166bba67b00/1538785588130-I8WVGV947EEW81LII25S/ke17ZwdGBToddI8pDm48kODKEPcE7oOaZ-HX_UAJexAUqsxRUqqbr1mOJYKfIPR7LoDQ9mXPOjoJoqy81S2I8N_N4V1vUb5AoIIIbLZhVYy7Mythp_T-mtop-vrsUOmeInPi9iDjx9w8K4ZfjXt2dhV8WLpqAVTw2_ZfbaHHLLR7LAwPhjFlJ4O4wogcebl8m7cT0R_dexc_UL_zbpz6JQ/frame_advantage_5up.jpg?format=1000w
homo: https://innermantheatre.files.wordpress.com/2020/11/lightspeed-lab-ep.261-homosexuality.jpg
homo/s: https://innermantheatre.com/2021/03/29/lightspeed-lab-homosexuality/
miruku: http://danbooru.donmai.us/posts/578126
nadeko: https://docs.google.com/spreadsheets/d/12ZpOI3coZHlSFQ7oFuo1HzbkTkgX8RBk06oeMM56HFQ/edit#gid=0
nlship: https://docs.google.com/document/d/1oVZSv7v8cePVu22qmbgkCUtm9LnUcSZIaQyH-3b_DhI/edit?usp=sharing
nlvn: https://docs.google.com/document/d/1tVVI2NAY_1vFLsMrbRzn18FiXNzZcDgdxnNXKHEFzTs/edit#
osscans: https://discord.gg/VStXkfm
ossd: https://drive.google.com/drive/folders/14xIZJER551zEB9rP9d655MdpRE0xDBW8
perm: http://nadekobot.readthedocs.io/en/latest/Permissions%20System/
rinbot: https://discordapp.com/oauth2/authorize?client_id=448458599673364481&scope=bot
sauce: https://discord.gg/gsUT8B
spook: /static/pics/SPOOKY/SCARY/SKELETONS/SEND/SHIVERS/DOWN/YOUR/SPINE/SHRIEKING/SKULLS/WILL/SHOCK/YOUR/SOUL/SEAL/YOUR/DOOM/TONIGHT/SPOOKY/SCARY/SKELETONS/SPEAK/WITH/SUCH/A/SCREECH/YOU'LL/SHAKE/AND/SHUDDER/IN/SURPRISE/WHEN/YOU/HEAR/THESE/ZOMBIES/SHRIEK/WE'RE/SO/SORRY/SKELETONS/YOU'RE/SO/MISUNDERSTOOD/YOU/ONLY/WANT/TO/SOCIALIZE/BUT/I/DON'T/THINK/WE/SHOULD/CAUSE_SPOOKY_SCARY_SKELETONS_SHOUT_STARTLING_SHRILLY_SCREAMS.gif
wou: https://discord.gg/8sc5m6R
WushuAT: https://docs.google.com/document/d/1wtJ6JCpmpr-ziAb0UR0OpW1tX7Ms5CiDFUQkjPgFzIE/edit?usp=drive_web&ouid=102857329945830311247
years: https://docs.google.com/spreadsheets/d/1p7NIoC2-o8BJvbLD5N1WazaFAtw4vto7bxJMGsarcgE/edit
support: https://www.nerfnow.com/comic/1434

View File

@ -2,6 +2,7 @@ from django.urls import path, register_converter
from . import views,converters from . import views,converters
register_converter(converters.AutoPageConverter,'autopage') register_converter(converters.AutoPageConverter,'autopage')
register_converter(converters.RedirectConverter,'redirect')
urlpatterns=[ urlpatterns=[
path('',views.index,name='idex'), path('',views.index,name='idex'),
@ -12,7 +13,7 @@ urlpatterns=[
path('nerdshope',views.nerdshope,name='shop'), path('nerdshope',views.nerdshope,name='shop'),
path('teapot',views.teapot,name='teapot'), path('teapot',views.teapot,name='teapot'),
path('toask',views.articles,name='articles'), path('toask',views.articles,name='articles'),
path('r/<path:src>',views.redirect,name='redirect'), path('r/<redirect:src>',views.redirect,name='redirect'),
path('md.rss',views.md,name='md'), path('md.rss',views.md,name='md'),
path('me.vcf',views.vcard,name='vcard'), path('me.vcf',views.vcard,name='vcard'),
path('<autopage:page>',views.autopage,name='everything'), path('<autopage:page>',views.autopage,name='everything'),

View File

@ -2,7 +2,7 @@ from django.http import HttpResponse
import random as ra import random as ra
import asyncio import asyncio
from . import mdl from . import mdl
from .models import Page,Contact,Update from .models import Page,Contact,Update,Redirect
from rakka.utils import rerender,parsecat from rakka.utils import rerender,parsecat
@ -74,10 +74,7 @@ def articles():
return {'title':'Articles','content':'<p>'+('</p><p>'.join(out))+'</p>','date':'2021/05/06'} return {'title':'Articles','content':'<p>'+('</p><p>'.join(out))+'</p>','date':'2021/05/06'}
def redirect(req,src): def redirect(req,src):
with open('main/pages/redirects') as b: return HttpResponse(status=302,headers={'Location':src.output})
lonks=b.read()
lonks=dict([n.split(': ',1) for n in lonks.split('\n')])
return HttpResponse(status=302,headers={'Location':lonks[src]})
def md(req): def md(req):
loop=asyncio.get_event_loop() loop=asyncio.get_event_loop()