From 86421a7eb3fc74a53ae3fc61e5163198e593b848 Mon Sep 17 00:00:00 2001 From: Zergling_man Date: Wed, 26 Jan 2022 19:51:03 +1100 Subject: [PATCH] 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. --- books/urls.py | 8 +++++--- books/views.py | 2 +- main/models.py | 3 ++- main/urls.py | 10 ++++++---- main/views.py | 5 ++--- rakka/settings.py | 3 ++- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/books/urls.py b/books/urls.py index 5f3ad79..0c4c877 100644 --- a/books/urls.py +++ b/books/urls.py @@ -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('',views.book,name='bbook'), - path('/',views.chapter,name='bchap'), + path('/',views.chapter,name='bchap'), ] \ No newline at end of file diff --git a/books/views.py b/books/views.py index cfd92f1..f94b32e 100644 --- a/books/views.py +++ b/books/views.py @@ -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='

'+chapter.contents.replace('<','<').replace('>','>').replace('\n\n','

').replace('\n','
')+'

' return {'title':chapter,'content':'

Navigation buttons will come later...

\n'+text,'date':chapter.added} \ No newline at end of file diff --git a/main/models.py b/main/models.py index 6ac6132..d82aef5 100644 --- a/main/models.py +++ b/main/models.py @@ -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) diff --git a/main/urls.py b/main/urls.py index 45fe464..2921bdf 100644 --- a/main/urls.py +++ b/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/',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('',views.autopage,name='everything'), ] \ No newline at end of file diff --git a/main/views.py b/main/views.py index 0f5fddc..2d5fed1 100644 --- a/main/views.py +++ b/main/views.py @@ -79,7 +79,7 @@ def contact(): out2+='\n'.join(map(lii,v)) out2+="\n

" 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} \ No newline at end of file + return {'title':page.title,'content':page.contents,'date':page.last_edited} \ No newline at end of file diff --git a/rakka/settings.py b/rakka/settings.py index 54f642d..ad278c4 100644 --- a/rakka/settings.py +++ b/rakka/settings.py @@ -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/