From a3e9dd23b41ee6aea5fb95101db8bd78fa9cf11c Mon Sep 17 00:00:00 2001 From: ilearnit Date: Sun, 8 Apr 2018 14:11:13 +0800 Subject: [PATCH] custom css --- media/css/seahub.css | 14 +++++++++++++- seahub/base/context_processors.py | 4 ++-- seahub/settings.py | 7 +++++-- seahub/templates/base.html | 2 +- seahub/templates/base_for_backbone.html | 2 +- seahub/templates/snippets/web_settings_form.html | 15 +++++++++++++++ seahub/templates/sysadmin/settings.html | 15 +++++++++++++-- seahub/templates/sysadmin/sysadmin_backbone.html | 2 +- seahub/urls.py | 1 + seahub/views/__init__.py | 5 +++++ seahub/views/sysadmin.py | 5 +++-- 11 files changed, 60 insertions(+), 12 deletions(-) diff --git a/media/css/seahub.css b/media/css/seahub.css index aafbb833f3..e17d6db9f1 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -3814,7 +3814,8 @@ img.thumbnail { } .web-setting-name, .web-setting-input, -.web-setting-ops { +.web-setting-ops, +.web-setting-ops-x1 { display:inline-block; } .web-setting-name { @@ -3836,10 +3837,21 @@ img.thumbnail { height:95px; margin:0; } +.web-setting-input .textarea-x1 { + width:inherit; + height:247px; +} .web-setting-ops { width:100px; vertical-align:top; } +.web-setting-ops-x1 { + vertical-align: bottom; + height: 50px; +} +.web-setting-ops-x1 .submit { + margin-left: 30px; +} .web-setting-form .submit, .web-setting-input { margin-top:0; diff --git a/seahub/base/context_processors.py b/seahub/base/context_processors.py index 842aa74b77..bc29732d74 100644 --- a/seahub/base/context_processors.py +++ b/seahub/base/context_processors.py @@ -16,7 +16,7 @@ from django.utils.functional import lazy from constance import config from seahub.settings import SEAFILE_VERSION, SITE_TITLE, SITE_NAME, \ - MAX_FILE_NAME, BRANDING_CSS, LOGO_PATH, LOGO_WIDTH, LOGO_HEIGHT,\ + MAX_FILE_NAME, LOGO_PATH, LOGO_WIDTH, LOGO_HEIGHT,\ SHOW_REPO_DOWNLOAD_BUTTON, SITE_ROOT, ENABLE_GUEST_INVITATION, \ FAVICON_PATH, ENABLE_THUMBNAIL, THUMBNAIL_SIZE_FOR_ORIGINAL, \ MEDIA_ROOT, SHOW_LOGOUT_ICON, CUSTOM_LOGO_PATH, CUSTOM_FAVICON_PATH @@ -84,7 +84,7 @@ def base(request): result = { 'seafile_version': SEAFILE_VERSION, 'site_title': config.SITE_TITLE, - 'branding_css': BRANDING_CSS, + 'branding_css': config.ENABLE_BRANDING_CSS, 'favicon_path': favicon_path, 'logo_path': logo_path, 'logo_width': LOGO_WIDTH, diff --git a/seahub/settings.py b/seahub/settings.py index dec7a86dbc..e836236162 100644 --- a/seahub/settings.py +++ b/seahub/settings.py @@ -464,8 +464,8 @@ LOGO_HEIGHT = 32 CUSTOM_LOGO_PATH = 'custom/mylogo.png' CUSTOM_FAVICON_PATH = 'custom/favicon.ico' -# css to modify the seafile css (e.g. css/my_site.css) -BRANDING_CSS = '' +# Enable custom css to modify the seafile css +ENABLE_BRANDING_CSS = False # Using Django to server static file. Set to `False` if deployed behide a web # server. @@ -763,4 +763,7 @@ CONSTANCE_CONFIG = { 'SITE_NAME': (SITE_NAME, ''), 'SITE_TITLE': (SITE_TITLE, ''), + + 'ENABLE_BRANDING_CSS': (ENABLE_BRANDING_CSS, ''), + 'CUSTOM_CSS': ('', ''), } diff --git a/seahub/templates/base.html b/seahub/templates/base.html index ccef7e08c0..b3d180edfa 100644 --- a/seahub/templates/base.html +++ b/seahub/templates/base.html @@ -16,7 +16,7 @@ {% block extra_style %}{% endblock %} -{% if branding_css != '' %}{% endif %} +{% if branding_css %}{% endif %} diff --git a/seahub/templates/base_for_backbone.html b/seahub/templates/base_for_backbone.html index 739c7eb8a4..e723b80733 100644 --- a/seahub/templates/base_for_backbone.html +++ b/seahub/templates/base_for_backbone.html @@ -19,7 +19,7 @@ {% endcompress %} {% block extra_style %}{% endblock %} -{% if branding_css != '' %}{% endif %} +{% if branding_css %}{% endif %} diff --git a/seahub/templates/snippets/web_settings_form.html b/seahub/templates/snippets/web_settings_form.html index 84eb530122..549865f0d2 100644 --- a/seahub/templates/snippets/web_settings_form.html +++ b/seahub/templates/snippets/web_settings_form.html @@ -30,6 +30,21 @@ {% endif %} +{% if type == 'css_textarea' %} +
+
{{ setting_display_name }}
+
+ +

+

{{ help_tip }}

+
+
+ + +
+
+{% endif %} + {% if type == 'checkbox' %}
{% csrf_token %}
{{ setting_display_name }}
diff --git a/seahub/templates/sysadmin/settings.html b/seahub/templates/sysadmin/settings.html index 4eb898e8a9..f9353b5178 100644 --- a/seahub/templates/sysadmin/settings.html +++ b/seahub/templates/sysadmin/settings.html @@ -22,10 +22,10 @@ {% include "snippets/web_settings_form.html" %} {% endwith %} -

Branding

+

{% trans "Branding" %}

{% with type="input" setting_display_name="SITE_TITLE" setting_name="SITE_TITLE" setting_val=config_dict.SITE_TITLE %} - {% trans "Site title showing in browser tab" as help_tip %} + {% trans "Site title shown in a browser tab" as help_tip %} {% include "snippets/web_settings_form.html" %} {% endwith %} @@ -47,6 +47,17 @@ {% include "snippets/web_settings_form.html" %} {% endwith %} + {% with type="checkbox" setting_name="ENABLE_BRANDING_CSS" setting_val=config_dict.ENABLE_BRANDING_CSS %} + {% trans "ENABLE_BRANDING_CSS" as setting_display_name %} + {% trans "Enable user use custom css" as help_tip %} + {% include "snippets/web_settings_form.html" %} + {% endwith %} + + {% with type="css_textarea" setting_name="CUSTOM_CSS" setting_val=config_dict.CUSTOM_CSS %} + {% trans "Custom css content" as setting_display_name %} + {% include "snippets/web_settings_form.html" %} + {% endwith %} +

{% trans "User" %}

{% with type="checkbox" setting_name="ENABLE_SIGNUP" setting_val=config_dict.ENABLE_SIGNUP %} diff --git a/seahub/templates/sysadmin/sysadmin_backbone.html b/seahub/templates/sysadmin/sysadmin_backbone.html index 72617e19af..5b4c64b076 100644 --- a/seahub/templates/sysadmin/sysadmin_backbone.html +++ b/seahub/templates/sysadmin/sysadmin_backbone.html @@ -18,7 +18,7 @@ {% endcompress %} -{% if branding_css != '' %}{% endif %} +{% if branding_css %}{% endif %} diff --git a/seahub/urls.py b/seahub/urls.py index ae72747a5e..f882ec82f0 100644 --- a/seahub/urls.py +++ b/seahub/urls.py @@ -154,6 +154,7 @@ urlpatterns = [ ### Misc ### url(r'^image-view/(?P.*)$', image_view, name='image_view'), + url(r'^custom-css/$', custom_css_view, name='custom_css'), url(r'^i18n/$', i18n, name='i18n'), url(r'^convert_cmmt_desc_link/$', convert_cmmt_desc_link, name='convert_cmmt_desc_link'), url(r'^modules/toggle/$', toggle_modules, name="toggle_modules"), diff --git a/seahub/views/__init__.py b/seahub/views/__init__.py index 789a144858..2d6b3f40d2 100644 --- a/seahub/views/__init__.py +++ b/seahub/views/__init__.py @@ -1077,6 +1077,11 @@ def image_view(request, filename): response['Content-Encoding'] = content_encoding return response +def custom_css_view(request): + file_content = config.CUSTOM_CSS + response = HttpResponse(content=file_content, content_type='text/css') + return response + def underscore_template(request, template): """Serve underscore template through Django, mainly for I18n. diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index 2d836db45b..6912bd3d4a 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -2074,11 +2074,12 @@ def sys_settings(request): 'USER_PASSWORD_STRENGTH_LEVEL', 'SHARE_LINK_PASSWORD_MIN_LENGTH', 'ENABLE_USER_CREATE_ORG_REPO', 'FORCE_PASSWORD_CHANGE', 'LOGIN_ATTEMPT_LIMIT', 'FREEZE_USER_ON_LOGIN_FAILED', - 'ENABLE_SHARE_TO_ALL_GROUPS', 'ENABLE_TWO_FACTOR_AUTH' + 'ENABLE_SHARE_TO_ALL_GROUPS', 'ENABLE_TWO_FACTOR_AUTH', + 'ENABLE_BRANDING_CSS', ] STRING_WEB_SETTINGS = ('SERVICE_URL', 'FILE_SERVER_ROOT', 'TEXT_PREVIEW_EXT', - 'SITE_NAME', 'SITE_TITLE') + 'SITE_NAME', 'SITE_TITLE', 'CUSTOM_CSS') if request.is_ajax() and request.method == "POST": content_type = 'application/json; charset=utf-8'