def feeds(): ''' the back end list of feeds. ''' if request.method == 'POST': if not user_session.is_admin(): flash('Only Admins can do this!') return redirect(url_for('feeds')) action = request.form.get('action', 'create') if action == 'create': if not request.form.get('title', '').strip(): flash("I'm not making you an un-named feed!") return redirect(url_for('feeds')) Feed(name=request.form.get('title', 'blank').strip()).save() try: user = user_session.get_user() except user_session.NotLoggedIn as e: user = User() return render_template('feeds.html', feeds=Feed.select(), user=user, external_sources=ExternalSource.select(), source_types=external_source_types.types())
def screenedit(screenid): ''' edit one screen ''' try: if int(screenid) == -1: flash('New Screen') screen = Screen() # pylint: disable=no-value-for-parameter else: screen = Screen().get(Screen.id == int(screenid)) # pylint: disable=no-value-for-parameter backgrounds = [basename(x) for x in \ glob(app.config['SITE_VARS']['user_dir'] + '*') if allow_filetype(x)] except Screen.DoesNotExist: flash('Invalid Screen ID! Screen does NOT exist!') return redirect(url_for('index')) if request.method == 'POST': if not user_session.logged_in(): flash("You're not logged in!") return redirect(url_for('posts')) user = user_session.get_user() if not user.is_admin: flash('Sorry. You are NOT an admin!') return redirect(url_for('index')) if request.form.get('action', 'update') == 'delete': screen.delete_instance() flash('deleted') return redirect(request.referrer) # first check that name is OK: try: oldname = screen.urlname screen.urlname = urllib.quote(request.form.get('urlname'), '') screen.save() except sqlite3.IntegrityError: screen.urlname = oldname flash("Sorry! That name is already being used!") screen.background = request.form.get('background') screen.settings = request.form.get('settings', '') screen.css = request.form.get('css', '').replace('"',"'") screen.zones = form_json('zones', {}) screen.save() flash('saved.') if int(screenid) == -1: return redirect(url_for('screenedit', screenid=screen.id)) return render_template('screen_editor.html', feeds=Feed.select(), backgrounds=backgrounds, screen=screen)
def screenedit(screenid): ''' edit one screen ''' try: if int(screenid) == -1: flash('New Screen') screen = Screen() # pylint: disable=no-value-for-parameter else: screen = Screen().get(Screen.id == int(screenid)) # pylint: disable=no-value-for-parameter backgrounds = [basename(x) for x in \ glob(app.config['SITE_VARS']['user_dir'] + '*') if allow_filetype(x)] except Screen.DoesNotExist: flash('Invalid Screen ID! Screen does NOT exist!') return redirect(url_for('index')) if request.method == 'POST': if request.form.get('action', 'update') == 'delete': screen.delete_instance() flash('deleted') return redirect(request.referrer) # first check that name is OK: try: oldname = screen.urlname screen.urlname = urllib.parse.quote(request.form.get('urlname'), '') screen.save() except sqlite3.IntegrityError: screen.urlname = oldname flash("Sorry! That name is already being used!") screen.background = request.form.get('background') screen.settings = request.form.get('settings', '') screen.css = request.form.get('css', '').replace('"', "'") screen.zones = form_json('zones', {}) screen.save() flash('saved.') if int(screenid) == -1: return redirect(url_for('screenedit', screenid=screen.id)) fonts = ['', 'serif', 'sans-serif', 'monospace', 'cursive', 'fantasy'] fonts += [name for name, _ in user_fonts()] return render_template('screen_editor.html', feeds=Feed.select(), backgrounds=backgrounds, fonts=fonts, screen=screen)
def index(): ''' main front page / dashboard / index. ''' try: user = user_session.get_user() except user_session.NotLoggedIn as e: user = User() if not user: user = User() publishable_feeds = user.publishable_feeds() posts_to_publish = Post.select()\ .where((Post.published==False) & (Post.feed << publishable_feeds)) screens = Screen.select() aliases = config_var('screens.aliases', []) for alias in aliases: for screen in screens: if screen.urlname == alias['screen_name']: alias['screen'] = screen break else: alias['screen'] = None return render_template('dashboard.html', aliases=aliases, feeds=Feed.select(), publishable_feeds=publishable_feeds, posts=Post.select().where(Post.author == user)\ .order_by(Post.write_date.desc())\ .limit(15), posts_to_publish=posts_to_publish, screens=screens, user=user)
def feeds(): ''' the back end list of feeds. ''' if request.method == 'POST': action = request.form.get('action', 'create') if action == 'create': if not request.form.get('title', '').strip(): flash("I'm not making you an un-named feed!") return redirect(url_for('feeds')) Feed(name=request.form.get('title', 'blank').strip()).save() try: user = user_session.get_user() except user_session.NotLoggedIn: user = User() return render_template('feeds.html', feeds=Feed.select(), user=user, external_sources=ExternalSource.select(), source_types=external_source_types.types())
def index(): ''' main front page / dashboard / index. ''' try: user = user_session.get_user() except user_session.NotLoggedIn: user = User() if not user: user = User() publishable_feeds = user.publishable_feeds() posts_to_publish = Post.select()\ .where((Post.published == False) & (Post.feed << publishable_feeds)) screens = Screen.select() aliases = config_var('screens.aliases', []) for alias in aliases: for screen in screens: if screen.urlname == alias['screen_name']: alias['screen'] = screen break else: alias['screen'] = None return render_template('dashboard.html', aliases=aliases, feeds=Feed.select(), publishable_feeds=publishable_feeds, posts=Post.select().where(Post.author == user)\ .order_by(Post.write_date.desc())\ .limit(15), posts_to_publish=posts_to_publish, screens=screens, user=user)
def external_data_source_edit(source_id): ''' Editing a external data source ''' if not user_session.is_admin(): flash('Only Admins can do this!') return redirect(url_for('feeds')) # first find the data type: if request.method == 'DELETE': ExternalSource.delete() \ .where(ExternalSource.id == int(source_id)) \ .execute() return 'deleted' if source_id == None: try: source = ExternalSource() source.type = request.args['type'] source.name = "new " + source.type + " source" source.feed = Feed.get() # set initial feed except KeyError: return 'No type specified.', 500 else: try: source = ExternalSource.get(id=source_id) except peewee.DoesNotExist: return 'Invalid id.', 404 # Try and load the external source type ( and check it's valid): try: module = external_source_types.load(source.type) except ImportError: return 'Invalid External Source Type', 404 # if it's a post, then update the data with 'receive': if request.method == 'POST': source.post_as_user = user_session.get_user() source.settings = json.dumps(module.receive(request)) source.name = request.form.get('name', source.name) source.frequency = getint('frequency', 60) source.publish = getbool('publish', False) source.lifetime_start = request.form.get('active_start', source.lifetime_start) source.lifetime_end = request.form.get('active_end', source.lifetime_end) source.display_time = getint('display_time', source.display_time) source.post_template = request.form.get('post_template', source.post_template) try: source.feed = Feed.get(Feed.id == getint('feed', 100)) source.save() if source_id == None: # new source! return redirect(url_for('external_data_source_edit', source_id=source.id)) else: flash('Updated.') except Feed.DoesNotExist: flash("Can't save! Invalid Feed!{}".format( getint('feed', '-11'))) return render_template("external_source.html", source=source, feeds=Feed.select(), form=module.form(json.loads(source.settings)))
def external_data_source_edit(source_id): ''' Editing a external data source ''' if not user_session.is_admin(): flash('Only Admins can do this!') return redirect(url_for('feeds')) # first find the data type: if request.method == 'DELETE': ExternalSource.delete() \ .where(ExternalSource.id == int(source_id)) \ .execute() return 'deleted' if source_id == None: try: source = ExternalSource() source.type = request.args['type'] source.name = "new " + source.type + " source" source.feed = Feed.get() # set initial feed except KeyError: return 'No type specified.', 500 else: try: source = ExternalSource.get(id=source_id) except peewee.DoesNotExist: return 'Invalid id.', 404 # Try and load the external source type ( and check it's valid): try: module = external_source_types.load(source.type) except ImportError: return 'Invalid External Source Type', 404 # if it's a post, then update the data with 'receive': if request.method == 'POST': source.post_as_user = user_session.get_user() source.settings = json.dumps(module.receive(request)) source.name = request.form.get('name', source.name) source.frequency = getint('frequency', 60) source.publish = getbool('publish', False) source.lifetime_start = getstr('active_start', source.lifetime_start, validate=DATESTR) source.lifetime_end = getstr('active_end', source.lifetime_end, validate=DATESTR) source.display_time = getint('display_time', source.display_time) source.post_template = request.form.get('post_template', source.post_template) try: source.feed = Feed.get(Feed.id == getint('feed', 100)) source.save() if source_id == None: # new source! return redirect( url_for('external_data_source_edit', source_id=source.id)) else: flash('Updated.') except Feed.DoesNotExist: flash("Can't save! Invalid Feed!{}".format(getint('feed', '-11'))) return render_template("external_source.html", source=source, feeds=Feed.select(), form=module.form(json.loads(source.settings)))
def test_users_none(self): self.assertEqual(Feed.select().count(), 0)
def test_users_none(self): self.assertEqual(Feed.select().count(), 0)