Example #1
0

login_manager = LoginManager()
babel = Babel()

app = Flask(__name__)
app.debug = True
login_manager.init_app(app)
babel.init_app(app)

app.jinja_env.globals["bootstrap_is_hidden_field"] = is_hidden_field_filter

# in a real app, these should be configured through Flask-Appconfig
app.config["SECRET_KEY"] = "devkey"
app.config["RECAPTCHA_PUBLIC_KEY"] = "6Lfol9cSAAAAADAkodaYl9wvQCwBMr3qGR_PPHcw"
app.config["BABEL_DEFAULT_TIMEZONE"] = "Europe/Paris"

# jinja 2 filters
def format_babel_datetime(value, format="medium"):
    if format == "full":
        format = "EEEE, d. MMMM y 'at' HH:mm"
    elif format == "medium":
        format = "EE dd.MM.y HH:mm"
    elif format == "basic":
        format = "dd.MM.y HH:mm"
    return format_datetime(value, format)


def sort_by_id(value):
    return sorted(value.items(), key=lambda x: x[1]["id"])
Example #2
0
import rfk.database
from rfk.database.base import User, Anonymous, News
from rfk.database.donations import Donation
from rfk.database.streaming import Stream, Listener, Relay
from rfk.site.forms.login import login_form, register_form
from rfk.site.forms.settings import SettingsForm
from rfk.exc.base import UserNameTakenException, UserNotFoundException, InvalidUsernameException
from rfk.database.track import Track
from rfk.database.show import Show, UserShow
from rfk.database.stats import Statistic
from collections import OrderedDict


app = Flask(__name__, instance_relative_config=True)
app.config["DEBUG"] = True
app.config["BABEL_DEFAULT_TIMEZONE"] = "Europe/Berlin"
app.config["BABEL_DEFAULT_LOCALE"] = "de"
app.config["BABEL_LOCALE_PATH"] = "de"
app.secret_key = get_secret_key()

locales = {
    "de": {"name": "Bernd", "img": "/static/img/cb/de.png", "datetime_format": "DD.MM.YYYY HH:mm"},
    "en": {"name": "English", "img": "/static/img/cb/gb.png", "datetime_format": "MM/DD/YYYY HH:mm"},
}


def get_datetime_format():
    try:
        return locales[str(get_locale())]["datetime_format"]
    except KeyError:
        return locales["de"]["datetime_format"]