formatting
This commit is contained in:
parent
f8c3577a54
commit
6d9660f44c
|
@ -11,6 +11,8 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# for getting envvars
|
# for getting envvars
|
||||||
|
import logging
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# default django
|
# default django
|
||||||
|
@ -100,7 +102,6 @@ DATABASES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
|
@ -123,7 +124,6 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
LANGUAGES = [
|
LANGUAGES = [
|
||||||
("de", _("German")),
|
("de", _("German")),
|
||||||
|
@ -173,7 +173,6 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
# Logging configs
|
# Logging configs
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
myServerFormatter = ServerFormatter
|
myServerFormatter = ServerFormatter
|
||||||
myServerFormatter.default_time_format = "%Y-%M-%d %H:%M:%S"
|
myServerFormatter.default_time_format = "%Y-%M-%d %H:%M:%S"
|
||||||
|
|
|
@ -10,6 +10,7 @@ def regenerate(modeladmin, request, queryset):
|
||||||
for obj in queryset:
|
for obj in queryset:
|
||||||
obj.regenerate()
|
obj.regenerate()
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Keyword)
|
@admin.register(Keyword)
|
||||||
class KeywordAdmin(admin.ModelAdmin):
|
class KeywordAdmin(admin.ModelAdmin):
|
||||||
"""
|
"""
|
||||||
|
@ -17,21 +18,25 @@ class KeywordAdmin(admin.ModelAdmin):
|
||||||
"""
|
"""
|
||||||
list_display = ["text_en", "text_de"]
|
list_display = ["text_en", "text_de"]
|
||||||
|
|
||||||
|
|
||||||
@admin.register(StaticSite)
|
@admin.register(StaticSite)
|
||||||
class StaticSiteAdmin(admin.ModelAdmin):
|
class StaticSiteAdmin(admin.ModelAdmin):
|
||||||
"""
|
"""
|
||||||
Admin Interface for StaticSite
|
Admin Interface for StaticSite
|
||||||
"""
|
"""
|
||||||
list_display = ["title_en", "subtitle_en", "title_de", "subtitle_de", "suburl"]
|
list_display = ["title_en", "subtitle_en",
|
||||||
|
"title_de", "subtitle_de", "suburl"]
|
||||||
ordering = ['title_de', 'title_en']
|
ordering = ['title_de', 'title_en']
|
||||||
actions = [regenerate]
|
actions = [regenerate]
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Searchable)
|
@admin.register(Searchable)
|
||||||
class SearchableAdmin(admin.ModelAdmin):
|
class SearchableAdmin(admin.ModelAdmin):
|
||||||
"""
|
"""
|
||||||
Abstract Admin Interface for all Searchables
|
Abstract Admin Interface for all Searchables
|
||||||
"""
|
"""
|
||||||
list_display = ["title_en", "subtitle_en", "title_de", "subtitle_de", "suburl"]
|
list_display = ["title_en", "subtitle_en",
|
||||||
|
"title_de", "subtitle_de", "suburl"]
|
||||||
ordering = ['title_de', 'title_en']
|
ordering = ['title_de', 'title_en']
|
||||||
actions = [regenerate]
|
actions = [regenerate]
|
||||||
|
|
||||||
|
@ -41,6 +46,7 @@ class LinkAdmin(admin.ModelAdmin):
|
||||||
"""
|
"""
|
||||||
Admin Interface for Links
|
Admin Interface for Links
|
||||||
"""
|
"""
|
||||||
list_display = ["title_en", "title_de", "url", "suburl", "favicon", "status", "personal"]
|
list_display = ["title_en", "title_de", "url",
|
||||||
|
"suburl", "favicon", "status", "personal"]
|
||||||
ordering = ['status', 'title_de', 'title_en']
|
ordering = ['status', 'title_de', 'title_en']
|
||||||
actions = [regenerate]
|
actions = [regenerate]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
class StartConfig(AppConfig):
|
class StartConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
name = 'start'
|
name = 'start'
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
|
||||||
class MainSearchForm(forms.Form):
|
class MainSearchForm(forms.Form):
|
||||||
search = forms.CharField(
|
search = forms.CharField(
|
||||||
max_length=100,
|
max_length=100,
|
||||||
|
|
|
@ -15,7 +15,8 @@ class LangBasedOnUrlMiddleware(MiddlewareMixin):
|
||||||
def process_request(request):
|
def process_request(request):
|
||||||
|
|
||||||
if hasattr(request, 'session'):
|
if hasattr(request, 'session'):
|
||||||
active_session_lang = request.session.get(translation.LANGUAGE_SESSION_KEY)
|
active_session_lang = request.session.get(
|
||||||
|
translation.LANGUAGE_SESSION_KEY)
|
||||||
|
|
||||||
if active_session_lang == request.LANGUAGE_CODE:
|
if active_session_lang == request.LANGUAGE_CODE:
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import random
|
||||||
|
import favicon
|
||||||
|
import requests
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.options import override
|
from django.db.models.options import override
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
@ -8,9 +11,6 @@ from django.conf import settings
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
import requests
|
|
||||||
import favicon
|
|
||||||
import random
|
|
||||||
|
|
||||||
class Keyword(models.Model):
|
class Keyword(models.Model):
|
||||||
"""
|
"""
|
||||||
|
@ -26,6 +26,7 @@ class Keyword(models.Model):
|
||||||
verbose_name = _("Keyword")
|
verbose_name = _("Keyword")
|
||||||
verbose_name_plural = _("keywords")
|
verbose_name_plural = _("keywords")
|
||||||
|
|
||||||
|
|
||||||
class Searchable(models.Model):
|
class Searchable(models.Model):
|
||||||
"""
|
"""
|
||||||
Abstract class for any model that should be searchable.
|
Abstract class for any model that should be searchable.
|
||||||
|
@ -37,8 +38,10 @@ class Searchable(models.Model):
|
||||||
title_en = models.CharField(max_length=50, default="title EN")
|
title_en = models.CharField(max_length=50, default="title EN")
|
||||||
subtitle_de = models.CharField(max_length=50, blank=True)
|
subtitle_de = models.CharField(max_length=50, blank=True)
|
||||||
subtitle_en = models.CharField(max_length=50, blank=True)
|
subtitle_en = models.CharField(max_length=50, blank=True)
|
||||||
desc_de = models.TextField(blank=True, max_length=250, unique=False, default="Beschreibung DE")
|
desc_de = models.TextField(
|
||||||
desc_en = models.TextField(blank=True, max_length=250, unique=False, default="Description EN")
|
blank=True, max_length=250, unique=False, default="Beschreibung DE")
|
||||||
|
desc_en = models.TextField(
|
||||||
|
blank=True, max_length=250, unique=False, default="Description EN")
|
||||||
# may be empty/blank for some entries
|
# may be empty/blank for some entries
|
||||||
date = models.DateField(blank=True, null=True)
|
date = models.DateField(blank=True, null=True)
|
||||||
keywords = models.ManyToManyField(Keyword)
|
keywords = models.ManyToManyField(Keyword)
|
||||||
|
@ -61,12 +64,14 @@ class Searchable(models.Model):
|
||||||
"""
|
"""
|
||||||
regenerate a object
|
regenerate a object
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError(f"{self.__class__.__name__} does not implement regenerate")
|
raise NotImplementedError(
|
||||||
|
f"{self.__class__.__name__} does not implement regenerate")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("Searchable")
|
verbose_name = _("Searchable")
|
||||||
verbose_name_plural = _("Searchables")
|
verbose_name_plural = _("Searchables")
|
||||||
|
|
||||||
|
|
||||||
class StaticSite(Searchable):
|
class StaticSite(Searchable):
|
||||||
"""
|
"""
|
||||||
This model represents any static site, such as start:index,
|
This model represents any static site, such as start:index,
|
||||||
|
@ -89,6 +94,7 @@ class StaticSite(Searchable):
|
||||||
verbose_name = _("static site")
|
verbose_name = _("static site")
|
||||||
verbose_name_plural = _("static sites")
|
verbose_name_plural = _("static sites")
|
||||||
|
|
||||||
|
|
||||||
class Link(Searchable):
|
class Link(Searchable):
|
||||||
"""
|
"""
|
||||||
contains all my interesting links
|
contains all my interesting links
|
||||||
|
@ -121,11 +127,13 @@ class Link(Searchable):
|
||||||
icons = favicon.get(self.url, timeout=2)
|
icons = favicon.get(self.url, timeout=2)
|
||||||
except (ConnectionError) as ce:
|
except (ConnectionError) as ce:
|
||||||
# just keep whatever was stored if we cant get a new favicon
|
# just keep whatever was stored if we cant get a new favicon
|
||||||
logger.warn(f"unable to download favicon for {self}: {ce.with_traceback(None)}")
|
logger.warn(
|
||||||
|
f"unable to download favicon for {self}: {ce.with_traceback(None)}")
|
||||||
self.status = False
|
self.status = False
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn(f"Unexpected Exception while downloading {self}: {e.with_traceback(None)}")
|
logger.warn(
|
||||||
|
f"Unexpected Exception while downloading {self}: {e.with_traceback(None)}")
|
||||||
self.status = False
|
self.status = False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -146,7 +154,8 @@ class Link(Searchable):
|
||||||
self.favicon = None
|
self.favicon = None
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn(f"Unexpected Exception while downloading {self}: {e.with_traceback(None)}")
|
logger.warn(
|
||||||
|
f"Unexpected Exception while downloading {self}: {e.with_traceback(None)}")
|
||||||
self.favicon = None
|
self.favicon = None
|
||||||
|
|
||||||
self.save()
|
self.save()
|
||||||
|
|
|
@ -36,4 +36,3 @@ def change_lang(context, lang="de", *args, **kwargs):
|
||||||
finally:
|
finally:
|
||||||
activate(lang)
|
activate(lang)
|
||||||
return "%s" % url
|
return "%s" % url
|
||||||
|
|
||||||
|
|
|
@ -9,5 +9,6 @@ urlpatterns = [
|
||||||
path("legal/", views.LegalInfo.as_view(), name="legal"),
|
path("legal/", views.LegalInfo.as_view(), name="legal"),
|
||||||
path("links/", views.Links.as_view(), name="links"),
|
path("links/", views.Links.as_view(), name="links"),
|
||||||
path("professional/", views.LegalInfo.as_view(), name="professional"),
|
path("professional/", views.LegalInfo.as_view(), name="professional"),
|
||||||
path('language/activate/<language_code>/', views.ActivateLanguage.as_view(), name='activate_language'),
|
path('language/activate/<language_code>/',
|
||||||
|
views.ActivateLanguage.as_view(), name='activate_language'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -18,6 +18,7 @@ from abc import ABC
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SearchableView(View, ABC):
|
class SearchableView(View, ABC):
|
||||||
"""
|
"""
|
||||||
This abstract view implements some traits of views that should show up
|
This abstract view implements some traits of views that should show up
|
||||||
|
@ -40,6 +41,7 @@ class Index(TemplateView, SearchableView):
|
||||||
|
|
||||||
template_name: str = "start/index.html"
|
template_name: str = "start/index.html"
|
||||||
|
|
||||||
|
|
||||||
class Professional(TemplateView, SearchableView):
|
class Professional(TemplateView, SearchableView):
|
||||||
"""
|
"""
|
||||||
Professional informations that might interest a professional employer
|
Professional informations that might interest a professional employer
|
||||||
|
@ -47,6 +49,7 @@ class Professional(TemplateView, SearchableView):
|
||||||
# TODO
|
# TODO
|
||||||
template_name: str = "start/legalinfo.html"
|
template_name: str = "start/legalinfo.html"
|
||||||
|
|
||||||
|
|
||||||
class LegalInfo(TemplateView, SearchableView):
|
class LegalInfo(TemplateView, SearchableView):
|
||||||
"""
|
"""
|
||||||
Legal info that the german authorities want.
|
Legal info that the german authorities want.
|
||||||
|
@ -54,6 +57,7 @@ class LegalInfo(TemplateView, SearchableView):
|
||||||
# TODO
|
# TODO
|
||||||
template_name: str = "start/legalinfo.html"
|
template_name: str = "start/legalinfo.html"
|
||||||
|
|
||||||
|
|
||||||
class ActivateLanguage(View):
|
class ActivateLanguage(View):
|
||||||
"""
|
"""
|
||||||
Set the language to whatever
|
Set the language to whatever
|
||||||
|
@ -68,6 +72,7 @@ class ActivateLanguage(View):
|
||||||
request.session[translation.LANGUAGE_SESSION_KEY] = self.language_code
|
request.session[translation.LANGUAGE_SESSION_KEY] = self.language_code
|
||||||
return redirect(self.redirect_to)
|
return redirect(self.redirect_to)
|
||||||
|
|
||||||
|
|
||||||
class MainSearch(ListView):
|
class MainSearch(ListView):
|
||||||
"""
|
"""
|
||||||
Search for anything.
|
Search for anything.
|
||||||
|
@ -94,6 +99,7 @@ class MainSearch(ListView):
|
||||||
return render(request, "errors/bad_request.html")
|
return render(request, "errors/bad_request.html")
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Links(ListView):
|
class Links(ListView):
|
||||||
"""
|
"""
|
||||||
This View contains links to various interesting sites.
|
This View contains links to various interesting sites.
|
||||||
|
|
Loading…
Reference in New Issue