def theme(self): # custom view to set theme form = ThemeForm() theme = ThirdPartyServices.query.filter_by(name='theme').first() if theme is None: temp_theme = current_app.config['THEME'] else: temp_theme = theme.code if form.validate_on_submit(): if theme is None: theme = ThirdPartyServices( name='theme', code=form.theme.data, ) db.session.add(theme) else: theme.code = form.theme.data db.session.commit() current_app.config['THEME'] = form.theme.data current_app.jinja_env.cache = {} current_app.jinja_env.globals['THEME_FILE'] = 'themes/' + \ form.theme.data + '.min.css' flash('Theme saved. Switch from the admin panel back to \ your site to see the changes. You may need to reload.') Thread(hup_gunicorn()).start() return redirect(url_for('theme.theme')) return self.render('admin/theme.html', form=form, current_theme=temp_theme)
def isso(self): # custom view to activate isso comments if Email.query.first() is None: flash('You must set up email first.') return redirect(url_for('email.email')) elif Email.query.first().server is None: flash('You must set up email first.') return redirect(url_for('email.email')) form = IssoForm() isso = ThirdPartyServices.query.filter_by(name='isso').first() if form.validate_on_submit(): if isso is None: isso = ThirdPartyServices( name='isso', code=form.code.data, ) db.session.add(isso) else: isso.code = form.code.data db.session.commit() isso_config() current_app.config['COMMENTS'] = True flash('User comments active.') Thread(hup_gunicorn()).start() return redirect(url_for('admin.index')) return self.render('admin/isso.html', form=form, isso=isso)
def delete_ga(): # deactivates Google Analytics ga = ThirdPartyServices.query.filter_by(name='ga').first() if ga is not None: db.session.delete(ga) db.session.commit() current_app.config['BLOGGING_GOOGLE_ANALYTICS'] = None flash('Google Analytics deactivated.') Thread(hup_gunicorn()).start() return redirect(url_for('admin.index'))
def deactivate_isso(): # deactivates isso comments # does not delete the comments.db, so can be reactivated later # comment moderation password can be rest by deactivate/reactivate isso = ThirdPartyServices.query.filter_by(name='isso').first() if isso is not None: db.session.delete(isso) db.session.commit() current_app.config['COMMENTS'] = False flash(''' Comments deactivated. Due to browser caching, there can be a delay before comments disappear. ''') Thread(hup_gunicorn()).start() return redirect(url_for('admin.index'))
def ga(self): # custom view to input Google Analytics UA code form = GAForm() ga = ThirdPartyServices.query.filter_by(name='ga').first() if form.validate_on_submit(): if ga is None: ga = ThirdPartyServices( name='ga', code=form.code.data, ) db.session.add(ga) else: ga.code = form.code.data db.session.commit() current_app.config['BLOGGING_GOOGLE_ANALYTICS'] = \ ga.code flash('Google Analytics data saved.') Thread(hup_gunicorn()).start() return redirect(url_for('admin.index')) return self.render('admin/ga.html', form=form, ga=ga)