From dae9aac1bcaeaab86649051cd0ab56a9fecbf63c Mon Sep 17 00:00:00 2001 From: Bobby Date: Fri, 18 Nov 2022 15:12:23 -0500 Subject: rename module --- ignis/__init__.py | 0 ignis/admin.py | 3 +++ ignis/apps.py | 6 ++++++ ignis/migrations/__init__.py | 0 ignis/models.py | 3 +++ ignis/tests.py | 3 +++ ignis/urls.py | 8 ++++++++ ignis/views.py | 39 +++++++++++++++++++++++++++++++++++++ iss/__init__.py | 0 iss/admin.py | 3 --- iss/apps.py | 6 ------ iss/migrations/__init__.py | 0 iss/models.py | 3 --- iss/tests.py | 3 --- iss/urls.py | 8 -------- iss/views.py | 39 ------------------------------------- templates/blog/post.html | 2 +- templates/blog_admin/edit_post.html | 6 +++--- templates/blog_admin/new_post.html | 4 ++-- thatcomputerscientist/settings.py | 2 +- thatcomputerscientist/urls.py | 2 +- 21 files changed, 70 insertions(+), 70 deletions(-) create mode 100644 ignis/__init__.py create mode 100644 ignis/admin.py create mode 100644 ignis/apps.py create mode 100644 ignis/migrations/__init__.py create mode 100644 ignis/models.py create mode 100644 ignis/tests.py create mode 100644 ignis/urls.py create mode 100644 ignis/views.py delete mode 100644 iss/__init__.py delete mode 100644 iss/admin.py delete mode 100644 iss/apps.py delete mode 100644 iss/migrations/__init__.py delete mode 100644 iss/models.py delete mode 100644 iss/tests.py delete mode 100644 iss/urls.py delete mode 100644 iss/views.py diff --git a/ignis/__init__.py b/ignis/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ignis/admin.py b/ignis/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/ignis/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/ignis/apps.py b/ignis/apps.py new file mode 100644 index 00000000..8c2eea77 --- /dev/null +++ b/ignis/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class IgnisConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'ignis' diff --git a/ignis/migrations/__init__.py b/ignis/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ignis/models.py b/ignis/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/ignis/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/ignis/tests.py b/ignis/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/ignis/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/ignis/urls.py b/ignis/urls.py new file mode 100644 index 00000000..4e931c4d --- /dev/null +++ b/ignis/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from . import views + +app_name = 'ignis' +urlpatterns = [ + path('tex/', views.tex, name='tex'), + path('post_image//', views.post_image, name='post_image'), +] diff --git a/ignis/views.py b/ignis/views.py new file mode 100644 index 00000000..ffbce848 --- /dev/null +++ b/ignis/views.py @@ -0,0 +1,39 @@ +from django.shortcuts import render +from PIL import Image +from io import BytesIO +from django.http import HttpResponse +from django.views.decorators.csrf import csrf_exempt +import base64 +from blog.models import Post + +# Create your views here. +@csrf_exempt +def tex(request): + # get expression from request query + expression = request.GET.get('expr').replace('"', '').strip() + if not expression: + return HttpResponse('No expression provided!', status=400) + + import requests + + image = requests.get('https://latex.codecogs.com/png.image?%5Cinline%20%5Clarge%20%5Cdpi%7B300%7D%5Cbg%7Btransparent%7D' + expression).content + + # Image is a transparent GIF with black text. Invert the colors. + image = Image.open(BytesIO(image)) + image = image.convert('RGBA') + image = Image.eval(image, lambda x: 255 - x) + + # Convert back to gif and return + output = BytesIO() + image.save(output, format='GIF') + return HttpResponse(output.getvalue(), content_type='image/gif') + +@csrf_exempt +def post_image(request, post_id): + pi = Post.objects.get(id=post_id).post_image + if not pi: + return HttpResponse('No image found!', status=404) + + # convert base64 data src to image + image = base64.b64decode(pi.split(',')[1]) + return HttpResponse(image, content_type='image/png') diff --git a/iss/__init__.py b/iss/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/iss/admin.py b/iss/admin.py deleted file mode 100644 index 8c38f3f3..00000000 --- a/iss/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/iss/apps.py b/iss/apps.py deleted file mode 100644 index 343a2e09..00000000 --- a/iss/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class IssConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'iss' diff --git a/iss/migrations/__init__.py b/iss/migrations/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/iss/models.py b/iss/models.py deleted file mode 100644 index 71a83623..00000000 --- a/iss/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/iss/tests.py b/iss/tests.py deleted file mode 100644 index 7ce503c2..00000000 --- a/iss/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/iss/urls.py b/iss/urls.py deleted file mode 100644 index aa083ee5..00000000 --- a/iss/urls.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.urls import path -from . import views - -app_name = 'iss' -urlpatterns = [ - path('tex/', views.tex, name='tex'), - path('post_image//', views.post_image, name='post_image'), -] diff --git a/iss/views.py b/iss/views.py deleted file mode 100644 index ffbce848..00000000 --- a/iss/views.py +++ /dev/null @@ -1,39 +0,0 @@ -from django.shortcuts import render -from PIL import Image -from io import BytesIO -from django.http import HttpResponse -from django.views.decorators.csrf import csrf_exempt -import base64 -from blog.models import Post - -# Create your views here. -@csrf_exempt -def tex(request): - # get expression from request query - expression = request.GET.get('expr').replace('"', '').strip() - if not expression: - return HttpResponse('No expression provided!', status=400) - - import requests - - image = requests.get('https://latex.codecogs.com/png.image?%5Cinline%20%5Clarge%20%5Cdpi%7B300%7D%5Cbg%7Btransparent%7D' + expression).content - - # Image is a transparent GIF with black text. Invert the colors. - image = Image.open(BytesIO(image)) - image = image.convert('RGBA') - image = Image.eval(image, lambda x: 255 - x) - - # Convert back to gif and return - output = BytesIO() - image.save(output, format='GIF') - return HttpResponse(output.getvalue(), content_type='image/gif') - -@csrf_exempt -def post_image(request, post_id): - pi = Post.objects.get(id=post_id).post_image - if not pi: - return HttpResponse('No image found!', status=404) - - # convert base64 data src to image - image = base64.b64decode(pi.split(',')[1]) - return HttpResponse(image, content_type='image/png') diff --git a/templates/blog/post.html b/templates/blog/post.html index f2baf977..96a0f948 100644 --- a/templates/blog/post.html +++ b/templates/blog/post.html @@ -8,7 +8,7 @@
- Cover Image + Cover Image

