Skip to content
Snippets Groups Projects
Commit d5a4dd2d authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Fix some bugs with too early imports

parent 50e0508d
No related branches found
No related tags found
1 merge request!86Merge school-apps
# Generated by Django 2.2.6 on 2019-11-18 18:39
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0005_cache_needed_until'),
('dashboard', '0002_notification_read'),
]
operations = [
]
from django.db import ProgrammingError
from django.urls import path
from untisconnect.models import Terms, Schoolyear
try:
from . import views
import dashboard.views.dashboard as views
urlpatterns = [
path('', views.index, name='dashboard'),
......@@ -12,7 +13,7 @@ try:
path('api/my-plan', views.api_my_plan_html, name="api_my_plan_html"),
]
except (Terms.DoesNotExist, Schoolyear.DoesNotExist):
except (Terms.DoesNotExist, Schoolyear.DoesNotExist, ProgrammingError):
from timetable import fallback_view
urlpatterns = [
......@@ -22,8 +23,10 @@ except (Terms.DoesNotExist, Schoolyear.DoesNotExist):
path('api/my-plan', fallback_view.fallback, name="api_my_plan_html"),
]
import dashboard.views.tools as tools_views
urlpatterns += [
path("tools", views.tools, name="tools"),
path("tools/clear-cache", views.tools_clear_cache, name="tools_clear_cache"),
path("tools/clear-cache/<str:id>", views.tools_clear_cache, name="tools_clear_single_cache"),
]
\ No newline at end of file
path("tools", tools_views.tools, name="tools"),
path("tools/clear-cache", tools_views.tools_clear_cache, name="tools_clear_cache"),
path("tools/clear-cache/<str:id>", tools_views.tools_clear_cache, name="tools_clear_single_cache"),
]
from email.utils import formatdate
from django.contrib.auth.decorators import login_required, user_passes_test
from django.core.cache import cache
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from django.shortcuts import render, redirect
from django.shortcuts import render
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils import timezone
from martor.templatetags.martortags import safe_markdown
from dashboard.models import Activity, Notification
from dashboard.settings import latest_article_settings, current_events_settings
from helper import get_newest_article_from_news, get_current_events_with_cal
from timetable.hints import get_all_hints_by_class_and_time_period, get_all_hints_for_teachers_by_time_period
from timetable.views import get_next_weekday_with_time
from untisconnect.api import TYPE_TEACHER, TYPE_CLASS
from untisconnect.datetimeutils import get_name_for_next_week_day_from_today
from untisconnect.utils import get_type_and_object_of_user, get_plan_for_day
from .models import Activity, Notification
from .models import Cache
from utils.network import get_newest_article_from_news, get_current_events_with_cal
@login_required
......@@ -143,38 +140,3 @@ def api_my_plan_html(request):
# Return JSON
return JsonResponse(
{"success": True, "lessons": lessons, "holiday": holiday[0].__dict__ if len(holiday) > 0 else None})
@login_required
@user_passes_test(lambda u: u.is_superuser)
def tools(request):
msg = None
if request.session.get("msg", False):
msg = request.session["msg"]
request.session["msg"] = None
caches = Cache.objects.all()
context = {
"msg": msg,
"caches": caches
}
return render(request, "dashboard/tools.html", context)
@login_required
def tools_clear_cache(request, id=None):
if id is not None:
cache.delete(id)
request.session["msg"] = "success_cleared_single_cache"
print("[IMPORTANT] Single cache cleared!")
else:
cache.clear()
request.session["msg"] = "success_cleared_whole_cache"
print("[IMPORTANT] Whole cache cleared!")
return redirect(reverse("tools"))
def error_404(request, exception):
""" 404 page """
return render(request, 'common/404.html')
from django.contrib.auth.decorators import login_required, user_passes_test
from django.core.cache import cache
from django.shortcuts import render, redirect
from django.urls import reverse
from dashboard.models import Cache
@login_required
@user_passes_test(lambda u: u.is_superuser)
def tools(request):
msg = None
if request.session.get("msg", False):
msg = request.session["msg"]
request.session["msg"] = None
caches = Cache.objects.all()
context = {
"msg": msg,
"caches": caches
}
return render(request, "dashboard/tools.html", context)
@login_required
def tools_clear_cache(request, id=None):
if id is not None:
cache.delete(id)
request.session["msg"] = "success_cleared_single_cache"
print("[IMPORTANT] Single cache cleared!")
else:
cache.clear()
request.session["msg"] = "success_cleared_whole_cache"
print("[IMPORTANT] Whole cache cleared!")
return redirect(reverse("tools"))
# Generated by Django 2.2.1 on 2019-05-29 15:05
from django.db import migrations, models
import helper
import utils.helper as helper
class Migration(migrations.Migration):
......
from django.db import models
# Create your models here.
from helper import path_and_rename
from utils.helper import path_and_rename
class Menu(models.Model):
......
......@@ -33,7 +33,8 @@ def manifest(request):
def serviceworker(request):
return serve(request, "common/pwabuilder-sw.js")
handler404 = 'dashboard.views.error_404'
# handler404 = 'dashboard.views.error_404'
def custom_page_not_found(request):
return defaults.page_not_found(request, None, "common/404.html")
......@@ -94,4 +95,3 @@ urlpatterns = [
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# Generated by Django 2.2.6 on 2019-11-18 18:39
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('timetable', '0011_merge_20191113_1655'),
('timetable', '0010_auto_20190901_1040'),
]
operations = [
]
import os
from uuid import uuid4
from django.template.loader_tags import register
def path_and_rename(instance, filename):
upload_to = 'menus'
ext = filename.split('.')[-1].lower()
# get filename
if instance.pk:
filename = '{}.{}'.format(instance.pk, ext)
else:
# set filename as random string
filename = '{}.{}'.format(uuid4().hex, ext)
# return the whole path to the file
return os.path.join(upload_to, filename)
@register.inclusion_tag("components/msgbox.html")
def msg_box(msg, status="success", icon="info"):
return {"msg": msg, "status": status, "icon": icon}
import os
import re
from uuid import uuid4
from django.template.loader_tags import register
import requests
from django.utils import timezone, formats
from ics import Calendar
import requests
from requests import RequestException
from dashboard import settings
from dashboard.caches import LATEST_ARTICLE_CACHE, CURRENT_EVENTS_CACHE
def path_and_rename(instance, filename):
upload_to = 'menus'
ext = filename.split('.')[-1].lower()
# get filename
if instance.pk:
filename = '{}.{}'.format(instance.pk, ext)
else:
# set filename as random string
filename = '{}.{}'.format(uuid4().hex, ext)
# return the whole path to the file
return os.path.join(upload_to, filename)
@register.inclusion_tag("components/msgbox.html")
def msg_box(msg, status="success", icon="info"):
return {"msg": msg, "status": status, "icon": icon}
WP_DOMAIN: str = "https://katharineum-zu-luebeck.de"
VS_COMPOSER_REGEX = re.compile(r"\[[\w\s\d!\"§$%&/()=?#'+*~’¸´`;,·.:…\-_–]*\]")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment