This commit is contained in:
Izalia Mae 2021-09-12 04:11:45 -04:00
parent 5efee0ffd2
commit c2796a5075
11 changed files with 89 additions and 54 deletions

View file

@ -0,0 +1,15 @@
from . import view
class ActivityPub:
def __init__(self, app):
self.app = app
self.cfg = app.cfg
def setup_views(self):
self.app.add_class_route(view.Actor)
self.app.add_class_route(view.Nodeinfo)
self.app.add_class_route(view.Webfinger)
self.app.add_class_route(view.WkHostMeta)
self.app.add_class_route(view.WkNodeinfo)

View file

@ -30,7 +30,7 @@ class GenericError:
traceback.print_exc() traceback.print_exc()
try: try:
return response.error(msg, status) return response.error(msg, status, pprint=True)
except Exception as e: except Exception as e:
traceback.print_exc() traceback.print_exc()

View file

@ -43,6 +43,7 @@ input:not([type='checkbox']), select, textarea {
background-color: var(--background); background-color: var(--background);
border: 1px solid var(--background); border: 1px solid var(--background);
box-shadow: 0 2px 2px 0 var(--shadow-color); box-shadow: 0 2px 2px 0 var(--shadow-color);
padding: 5px;
} }
input:hover, select:hover, textarea:hover { input:hover, select:hover, textarea:hover {
@ -195,9 +196,9 @@ details:focus, summary:focus {
#content-body .title { #content-body .title {
text-align: center; text-align: center;
font-size: 1.5em; font-size: 2em;
font-weight: bold; font-weight: bold;
color: var(--primary) color: var(--primary);
} }
#footer { #footer {
@ -226,32 +227,16 @@ details:focus, summary:focus {
white-space: nowrap; white-space: nowrap;
} }
{% for name in cssfiles %} #logreg input, textarea {
{% include 'style/' + name + '.css' %} display: block;
{% endfor %} margin: 8px auto;
/* responsive design */
@media (max-width: 810px) {
body {
margin: 0;
}
#body {
width: auto;
}
} }
@media (max-width: 610px) { #logreg textarea, input:not([type='submit']) {
.settings .grid-container { width: 50%;
grid-template-columns: auto;
}
.settings .label {
text-align: center;
}
} }
/* Main menu */ /* Main menu */
#btn { #btn {
cursor: pointer; cursor: pointer;
@ -277,7 +262,7 @@ details:focus, summary:focus {
position: fixed; position: fixed;
z-index: 5; z-index: 5;
top: 12px; top: 12px;
{% if menu_left %}right: calc(100% - 250px + 12px){% else %}right: 12px;{% endif %}; {% if menu_left %}right: calc(100% - 250px + 12px){% else %}right: 12px{% endif %};
background-color: {{primary.darken(75)}}; background-color: {{primary.darken(75)}};
color: {{background}}; color: {{background}};
} }
@ -386,14 +371,45 @@ details:focus, summary:focus {
@keyframes fadeInDown { @keyframes fadeInDown {
0% { 0% {
opacity: 0; opacity: 0;
transform: translateY(-1.25em); transform: translateY(-1.25em);
} }
100% { 100% {
opacity: 1; opacity: 1;
transform: translateY(0); transform: translateY(0);
} }
}
{% for name in cssfiles %}
{% include 'style/' + name + '.css' %}
{% endfor %}
/* responsive design */
@media (max-width: 810px) {
body {
margin: 0;
}
#body {
width: auto;
}
}
@media (max-width: 610px) {
.settings .grid-container {
grid-template-columns: auto;
}
.settings .label {
text-align: center;
}
#logreg textarea, input:not([type='submit']) {
width: calc(100% - 16px);
}
} }

View file

@ -2,10 +2,10 @@
%html %html
%head %head
%title << {{cfg.name}}: {{page}} %title << {{cfg.name}}: {{page}}
%link rel='stylesheet' type='text/css' href='/framework/style.css' %link(rel='stylesheet' type='text/css' href='/framework/style.css')
%link rel='manifest' href='/framework/manifest.json' %link(rel='manifest' href='/framework/manifest.json')
%meta charset='UTF-8' %meta(charset='UTF-8')
%meta name='viewport' content='width=device-width, initial-scale=1' %meta(name='viewport' content='width=device-width, initial-scale=1')
-block head -block head
%body %body
@ -13,10 +13,10 @@
#header.flex-container #header.flex-container
-if menu_left -if menu_left
#btn.section #btn.section
.page-title.section -> %a.title href='/' << {{cfg.name}} .page-title.section -> %a.title(href='/') << {{cfg.name}}
-else -else
.page-title.section -> %a.title href='/' << {{cfg.name}} .page-title.section -> %a.title(href='/') << {{cfg.name}}
#btn.section #btn.section
-if message -if message
@ -34,9 +34,9 @@
-else: -else:
-for label, path_data in cfg.menu.items() -for label, path_data in cfg.menu.items()
-if path_data[1] == 1000 and request.user_level == 0: -if path_data[1] == 1000 and request.user_level == 0:
.item -> %a href='{{path_data[0]}}' << {{label}} .item -> %a(href='{{path_data[0]}}') << {{label}}
-elif request.user_level >= path_data[1] -elif request.user_level >= path_data[1]
.item -> %a href='{{path_data[0]}}' << {{label}} .item -> %a(href='{{path_data[0]}}') << {{label}}
#content-body.section #content-body.section
-block content -block content
@ -45,6 +45,6 @@
.avatar .avatar
.user .user
.source .source
%a href='{{cfg.git_repo}}' target='_new' << {{cfg.name}}/{{cfg.version}} %a(href='{{cfg.git_repo}}' target='_new') << {{cfg.name}}/{{cfg.version}}
%script type='application/javascript' src='/framework/static/menu.js' %script(type='application/javascript' src='/framework/static/menu.js')