{{ post.title }}

diff --git a/templates/blog_admin/edit_post.html b/templates/blog_admin/edit_post.html index cd1b0d0e..b80ef118 100644 --- a/templates/blog_admin/edit_post.html +++ b/templates/blog_admin/edit_post.html @@ -13,7 +13,7 @@

{% include 'blog_admin/partials/posts_topbar.html' %}
- Cover Image + Cover Image

@@ -158,7 +158,7 @@ static gettex(latex) { // make a GET request to /tex, returns a png response. render this to image tag - const url = `/iss/tex/?expr="${latex}"`; + const url = `/ignis/tex/?expr="${latex}"`; const img = ``; return img; @@ -182,7 +182,7 @@ static gettex(latex) { // make a POST request to /tex, returns a png response. render this to image tag - const url = `/iss/tex/?expr="${latex}"`; + const url = `/ignis/tex/?expr="${latex}"`; const img = ``; return img; } diff --git a/templates/blog_admin/new_post.html b/templates/blog_admin/new_post.html index 7570d841..9f39e445 100644 --- a/templates/blog_admin/new_post.html +++ b/templates/blog_admin/new_post.html @@ -154,7 +154,7 @@ static gettex(latex) { // make a GET request to /tex, returns a png response. render this to image tag - const url = `/iss/tex/?expr="${latex}"`; + const url = `/ignis/tex/?expr="${latex}"`; const img = ``; return img; @@ -178,7 +178,7 @@ static gettex(latex) { // make a POST request to /tex, returns a png response. render this to image tag - const url = `/iss/tex/?expr="${latex}"`; + const url = `/ignis/tex/?expr="${latex}"`; const img = ``; return img; } diff --git a/thatcomputerscientist/settings.py b/thatcomputerscientist/settings.py index 3e7f9119..aac4a3a0 100644 --- a/thatcomputerscientist/settings.py +++ b/thatcomputerscientist/settings.py @@ -51,7 +51,7 @@ INSTALLED_APPS = [ 'blog_admin', 'dev_status', 'announcements', - 'iss', + 'ignis', ] MIDDLEWARE = [ diff --git a/thatcomputerscientist/urls.py b/thatcomputerscientist/urls.py index abcc5681..7d268bb0 100644 --- a/thatcomputerscientist/urls.py +++ b/thatcomputerscientist/urls.py @@ -24,7 +24,7 @@ urlpatterns = [ path('users/', include('users.urls', namespace='users')), path('blog-admin/', include('blog_admin.urls', namespace='blog-admin')), path('source/', include(('dev_status.urls', 'dev_status'), namespace='dev_status')), - path('iss/', include(('iss.urls', 'iss'), namespace='iss')), + path('ignis/', include(('ignis.urls', 'ignis'), namespace='ignis')), ] urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) -- cgit v1.2.3