def post_form_intake(post, form, editor):
    ''' takes the values from 'form', passes the post contents to
        the editor 'receive' function, and adds all the values into
        the 'post' object.

        NOTE: this actually modifies the post it is sent!
    '''

    post.content = json.dumps(editor.receive(form))

    post.status = 0  # any time a post is edited, remove it from archive.

    post.time_restrictions_show = \
        (form.get('times_mode', 'do_not_show') == 'only_show')
    post.time_restrictions = form.get('time_restrictions_json', '[]')
    post.display_time = \
        getint('displaytime', 8, minimum=2, maximum=100, form=form)

    print(type(form['active_start']))

    post.active_start = \
        getstr('active_start', post.active_start, validate=DATESTR, form=form)

    print(type(post.active_start))
    post.active_end = \
        getstr('active_end', post.active_end, validate=DATESTR, form=form)

    post.write_date = now()
def post_form_intake(post, form, editor):
    ''' takes the values from 'form', passes the post contents to
        the editor 'receive' function, and adds all the values into
        the 'post' object.

        NOTE: this actually modifies the post it is sent!
    '''

    post.content = json.dumps(editor.receive(form))

    post.status = 0 # any time a post is edited, remove it from archive.

    post.time_restrictions_show = \
        (form.get('times_mode', 'do_not_show') == 'only_show')
    post.time_restrictions = form.get('time_restrictions_json', '[]')
    post.display_time = \
        getint('displaytime', 8, minimum=2, maximum=100, form=form)

    print type(form['active_start'])

    post.active_start = \
        getstr('active_start', post.active_start, validate=DATESTR, form=form)

    print type(post.active_start)
    post.active_end = \
        getstr('active_end', post.active_end, validate=DATESTR, form=form)

    post.write_date = now()
Beispiel #3
0
    def test_validates_date(self):
        self.resp.form['GETME'] = 'blah'
        dateformat = r'(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)'
        date = '2016-10-12 16:02:19'

        self.assertEqual(getstr('GETME', 'none', validate=dateformat), 'none')

        self.resp.form['GETME'] = date
        self.assertEqual(getstr('GETME', 'none', validate=dateformat), date)
    def test_validates_date(self):
        self.resp.form['GETME'] = 'blah'
        dateformat = r'(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)'
        date = '2016-10-12 16:02:19'

        self.assertEquals(getstr('GETME', 'none', validate=dateformat), 'none')

        self.resp.form['GETME'] = date
        self.assertEquals(getstr('GETME', 'none', validate=dateformat), date)
 def test_empty(self):
     self.resp.form['GETME'] = ''
     self.assertEquals(getstr('GETME', 'default'), '')
 def test_not_there(self):
     self.assertFalse('GETME' in self.resp.form)
     self.assertEquals(getstr('GETME', 'default_value'), 'default_value')
 def test_there(self):
     self.resp.form['GETME'] = 'set thing'
     self.assertEquals(getstr('GETME', 'default_value'), 'set thing')
 def test_validates_STRIPSTR_number(self):
     text = '2019'
     self.resp.form['GETME'] = ' ' + text + '\t '
     self.assertEquals(getstr('GETME', 'none', validate=STRIPSTR), text)
 def test_empty_string(self):
     self.resp.form['GETME'] = ''
     self.assertEquals(getstr('GETME', 'none'), '')
Beispiel #10
0
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)))
Beispiel #11
0
 def test_validates_STRIPSTR_lstrip(self):
     text = 'this is some text'
     self.resp.form['GETME'] = ' ' + text
     self.assertEqual(getstr('GETME', 'none', validate=STRIPSTR), text)
 def test_validate_fails(self):
     fallback = 42
     self.resp.form['GETME'] = 'Not a valid date.'
     self.assertEquals(getstr('GETME', fallback, validate=DATESTR), fallback)
 def test_validates_DATESTR_strip(self):
     date = '2016-10-12 16:02:19'
     self.resp.form['GETME'] = '   ' + date + '.00 stuff'
     self.assertEquals(getstr('GETME', 'none', validate=DATESTR), date)
Beispiel #14
0
 def test_validates(self):
     self.resp.form['GETME'] = 'blah'
     self.assertEqual(getstr('GETME', 'none', validate='.*@.*'), 'none')
 def test_validates(self):
     self.resp.form['GETME'] = 'blah'
     self.assertEquals(getstr('GETME', 'none', validate='.*@.*'), 'none')
Beispiel #16
0
 def test_empty(self):
     self.resp.form['GETME'] = ''
     self.assertEqual(getstr('GETME', 'default'), '')
Beispiel #17
0
 def test_there(self):
     self.resp.form['GETME'] = 'set thing'
     self.assertEqual(getstr('GETME', 'default_value'), 'set thing')
Beispiel #18
0
 def test_not_there(self):
     self.assertFalse('GETME' in self.resp.form)
     self.assertEqual(getstr('GETME', 'default_value'), 'default_value')
Beispiel #19
0
 def test_empty_string(self):
     self.resp.form['GETME'] = ''
     self.assertEqual(getstr('GETME', 'none'), '')
Beispiel #20
0
 def test_validates_STRIPSTR_number(self):
     text = '2019'
     self.resp.form['GETME'] = ' ' + text + '\t '
     self.assertEqual(getstr('GETME', 'none', validate=STRIPSTR), text)
Beispiel #21
0
 def test_validate_fails(self):
     fallback = 42
     self.resp.form['GETME'] = 'Not a valid date.'
     self.assertEqual(getstr('GETME', fallback, validate=DATESTR), fallback)
Beispiel #22
0
 def test_validates_DATESTR_valid(self):
     date = '2016-10-12 16:02:19'
     self.resp.form['GETME'] = date
     self.assertEqual(getstr('GETME', 'none', validate=DATESTR), date)
 def test_validates_DATESTR_valid(self):
     date = '2016-10-12 16:02:19'
     self.resp.form['GETME'] = date
     self.assertEquals(getstr('GETME', 'none', validate=DATESTR), date)
Beispiel #24
0
 def test_validates_DATESTR_strip(self):
     date = '2016-10-12 16:02:19'
     self.resp.form['GETME'] = '   ' + date + '.00 stuff'
     self.assertEqual(getstr('GETME', 'none', validate=DATESTR), date)
 def test_validates_STRIPSTR_rstrip(self):
     text = 'this is some text'
     self.resp.form['GETME'] = ' ' + text + '\t'
     self.assertEquals(getstr('GETME', 'none', validate=STRIPSTR), text)
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)))