Skip to content

Commit

Permalink
Add custom favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
kizniche committed Oct 1, 2024
1 parent e284399 commit 32f7424
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### Miscellaneous

- Allow deletion of the last remaining Dashboard
- Add custom favicon


## 8.16.0 (2024.09.29)
Expand Down
44 changes: 44 additions & 0 deletions alembic_db/alembic/versions/5966b3569c89_add_favicon_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""add favicon options
Revision ID: 5966b3569c89
Revises: 435f35958689
Create Date: 2024-10-01 13:39:25.265702
"""
import sys
import os

sys.path.append(os.path.abspath(os.path.join(__file__, "../../../..")))

from alembic_db.alembic_post_utils import write_revision_post_alembic

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '5966b3569c89'
down_revision = '435f35958689'
branch_labels = None
depends_on = None


def upgrade():
# write_revision_post_alembic(revision)

with op.batch_alter_table("misc") as batch_op:
batch_op.add_column(sa.Column('favicon_display', sa.Text))
batch_op.add_column(sa.Column('brand_favicon', sa.BLOB))

op.execute(
'''
UPDATE misc
SET favicon_display='default'
'''
)


def downgrade():
with op.batch_alter_table("misc") as batch_op:
batch_op.drop_column('favicon_display')
batch_op.drop_column('brand_favicon')
10 changes: 5 additions & 5 deletions mycodo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from config_translations import TRANSLATIONS as T

MYCODO_VERSION = '8.16.0'
ALEMBIC_VERSION = '435f35958689'
ALEMBIC_VERSION = '5966b3569c89'

# FORCE UPGRADE MASTER
# Set True to enable upgrading to the master branch of the Mycodo repository.
Expand Down Expand Up @@ -59,10 +59,10 @@
PATH_TEMPLATE_LAYOUT = os.path.join(PATH_TEMPLATE, 'layout.html')
PATH_TEMPLATE_LAYOUT_DEFAULT = os.path.join(PATH_TEMPLATE, 'layout_default.html')
PATH_TEMPLATE_USER = os.path.join(PATH_TEMPLATE, 'user_templates')
PATH_CSS = os.path.join(INSTALL_DIRECTORY, 'mycodo/mycodo_flask/static/css')
PATH_CSS_USER = os.path.join(PATH_CSS, 'user_css')
PATH_JS_USER = os.path.join(INSTALL_DIRECTORY, 'mycodo/mycodo_flask/static/js/user_js')
PATH_FONTS_USER = os.path.join(INSTALL_DIRECTORY, 'mycodo/mycodo_flask/static/fonts/user_fonts')
PATH_STATIC = os.path.join(INSTALL_DIRECTORY, 'mycodo/mycodo_flask/static')
PATH_CSS_USER = os.path.join(PATH_STATIC, 'css/user_css')
PATH_JS_USER = os.path.join(PATH_STATIC, 'js/user_js')
PATH_FONTS_USER = os.path.join(PATH_STATIC, 'fonts/user_fonts')
PATH_USER_SCRIPTS = os.path.join(INSTALL_DIRECTORY, 'mycodo/user_scripts')
PATH_PYTHON_CODE_USER = os.path.join(INSTALL_DIRECTORY, 'mycodo/user_python_code')
PATH_MEASUREMENTS_BACKUP = os.path.join(INSTALL_DIRECTORY, 'mycodo/backup_measurements')
Expand Down
2 changes: 2 additions & 0 deletions mycodo/databases/models/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Misc(CRUDMixin, db.Model):
hostname_override = db.Column(db.String, default='')
brand_image = db.Column(db.BLOB, default=b'')
brand_image_height = db.Column(db.Integer, default=55)
favicon_display = db.Column(db.String, default='default')
brand_favicon = db.Column(db.BLOB, default=b'')
custom_css = db.Column(db.String, default='')
custom_layout = db.Column(db.String, default='')

Expand Down
2 changes: 2 additions & 0 deletions mycodo/mycodo_flask/forms/forms_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class SettingsGeneral(FlaskForm):
hostname_override = StringField(lazy_gettext('Brand Text'))
brand_image = FileField(lazy_gettext('Brand Image'))
brand_image_height = IntegerField(lazy_gettext('Brand Image Height'))
favicon_display = StringField(lazy_gettext('Favicon Display'))
brand_favicon = FileField(lazy_gettext('Favicon Image'))
daemon_debug_mode = BooleanField(lazy_gettext('Enable Daemon Debug Logging'))
force_https = BooleanField(lazy_gettext('Force HTTPS'))
hide_success = BooleanField(lazy_gettext('Hide success messages'))
Expand Down
22 changes: 22 additions & 0 deletions mycodo/mycodo_flask/routes_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import socket
import subprocess
import traceback
from io import BytesIO

import flask_login
from flask import (current_app, redirect, render_template, request,
send_from_directory, url_for)
from flask import send_file
from flask.blueprints import Blueprint

from mycodo.config import (ALEMBIC_VERSION, INSTALL_DIRECTORY, LANGUAGES,
MYCODO_VERSION, THEMES, THEMES_DARK)
from mycodo.config import PATH_STATIC
from mycodo.config_translations import TRANSLATIONS
from mycodo.databases.models import Dashboard, Misc
from mycodo.mycodo_client import DaemonControl
Expand Down Expand Up @@ -86,6 +89,25 @@ def inject_variables():
upgrade_available=misc.mycodo_upgrade_available)


@blueprint.app_errorhandler(404)
def not_found(error):
return render_template('404.html', error=error), 404


@blueprint.route('/favicon.png')
def favicon():
"""Return favicon image"""
misc = Misc.query.first()

if misc.favicon_display == 'default':
return send_from_directory(os.path.join(PATH_STATIC, 'img'), "favicon.png")
else:
return send_file(
BytesIO(misc.brand_favicon),
mimetype='image/png'
)


@blueprint.route('/robots.txt')
def static_from_root():
"""Return static robots.txt."""
Expand Down
2 changes: 1 addition & 1 deletion mycodo/mycodo_flask/templates/create_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/static/img/favicon.png">
<link rel="icon" href="/favicon.png">

<title>Mycodo - {{_('Create Admin')}} - {{host}}</title>

Expand Down
2 changes: 1 addition & 1 deletion mycodo/mycodo_flask/templates/forgot_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/static/img/favicon.png">
<link rel="icon" href="/favicon.png">

<title>Mycodo Reset Password - {{host}}</title>

Expand Down
2 changes: 1 addition & 1 deletion mycodo/mycodo_flask/templates/layout-remote.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" type="image/png" href="/static/img/favicon.png">
<link rel="icon" type="image/png" href="/favicon.png">

<title>Mycodo {{mycodo_version}} - {{host}}{% block title %}{% endblock %}</title>

Expand Down
2 changes: 1 addition & 1 deletion mycodo/mycodo_flask/templates/layout_default.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" type="image/png" href="/static/img/favicon.png">
<link rel="icon" type="image/png" href="/favicon.png">

<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="Mycodo {{mycodo_version}}">
Expand Down
2 changes: 1 addition & 1 deletion mycodo/mycodo_flask/templates/login_keypad.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/static/img/favicon.png">
<link rel="icon" href="/favicon.png">

<title>{{host}} - Mycodo {{dict_translation['login']['title']}}</title>

Expand Down
2 changes: 1 addition & 1 deletion mycodo/mycodo_flask/templates/login_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/static/img/favicon.png">
<link rel="icon" href="/favicon.png">

<title>{{host}} - Mycodo {{dict_translation['login']['title']}}</title>

Expand Down
2 changes: 1 addition & 1 deletion mycodo/mycodo_flask/templates/reset_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/static/img/favicon.png">
<link rel="icon" href="/favicon.png">

<title>{{host}} - Mycodo Reset Password</title>

Expand Down
15 changes: 15 additions & 0 deletions mycodo/mycodo_flask/templates/settings/general.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ <h3 style="text-align: right; padding-bottom: 1.3em;"><a href="https://kizniche.
{{form_settings_general.brand_image_height(class_='form-control', value=settings.brand_image_height, **{'title':_("Height of the brand image, in pixels.")})}}
</div>
</div>
<div class="form-group">
{{form_settings_general.favicon_display.label(class_='col-sm-12 control-label')}}
<div class="col-sm-12">
<select class="form-control form-tooltip form-dropdown" data-placement="top" id="favicon_display" name="favicon_display" title="{{_('What to display as the favicon')}}">
<option value="default"{% if settings.favicon_display == 'default' %} selected{% endif %}>{{_('Default')}}</option>
<option value="brand_favicon"{% if settings.favicon_display == 'brand_favicon' %} selected{% endif %}>{{_('Brand Icon')}}</option>
</select>
</div>
</div>
<div class="form-group">
{{form_settings_general.brand_favicon.label(class_='col-sm-12 control-label checkbox-nopad')}}
<div class="col-sm-12">
<span class="btn btn-sm btn-file"><input id="brand_favicon" name="brand_favicon" type="file" /></span> Data Saved: {% if settings.brand_favicon %}True{% else %}False{% endif %}
</div>
</div>
<div class="form-group">
{{form_settings_general.rpyc_timeout.label(class_='col-sm-12 control-label checkbox-nopad')}}
<div class="col-sm-12">
Expand Down
3 changes: 3 additions & 0 deletions mycodo/mycodo_flask/utils/utils_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ def settings_general_mod(form):
if form.brand_image.data:
mod_misc.brand_image = form.brand_image.data.read()
mod_misc.brand_image_height = form.brand_image_height.data
mod_misc.favicon_display = form.favicon_display.data
if form.brand_favicon.data:
mod_misc.brand_favicon = form.brand_favicon.data.read()
mod_misc.daemon_debug_mode = form.daemon_debug_mode.data
mod_misc.hide_alert_success = form.hide_success.data
mod_misc.hide_alert_info = form.hide_info.data
Expand Down

0 comments on commit 32f7424

Please sign in to comment.