def server_settings_dialog(server_id=None): """ Server settings dialog. If server_id exists then we're editing a server, otherwise we're adding one. """ server = None if server_id: try: server = XbmcServer.query.get(server_id) except: logger.log('Error retrieving server details for server ID %s' % server_id , 'WARNING') # GET if request.method == 'GET': return render_template('dialogs/server_settings_dialog.html', server = server, ) # POST else: if not server: server = XbmcServer('', 1, '') label = request.form['label'] if not label: label = 'XBMC server' try: server.label = label server.position = request.form['position'] server.hostname = request.form['hostname'] server.port = request.form['port'] server.username = request.form['username'] server.password = request.form['password'] server.mac_address = request.form['mac_address'] db_session.add(server) db_session.commit() active_server = get_setting('active_server') if not active_server: active_server = Setting('active_server', server.id) db_session.add(active_server) db_session.commit() return render_template('includes/servers.html', servers = XbmcServer.query.order_by(XbmcServer.position), ) except: logger.log('Error saving XBMC server to database', 'WARNING') return jsonify({ 'status': 'error' }) return jsonify({ 'status': 'error' })
def server_settings_dialog(server_id=None): """ Server settings dialog. If server_id exists then we're editing a server, otherwise we're adding one. """ server = None if server_id: try: server = XbmcServer.query.get(server_id) except: logger.log("Error retrieving server details for server ID %s" % server_id, "WARNING") # GET if request.method == "GET": return render_template("dialogs/server_settings_dialog.html", server=server) # POST else: if not server: server = XbmcServer("", 1, "") label = request.form["label"] if not label: label = "XBMC server" try: server.label = label server.position = request.form["position"] server.hostname = request.form["hostname"] server.port = request.form["port"] server.username = request.form["username"] server.password = request.form["password"] server.mac_address = request.form["mac_address"] db_session.add(server) db_session.commit() active_server = get_setting("active_server") if not active_server: active_server = Setting("active_server", server.id) db_session.add(active_server) db_session.commit() return render_template("includes/servers.html", servers=XbmcServer.query.order_by(XbmcServer.position)) except: logger.log("Error saving XBMC server to database", "WARNING") return jsonify({"status": "error"}) return jsonify({"status": "error"})
def index(): from maraschino.models import Module, Setting, Application, XbmcServer from maraschino.database import db_session unorganised_modules = Module.query.order_by(Module.position) num_columns = get_setting_value('num_columns') try: num_columns = int(num_columns) except: logger.log( 'Could not retrieve number of columns settings. Defaulting to 3.', 'WARNING') num_columns = 3 modules = [] for i in range(num_columns): modules.append([]) for module in unorganised_modules: module_info = get_module_info(module.name) module.template = '%s.html' % (module.name) module.static = module_info['static'] if module.column <= num_columns: modules[module.column - 1].append(module) else: modules[num_columns - 1].append( module) # if in a column out of range, place in last column applications = [] try: applications = Application.query.order_by(Application.position) except: pass new_tab = get_setting_value('app_new_tab') == '1' # display random background when not watching media (if setting enabled) # only changes on page refresh background = None if get_setting_value('random_backgrounds') == '1': try: backgrounds = [] custom_dir = 'static/images/backgrounds/custom/' if os.path.exists(os.path.dirname(custom_dir)): # use user-defined custom background backgrounds.extend(get_file_list(custom_dir, ['.jpg', '.png'])) # if no images in directory, use default background that is set in stylesheet if len(backgrounds) == 0: backgrounds = None else: # use backgrounds bundled with Maraschino backgrounds.extend( get_file_list('static/images/backgrounds/', ['.jpg', '.png'])) # select random background background = backgrounds[random.randrange(0, len(backgrounds))] if maraschino.WEBROOT: background = maraschino.WEBROOT + '/' + background except: background = None # show fanart backgrounds when watching media fanart_backgrounds = get_setting_value('fanart_backgrounds') == '1' # get list of servers servers = XbmcServer.query.order_by(XbmcServer.position) if servers.count() == 0: # check if old server settings value is set old_server_hostname = get_setting_value('server_hostname') # create an XbmcServer entry using the legacy settings if old_server_hostname: xbmc_server = XbmcServer( 'XBMC server 1', 1, old_server_hostname, get_setting_value('server_port'), get_setting_value('server_username'), get_setting_value('server_password'), get_setting_value('server_macaddress'), ) try: db_session.add(xbmc_server) db_session.commit() servers = XbmcServer.query.order_by(XbmcServer.position) except: logger.log( 'Could not create new XbmcServer based on legacy settings', 'WARNING') active_server = get_setting_value('active_server') if active_server and active_server != 'undefined': active_server = int(active_server) else: active_server = 1 # show currently playing bar? if get_setting_value('show_currently_playing') == None: show_currently_playing = True else: show_currently_playing = int( get_setting_value('show_currently_playing')) > 0 return render_template( 'index.html', modules=modules, num_columns=num_columns, servers=servers, active_server=active_server, show_currently_playing=show_currently_playing, search_enabled=get_setting_value('search') == '1', background=background, fanart_backgrounds=fanart_backgrounds, applications=applications, show_tutorial=unorganised_modules.count() == 0, show_music=get_setting_value('library_show_music') == '1', show_pvr=get_setting_value('library_show_pvr') == '1', show_files=get_setting_value('library_show_files') == '1', show_power=get_setting_value('library_show_power_buttons') == '1', webroot=maraschino.WEBROOT, kiosk=maraschino.KIOSK, new_tab=new_tab, title_color=get_setting_value('title_color'))