View file

@ -1 +1 @@
.item => %a(href='/') << Home .item -> %a(href='/') << Home

View file

@ -6,7 +6,7 @@ from .misc import Headers
class Request(sanic.request.Request): class Request(sanic.request.Request):
def __init__(self, url_bytes, headers, version, method, transport, app, **kwargs): def __init__(self, url_bytes, headers, version, method, transport, app):
super().__init__(url_bytes, headers, version, method, transport, app) super().__init__(url_bytes, headers, version, method, transport, app)
self.Headers = Headers(headers) self.Headers = Headers(headers)

View file

@ -5,6 +5,7 @@ from izzylib import DotDict, izzylog
from izzylib.template import Color from izzylib.template import Color
from sanic.compat import Header from sanic.compat import Header
from sanic.cookies import CookieJar from sanic.cookies import CookieJar
from sanic.response import text as Raw
class Response: class Response:
@ -171,6 +172,7 @@ class Response:
def error(self, message, status=500, **kwargs): def error(self, message, status=500, **kwargs):
if self.request and 'json' in self.request.headers.get('accept', ''): if self.request and 'json' in self.request.headers.get('accept', ''):
kwargs.pop('pprint', None)
return self.json({f'error {status}': message}, status=status, **kwargs) return self.json({f'error {status}': message}, status=status, **kwargs)
return self.template('error.haml', {'error_message': message}, status=status, **kwargs) return self.template('error.haml', {'error_message': message}, status=status, **kwargs)
@ -224,7 +226,7 @@ class Response:
def get_response(self, *args, **kwargs): def get_response(self, *args, **kwargs):
self.set_data(*args, **kwargs) self.set_data(*args, **kwargs)
response = sanic.response.HTTPResponse(self.body, self.status, self.headers, self.content_type) response = sanic.response.raw(self.body, self.status, self.headers, self.content_type)
response._cookies = self.cookies response._cookies = self.cookies
return response return response

View file

@ -62,7 +62,8 @@ class Style(View):
paths = ['/framework/style.css'] paths = ['/framework/style.css']
async def get(self, request, response): async def get(self, request, response):
return response.template('base.css', content_type='text/css') resp = response.template('base.css', content_type='text/css')
return resp
### ActivityPub Views ### ### ActivityPub Views ###

View file

@ -2,5 +2,5 @@
from .generic import SqlColumn, CustomRows, SqlSession, SqlDatabase, Tables, OperationalError, ProgrammingError from .generic import SqlColumn, CustomRows, SqlSession, SqlDatabase, Tables, OperationalError, ProgrammingError
from .sqlite_server import SqliteClient, SqliteColumn, SqliteServer, SqliteSession from .sqlite_server import SqliteClient, SqliteColumn, SqliteServer, SqliteSession
from .database import Database, Session #from .database import Database, Session
from .queries import Column, Insert, Select, Table, Tables, Update #from .queries import Column, Insert, Select, Table, Tables, Update

View file

@ -46,10 +46,7 @@ class SqlDatabase:
engine_string = dbtype + '://' engine_string = dbtype + '://'
if dbtype == 'sqlite': if dbtype == 'sqlite':
try: database = kwargs['name']
database = kwargs['name']
except KeyError:
database = kwargs['database']
if nfs_check(database): if nfs_check(database):
izzylog.error('Database file is on an NFS share which does not support locking. Any writes to the database will fail') izzylog.error('Database file is on an NFS share which does not support locking. Any writes to the database will fail')

View file

@ -129,6 +129,10 @@ class Template(Environment):
except TypeError: except TypeError:
context = self.func_context(context, {}) context = self.func_context(context, {})
if context == None:
izzylog.warning('Template context was set to "None"')
context = {}
result = self.get_template(tplfile).render(context) result = self.get_template(tplfile).render(context)
if pprint and any(map(tplfile.endswith, ['haml', 'html', 'xml'])): if pprint and any(map(tplfile.endswith, ['haml', 'html', 'xml'])):