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:
parent
5e3fc17daa
commit
86421a7eb3
|
@ -1,8 +1,10 @@
|
|||
from django.urls import path, re_path, include
|
||||
from . import views
|
||||
from django.urls import path, register_converter
|
||||
from . import views,converters
|
||||
|
||||
register_converter(converters.RealIntConverter,'rint')
|
||||
|
||||
urlpatterns=[
|
||||
path('',views.index,name='bidex'),
|
||||
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'),
|
||||
]
|
|
@ -58,6 +58,6 @@ def book(bookurl):
|
|||
@rerender
|
||||
def chapter(bookurl,chapnum):
|
||||
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('<','<').replace('>','>').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}
|
|
@ -1,5 +1,6 @@
|
|||
from django.db import models
|
||||
from datetime import date
|
||||
from django.utils.timezone import now
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
@ -35,7 +36,7 @@ class Contact(models.Model):
|
|||
|
||||
class Update(models.Model):
|
||||
page=models.CharField(max_length=100)
|
||||
date=models.DateField()
|
||||
date=models.DateField(default=now)
|
||||
|
||||
class Redirect(models.Model):
|
||||
match=models.CharField(max_length=200)
|
||||
|
|
10
main/urls.py
10
main/urls.py
|
@ -1,5 +1,7 @@
|
|||
from django.urls import path, re_path, include
|
||||
from . import views
|
||||
from django.urls import path, register_converter
|
||||
from . import views,converters
|
||||
|
||||
register_converter(converters.AutoPageConverter,'autopage')
|
||||
|
||||
urlpatterns=[
|
||||
path('',views.index,name='idex'),
|
||||
|
@ -10,8 +12,8 @@ urlpatterns=[
|
|||
path('nerdshope',views.nerdshope,name='shop'),
|
||||
path('teapot',views.teapot,name='teapot'),
|
||||
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('me.vcf',views.vcard,name='vcard'),
|
||||
re_path('(.*)',views.autopage,name='everything'),
|
||||
path('<autopage:page>',views.autopage,name='everything'),
|
||||
]
|
|
@ -79,7 +79,7 @@ def contact():
|
|||
out2+='\n'.join(map(lii,v))
|
||||
out2+="\n</ul></p>"
|
||||
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):
|
||||
with open('main/pages/specs') as b:
|
||||
|
@ -139,5 +139,4 @@ END:VCARD""")
|
|||
|
||||
@rerender
|
||||
def autopage(page):
|
||||
p=Page.objects.get(url=page)
|
||||
return {'title':p.title,'content':p.contents,'date':p.last_edited}
|
||||
return {'title':page.title,'content':page.contents,'date':page.last_edited}
|
|
@ -46,7 +46,7 @@ INSTALLED_APPS = [
|
|||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'rakka.UncommonMiddleware.UnCommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
|
@ -104,6 +104,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||
},
|
||||
]
|
||||
|
||||
REMOVE_SLASH=True
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/3.1/topics/i18n/
|
||||
|
|
Loading…
Reference in New Issue
Block a user