def test(data):
    ''' we get sent a copy of the data, and should reply with some HTML
        that reassures the user if the path/whatever is correct (preferably
        with some data from the feed) '''
    if exists(data['path']) and isdir(data['path']):
        files = glob(pathjoin(data['path'], '*'))

        return ('<br/>'.join([f for f in files if allow_filetype(f)]) +
                '<hr/><i>Not uploading:<br/>' +
                '<br/>'.join([f for f in files if not allow_filetype(f)]))
    else:
        return '...'
Example #2
0
def test(data):
    ''' we get sent a copy of the data, and should reply with some HTML
        that reassures the user if the path/whatever is correct (preferably
        with some data from the feed) '''
    if exists(data['path']) and isdir(data['path']):
        files = glob(pathjoin(data['path'], '*'))

        return ('<br/>'.join([f for f in files if allow_filetype(f)])
               + '<hr/><i>Not uploading:<br/>' 
               + '<br/>'.join([f for f in files if not allow_filetype(f)]))
    else:
        return '...'
Example #3
0
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)
Example #4
0
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 get_new(data):
    ''' ok, actually go get us some new posts, alright? (return new posts, and
        update data with any hidden fields updated that we need to
        (current_posts, for instance))'''

    current_files = glob(pathjoin(data['path'], '*'))

    current_files = [f for f in current_files if allow_filetype(f)]

    previous_list = data['current_posts']

    new_posts = []

    for filename in current_files:
        if basename(filename) not in previous_list:
            new_posts.append({'type': 'image', 'url': 'file://' + filename})

    data['current_posts'] = [basename(f) for f in current_files]

    return new_posts
Example #6
0
def get_new(data):
    ''' ok, actually go get us some new posts, alright? (return new posts, and
        update data with any hidden fields updated that we need to
        (current_posts, for instance))'''

    current_files = glob(pathjoin(data['path'], '*'))

    current_files = [f for f in current_files if allow_filetype(f)]

    previous_list = data['current_posts']

    new_posts = []

    for filename in current_files:
        if basename(filename) not in previous_list:
            new_posts.append({'type': 'image', 'url': 'file://' + filename})

    data['current_posts'] = [basename(f) for f in current_files]

    return new_posts