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 = MediaServer.query.get(server_id) except: logger.log('Error retrieving server details for server ID %s' % server_id , 'WARNING') # GET if request.method == 'GET': # This is a workaround to data not existing when we are creating a new server and in turn throwing errors at the template when trying to access the data hostname = '' port = '' username = '' password = '' mac_address = '' if server != None: hostname = server.data['hostname'] port = server.data['port'] username = server.data['username'] password = server.data['password'] mac_address = server.data['mac_address'] return render_template('dialogs/server_settings_dialog.html', server = server, hostname = hostname, port = port, username = username, password = password, mac_address = mac_address ) # POST else: if not server: server = MediaServer('', '', {}, 1) label = request.form['label'] if not label: label = 'Media server' try: server.data = {'hostname': request.form['hostname'], 'port': request.form['port'], 'username': request.form['username'], 'password': request.form['password'], 'mac_address': request.form['mac_address']} server.type = request.form['type'] 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 = MediaServer.query.order_by(MediaServer.position), ) except: logger.log('Error saving Media server to database', 'WARNING') return jsonify({ 'status': 'error' }) return jsonify({ 'status': 'error' })
def index(): from maraschino.models import Module, Setting, Application, MediaServer 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 = MediaServer.query.order_by(MediaServer.position) if servers.count() == 0: # check if old server settings value is set old_server_hostname = get_setting_value('server_hostname') # create an MediaServer entry using the legacy settings if old_server_hostname: mediaServer = MediaServer( 'XBMC server 1', '', {}, 1, ) mediaServer.data = {'hostname': old_server_hostname, 'port': get_setting_value('server_port'), 'username': get_setting_value('server_username'), 'password': get_setting_value('server_password'), 'mac_address': get_setting_value('server_macaddress'),} try: db_session.add(mediaServer) db_session.commit() servers = MediaServer.query.order_by(MediaServer.position) except: logger.log('Could not create new MediaServer 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', library_app_link="http://xbmc.org/" if safe_server_address() is None else safe_server_address(), webroot=maraschino.WEBROOT, kiosk=maraschino.KIOSK, new_tab=new_tab, title_color=get_setting_value('title_color'), remote_inactivity_enable=get_setting_value('remote_inactivity_enable') )