Finally put in proper converters, errors should be more accurate. Also put in an anti-slash redirect (because base only comes with pro-slash redirect, why...), and I think other stuff.

This commit is contained in:
Zergling_man 2022-01-26 19:51:03 +11:00
parent 5e3fc17daa
commit 86421a7eb3
6 changed files with 18 additions and 13 deletions

View File

@ -1,8 +1,10 @@
from django.urls import path, re_path, include from django.urls import path, register_converter
from . import views from . import views,converters
register_converter(converters.RealIntConverter,'rint')
urlpatterns=[ urlpatterns=[
path('',views.index,name='bidex'), path('',views.index,name='bidex'),
path('<str:bookurl>',views.book,name='bbook'), path('<str:bookurl>',views.book,name='bbook'),
path('<str:bookurl>/<str:chapnum>',views.chapter,name='bchap'), path('<str:bookurl>/<rint:chapnum>',views.chapter,name='bchap'),
] ]

View File

@ -58,6 +58,6 @@ def book(bookurl):
@rerender @rerender
def chapter(bookurl,chapnum): def chapter(bookurl,chapnum):
book=models.Book.objects.filter(url=bookurl)[0] book=models.Book.objects.filter(url=bookurl)[0]
chapter=models.Chapter.objects.filter(book=book,number=int(chapnum))[0] chapter=models.Chapter.objects.filter(book=book,number=chapnum)[0]
text='<p>'+chapter.contents.replace('<','&lt;').replace('>','&gt;').replace('\n\n','</p><p>').replace('\n','<br/>')+'</p>' text='<p>'+chapter.contents.replace('<','&lt;').replace('>','&gt;').replace('\n\n','</p><p>').replace('\n','<br/>')+'</p>'
return {'title':chapter,'content':'<p>Navigation buttons will come later...</p>\n'+text,'date':chapter.added} return {'title':chapter,'content':'<p>Navigation buttons will come later...</p>\n'+text,'date':chapter.added}

View File

@ -1,5 +1,6 @@
from django.db import models from django.db import models
from datetime import date from datetime import date
from django.utils.timezone import now
# Create your models here. # Create your models here.
@ -35,7 +36,7 @@ class Contact(models.Model):
class Update(models.Model): class Update(models.Model):
page=models.CharField(max_length=100) page=models.CharField(max_length=100)
date=models.DateField() date=models.DateField(default=now)
class Redirect(models.Model): class Redirect(models.Model):
match=models.CharField(max_length=200) match=models.CharField(max_length=200)

View File

@ -1,5 +1,7 @@
from django.urls import path, re_path, include from django.urls import path, register_converter
from . import views from . import views,converters
register_converter(converters.AutoPageConverter,'autopage')
urlpatterns=[ urlpatterns=[
path('',views.index,name='idex'), path('',views.index,name='idex'),
@ -10,8 +12,8 @@ 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'),
re_path('r/(.*)',views.redirect,name='redirect'), path('r/<path: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'),
re_path('(.*)',views.autopage,name='everything'), path('<autopage:page>',views.autopage,name='everything'),
] ]

View File

@ -79,7 +79,7 @@ def contact():
out2+='\n'.join(map(lii,v)) out2+='\n'.join(map(lii,v))
out2+="\n</ul></p>" out2+="\n</ul></p>"
out3+=out2 out3+=out2
return {'title':'Contact','content':head+out3,'date':Update.objects.get(page='contact').date} return {'title':'Contact','content':head+out3,'date':Update.objects.get_or_create(page='contact')[0].date}
def specs(req): def specs(req):
with open('main/pages/specs') as b: with open('main/pages/specs') as b:
@ -139,5 +139,4 @@ END:VCARD""")
@rerender @rerender
def autopage(page): def autopage(page):
p=Page.objects.get(url=page) return {'title':page.title,'content':page.contents,'date':page.last_edited}
return {'title':p.title,'content':p.contents,'date':p.last_edited}

View File

@ -46,7 +46,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'rakka.UncommonMiddleware.UnCommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
@ -104,6 +104,7 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
REMOVE_SLASH=True
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/ # https://docs.djangoproject.com/en/3.1/topics/i18n/