Compare commits

...

2 Commits

Author SHA1 Message Date
Otto Naderer 576296933c updated to mistune 3.0+ 2024-04-16 16:30:05 +02:00
Otto Naderer 9825a66281 init migration to django 4.x 2024-04-11 14:32:32 +02:00
7 changed files with 50 additions and 29 deletions

View File

@ -10,7 +10,7 @@ class blogcategory(models.Model):
class blogentry(models.Model):
user = models.ForeignKey(User)
user = models.ForeignKey(User, on_delete=models.CASCADE)
date = models.DateTimeField('date')
header = models.CharField(max_length=100)
intro = models.CharField(max_length=1000)
@ -24,7 +24,7 @@ class blogentry(models.Model):
class blogcomment(models.Model):
blogentry = models.ForeignKey(blogentry, on_delete=models.CASCADE)
user = models.ForeignKey(User, null=True, blank=True)
user = models.ForeignKey(User, null=True, blank=True, on_delete=models.CASCADE)
guestname = models.CharField(max_length=20)
body = models.CharField(max_length=300)
date = models.DateTimeField('date')

View File

@ -1,10 +1,10 @@
from django.conf.urls import url
from django.urls import include, re_path
from . import views
urlpatterns = [
url(r'^$', views.listall, name='listall'),
url(r'^(?P<blogentry_id>\d+)/$', views.detail, name='detail'),
url(r'^category/(?P<category_id>\d+)/$', views.list_category, name='category'),
#url(r'^$', views.detail, name='detail'),
re_path(r'^$', views.listall, name='listall'),
re_path(r'^(?P<blogentry_id>\d+)/$', views.detail, name='detail'),
re_path(r'^category/(?P<category_id>\d+)/$', views.list_category, name='category'),
#re_path(r'^$', views.detail, name='detail'),
]

View File

@ -44,7 +44,7 @@ def detail(request, blogentry_id):
bc.save()
renderer = CustomRenderer()
md = mistune.Markdown(renderer=renderer, hard_wrap=True)
md = mistune.Markdown(renderer=renderer)#, hard_wrap=True)
blogdetail.body = md(blogdetail.body)
form = BlogCommentForm()

View File

@ -2,9 +2,27 @@
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "polysite.settings")
#if __name__ == "__main__":
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "polysite.settings")##
from django.core.management import execute_from_command_line
# from django.core.management import execute_from_command_line
# execute_from_command_line(sys.argv)
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'polysite.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

View File

@ -3,13 +3,14 @@ from imageapp.models import BlogImage
from blogapp.models import blogentry, blogcategory, blogcomment
class CustomRenderer(mistune.Renderer):
def image(self, src, title, alt_text):
class CustomRenderer(mistune.HTMLRenderer):
def image(self, alt, url, title=None):
try:
img = BlogImage.objects.get(pk=src)
img = BlogImage.objects.get(pk=int(url))
print(img.image.url)
return '<div id="textimg"><img width="100%" src="' + img.image.url + '"/><br>Title: ' + img.title + '<br>Caption: ' + img.caption + '</div>'
except BlogImage.DoesNotExist:
return '<i>Should display an image here but none with id ' + src + ' was found.</i>'
except:
return '<i>You should see an image here that has not been found unfortunately.</i>'
def footer_info(request):

View File

@ -11,9 +11,11 @@ https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
@ -31,26 +33,26 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'blogapp.apps.BlogappConfig',
'pageapp.apps.PageappConfig',
'imageapp.apps.ImageappConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blogapp.apps.BlogappConfig',
'pageapp.apps.PageappConfig',
'imageapp.apps.ImageappConfig',
]
MIDDLEWARE_CLASSES = [
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'polysite.urls'

View File

@ -13,7 +13,7 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.urls import include, re_path
from django.contrib import admin
from pageapp.views import aboutpage, contactpage
#from blogapp.views import listall
@ -22,10 +22,10 @@ from django.conf.urls.static import static
from . import views, settings
urlpatterns = [
url(r'^$', views.redi),
url(r'^blog/', include('blogapp.urls')),
url(r'^admin/', admin.site.urls),
url(r'^about/', aboutpage, name='about'),
url(r'^contact/', contactpage, name='contact'),
# url(r'^', listall),
re_path(r'^$', views.redi),
re_path(r'^blog/', include('blogapp.urls')),
re_path(r'^admin/', admin.site.urls),
re_path(r'^about/', aboutpage, name='about'),
re_path(r'^contact/', contactpage, name='contact'),
# re_path(r'^', listall),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)