mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 12:30:15 +02:00
[ADD] Custom CSS module (First steps)
This commit is contained in:
parent
acff3695bc
commit
59391ad3c5
3
allianceauth/custom_css/__init__.py
Normal file
3
allianceauth/custom_css/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
"""
|
||||
Initializes the custom_css module.
|
||||
"""
|
22
allianceauth/custom_css/admin.py
Normal file
22
allianceauth/custom_css/admin.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""
|
||||
Admin classes for custom_css app
|
||||
"""
|
||||
|
||||
# Alliance Auth Custom CSS
|
||||
from allianceauth.custom_css.models import CustomCSS
|
||||
from allianceauth.custom_css.forms import CustomCSSAdminForm
|
||||
|
||||
# Alliance Auth Framework
|
||||
from allianceauth.framework.admin import SingletonModelAdmin
|
||||
|
||||
# Django
|
||||
from django.contrib import admin
|
||||
|
||||
|
||||
@admin.register(CustomCSS)
|
||||
class CustomCSSAdmin(SingletonModelAdmin):
|
||||
"""
|
||||
Custom CSS Admin
|
||||
"""
|
||||
|
||||
form = CustomCSSAdminForm
|
13
allianceauth/custom_css/apps.py
Normal file
13
allianceauth/custom_css/apps.py
Normal file
@ -0,0 +1,13 @@
|
||||
"""
|
||||
Django app configuration for custom_css
|
||||
"""
|
||||
|
||||
# Django
|
||||
from django.apps import AppConfig
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class CustomCSSConfig(AppConfig):
|
||||
name = "allianceauth.custom_css"
|
||||
label = "custom_css"
|
||||
verbose_name = _("Custom CSS")
|
21
allianceauth/custom_css/forms.py
Normal file
21
allianceauth/custom_css/forms.py
Normal file
@ -0,0 +1,21 @@
|
||||
"""
|
||||
Forms for custom_css app
|
||||
"""
|
||||
|
||||
# Alliance Auth Custom CSS
|
||||
from allianceauth.custom_css.models import CustomCSS
|
||||
from allianceauth.custom_css.widgets import CssEditorWidget
|
||||
|
||||
# Django
|
||||
from django import forms
|
||||
|
||||
|
||||
class CustomCSSAdminForm(forms.ModelForm):
|
||||
"""
|
||||
Form for editing custom CSS
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = CustomCSS
|
||||
fields = ("css",)
|
||||
widgets = {"css": CssEditorWidget(attrs={"style": "width: 90%; height: 100%;"})}
|
33
allianceauth/custom_css/migrations/0001_initial.py
Normal file
33
allianceauth/custom_css/migrations/0001_initial.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Generated by Django 4.2.15 on 2024-08-10 15:53
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="CustomCSS",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("css", models.TextField()),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "Custom CSS",
|
||||
"verbose_name_plural": "Custom CSS",
|
||||
"default_permissions": (),
|
||||
},
|
||||
),
|
||||
]
|
@ -0,0 +1,22 @@
|
||||
# Generated by Django 4.2.15 on 2024-08-10 15:56
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("custom_css", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="customcss",
|
||||
name="css",
|
||||
field=models.TextField(
|
||||
blank=True,
|
||||
help_text="Custom CSS that will be added to the site. This CSS will be added to the site after the default CSS.",
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
]
|
@ -0,0 +1,23 @@
|
||||
# Generated by Django 4.2.15 on 2024-08-10 15:58
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("custom_css", "0002_alter_customcss_css"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="customcss",
|
||||
name="css",
|
||||
field=models.TextField(
|
||||
blank=True,
|
||||
help_text="Custom CSS that will be added to the site. This CSS will be added to the site after the default CSS.",
|
||||
null=True,
|
||||
verbose_name="Your custom CSS",
|
||||
),
|
||||
),
|
||||
]
|
@ -0,0 +1,23 @@
|
||||
# Generated by Django 4.2.15 on 2024-08-10 15:58
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("custom_css", "0003_alter_customcss_css"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="customcss",
|
||||
name="css",
|
||||
field=models.TextField(
|
||||
blank=True,
|
||||
help_text="This CSS will be added to the site after the default CSS.",
|
||||
null=True,
|
||||
verbose_name="Your custom CSS",
|
||||
),
|
||||
),
|
||||
]
|
0
allianceauth/custom_css/migrations/__init__.py
Normal file
0
allianceauth/custom_css/migrations/__init__.py
Normal file
35
allianceauth/custom_css/models.py
Normal file
35
allianceauth/custom_css/models.py
Normal file
@ -0,0 +1,35 @@
|
||||
"""
|
||||
Models for the custom_css app
|
||||
"""
|
||||
|
||||
# Alliance Auth Framework
|
||||
from allianceauth.framework.models import SingletonModel
|
||||
|
||||
# Django
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class CustomCSS(SingletonModel):
|
||||
"""
|
||||
Model for storing custom CSS for the site
|
||||
"""
|
||||
|
||||
css = models.TextField(
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Your custom CSS"),
|
||||
help_text=_("This CSS will be added to the site after the default CSS."),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
"""
|
||||
Meta for CustomCSS
|
||||
"""
|
||||
|
||||
default_permissions = ()
|
||||
verbose_name = _("Custom CSS")
|
||||
verbose_name_plural = _("Custom CSS")
|
||||
|
||||
def __str__(self) -> str:
|
||||
return str(_("Custom CSS"))
|
@ -0,0 +1,16 @@
|
||||
/* global django, hljs */
|
||||
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
const $ = django.jQuery;
|
||||
|
||||
$(document).ready(() => {
|
||||
$('textarea.css-editor').each((idx, el) => {
|
||||
if (typeof hljs !== 'undefined' && typeof hljs.highlightAll === 'function') {
|
||||
console.log('highlighting');
|
||||
hljs.highlightAll();
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
2
allianceauth/custom_css/static/custom_css/javascript/custom-css.min.js
vendored
Normal file
2
allianceauth/custom_css/static/custom_css/javascript/custom-css.min.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
(()=>{const h=django.jQuery;h(document).ready(()=>{h("textarea.css-editor").each((h,e)=>{"undefined"!=typeof hljs&&"function"==typeof hljs.highlightAll&&(console.log("highlighting"),hljs.highlightAll())})})})();
|
||||
//# sourceMappingURL=custom-css.min.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["custom-css.js"],"names":["$","django","jQuery","document","ready","each","idx","el","hljs","highlightAll","console","log"],"mappings":"CAEA,KAGI,MAAMA,EAAIC,OAAOC,OAEjBF,EAAEG,QAAQ,EAAEC,MAAM,KACdJ,EAAE,qBAAqB,EAAEK,KAAK,CAACC,EAAKC,KACZ,aAAhB,OAAOC,MAAqD,YAA7B,OAAOA,KAAKC,eAC3CC,QAAQC,IAAI,cAAc,EAC1BH,KAAKC,aAAa,EAE1B,CAAC,CACL,CAAC,CACJ,GAAE"}
|
1232
allianceauth/custom_css/static/custom_css/libs/highlight.js/11.10.0/highlight.min.js
vendored
Normal file
1232
allianceauth/custom_css/static/custom_css/libs/highlight.js/11.10.0/highlight.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
31
allianceauth/custom_css/static/custom_css/libs/highlight.js/11.10.0/languages/css.min.js
vendored
Normal file
31
allianceauth/custom_css/static/custom_css/libs/highlight.js/11.10.0/languages/css.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
allianceauth/custom_css/static/custom_css/libs/highlight.js/11.10.0/styles/dark.min.css
vendored
Normal file
1
allianceauth/custom_css/static/custom_css/libs/highlight.js/11.10.0/styles/dark.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{color:#ddd;background:#303030}.hljs-keyword,.hljs-link,.hljs-literal,.hljs-section,.hljs-selector-tag{color:#fff}.hljs-addition,.hljs-attribute,.hljs-built_in,.hljs-bullet,.hljs-name,.hljs-string,.hljs-symbol,.hljs-template-tag,.hljs-template-variable,.hljs-title,.hljs-type,.hljs-variable{color:#d88}.hljs-comment,.hljs-deletion,.hljs-meta,.hljs-quote{color:#979797}.hljs-doctag,.hljs-keyword,.hljs-literal,.hljs-name,.hljs-section,.hljs-selector-tag,.hljs-strong,.hljs-title,.hljs-type{font-weight:700}.hljs-emphasis{font-style:italic}
|
9
allianceauth/custom_css/static/custom_css/libs/highlight.js/11.10.0/styles/default.min.css
vendored
Normal file
9
allianceauth/custom_css/static/custom_css/libs/highlight.js/11.10.0/styles/default.min.css
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/*!
|
||||
Theme: Default
|
||||
Description: Original highlight.js style
|
||||
Author: (c) Ivan Sagalaev <maniac@softwaremaniacs.org>
|
||||
Maintainer: @highlightjs/core-team
|
||||
Website: https://highlightjs.org/
|
||||
License: see project LICENSE
|
||||
Touched: 2021
|
||||
*/pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#f3f3f3;color:#444}.hljs-comment{color:#697070}.hljs-punctuation,.hljs-tag{color:#444a}.hljs-tag .hljs-attr,.hljs-tag .hljs-name{color:#444}.hljs-attribute,.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-name,.hljs-selector-tag{font-weight:700}.hljs-deletion,.hljs-number,.hljs-quote,.hljs-selector-class,.hljs-selector-id,.hljs-string,.hljs-template-tag,.hljs-type{color:#800}.hljs-section,.hljs-title{color:#800;font-weight:700}.hljs-link,.hljs-operator,.hljs-regexp,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-symbol,.hljs-template-variable,.hljs-variable{color:#ab5656}.hljs-literal{color:#695}.hljs-addition,.hljs-built_in,.hljs-bullet,.hljs-code{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta .hljs-string{color:#38a}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}
|
10
allianceauth/custom_css/static/custom_css/libs/highlight.js/11.10.0/styles/github-dark.min.css
vendored
Normal file
10
allianceauth/custom_css/static/custom_css/libs/highlight.js/11.10.0/styles/github-dark.min.css
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!
|
||||
Theme: GitHub Dark
|
||||
Description: Dark theme as seen on github.com
|
||||
Author: github.com
|
||||
Maintainer: @Hirse
|
||||
Updated: 2021-05-15
|
||||
|
||||
Outdated base version: https://github.com/primer/github-syntax-dark
|
||||
Current colors taken from GitHub's CSS
|
||||
*/.hljs{color:#c9d1d9;background:#0d1117}.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-template-tag,.hljs-template-variable,.hljs-type,.hljs-variable.language_{color:#ff7b72}.hljs-title,.hljs-title.class_,.hljs-title.class_.inherited__,.hljs-title.function_{color:#d2a8ff}.hljs-attr,.hljs-attribute,.hljs-literal,.hljs-meta,.hljs-number,.hljs-operator,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-variable{color:#79c0ff}.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#a5d6ff}.hljs-built_in,.hljs-symbol{color:#ffa657}.hljs-code,.hljs-comment,.hljs-formula{color:#8b949e}.hljs-name,.hljs-quote,.hljs-selector-pseudo,.hljs-selector-tag{color:#7ee787}.hljs-subst{color:#c9d1d9}.hljs-section{color:#1f6feb;font-weight:700}.hljs-bullet{color:#f2cc60}.hljs-emphasis{color:#c9d1d9;font-style:italic}.hljs-strong{color:#c9d1d9;font-weight:700}.hljs-addition{color:#aff5b4;background-color:#033a16}.hljs-deletion{color:#ffdcd7;background-color:#67060c}
|
10
allianceauth/custom_css/static/custom_css/libs/highlight.js/11.10.0/styles/github.min.css
vendored
Normal file
10
allianceauth/custom_css/static/custom_css/libs/highlight.js/11.10.0/styles/github.min.css
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!
|
||||
Theme: GitHub
|
||||
Description: Light theme as seen on github.com
|
||||
Author: github.com
|
||||
Maintainer: @Hirse
|
||||
Updated: 2021-05-15
|
||||
|
||||
Outdated base version: https://github.com/primer/github-syntax-light
|
||||
Current colors taken from GitHub's CSS
|
||||
*/.hljs{color:#24292e;background:#fff}.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-template-tag,.hljs-template-variable,.hljs-type,.hljs-variable.language_{color:#d73a49}.hljs-title,.hljs-title.class_,.hljs-title.class_.inherited__,.hljs-title.function_{color:#6f42c1}.hljs-attr,.hljs-attribute,.hljs-literal,.hljs-meta,.hljs-number,.hljs-operator,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-variable{color:#005cc5}.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#032f62}.hljs-built_in,.hljs-symbol{color:#e36209}.hljs-code,.hljs-comment,.hljs-formula{color:#6a737d}.hljs-name,.hljs-quote,.hljs-selector-pseudo,.hljs-selector-tag{color:#22863a}.hljs-subst{color:#24292e}.hljs-section{color:#005cc5;font-weight:700}.hljs-bullet{color:#735c0f}.hljs-emphasis{color:#24292e;font-style:italic}.hljs-strong{color:#24292e;font-weight:700}.hljs-addition{color:#22863a;background-color:#f0fff4}.hljs-deletion{color:#b31d28;background-color:#ffeef0}
|
35
allianceauth/custom_css/widgets.py
Normal file
35
allianceauth/custom_css/widgets.py
Normal file
@ -0,0 +1,35 @@
|
||||
"""
|
||||
Form widgets for custom_css app
|
||||
"""
|
||||
|
||||
# Django
|
||||
from django import forms
|
||||
|
||||
# Alliance Auth
|
||||
from allianceauth.custom_css.models import CustomCSS
|
||||
|
||||
|
||||
class CssEditorWidget(forms.Textarea):
|
||||
"""
|
||||
Widget for editing CSS
|
||||
"""
|
||||
|
||||
def __init__(self, attrs=None):
|
||||
default_attrs = {"class": "css-editor"}
|
||||
|
||||
if attrs:
|
||||
default_attrs.update(attrs)
|
||||
|
||||
super().__init__(default_attrs)
|
||||
|
||||
class Media:
|
||||
css = {
|
||||
"all": (
|
||||
"/static/custom_css/libs/highlight.js/11.10.0/styles/github.min.css",
|
||||
)
|
||||
}
|
||||
js = (
|
||||
"/static/custom_css/libs/highlight.js/11.10.0/highlight.min.js",
|
||||
"/static/custom_css/libs/highlight.js/11.10.0/languages/css.min.js",
|
||||
"/static/custom_css/javascript/custom-css.min.js",
|
||||
)
|
58
allianceauth/framework/admin.py
Normal file
58
allianceauth/framework/admin.py
Normal file
@ -0,0 +1,58 @@
|
||||
"""
|
||||
Admin classes for the framework app
|
||||
"""
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
|
||||
class SingletonModelAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Singleton Model Admin
|
||||
Prevents Django admin users deleting the singleton or adding extra rows.
|
||||
"""
|
||||
|
||||
actions = None # Removes the default delete action.
|
||||
|
||||
def has_add_permission(self, request): # pylint: disable=unused-argument
|
||||
"""
|
||||
Has "add" permissions
|
||||
|
||||
:param request:
|
||||
:type request:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
return self.model.objects.all().count() == 0
|
||||
|
||||
def has_change_permission(
|
||||
self, request, obj=None # pylint: disable=unused-argument
|
||||
):
|
||||
"""
|
||||
Has "change" permissions
|
||||
|
||||
:param request:
|
||||
:type request:
|
||||
:param obj:
|
||||
:type obj:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
return True
|
||||
|
||||
def has_delete_permission(
|
||||
self, request, obj=None # pylint: disable=unused-argument
|
||||
):
|
||||
"""
|
||||
Has "delete" permissions
|
||||
|
||||
:param request:
|
||||
:type request:
|
||||
:param obj:
|
||||
:type obj:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
return False
|
47
allianceauth/framework/models.py
Normal file
47
allianceauth/framework/models.py
Normal file
@ -0,0 +1,47 @@
|
||||
"""
|
||||
AA framework models
|
||||
"""
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
||||
class SingletonModel(models.Model):
|
||||
"""
|
||||
SingletonModel
|
||||
"""
|
||||
|
||||
class Meta: # pylint: disable=too-few-public-methods
|
||||
"""
|
||||
Model meta definitions
|
||||
"""
|
||||
|
||||
abstract = True
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""
|
||||
"Save" action
|
||||
|
||||
:param args:
|
||||
:type args:
|
||||
:param kwargs:
|
||||
:type kwargs:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
self.pk = 1
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
"""
|
||||
"Delete" action
|
||||
|
||||
:param args:
|
||||
:type args:
|
||||
:param kwargs:
|
||||
:type kwargs:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
pass # pylint: disable=unnecessary-pass
|
Loading…
x
Reference in New Issue
Block a user