コード例 #1
0
ファイル: testmodels.py プロジェクト: findgriffin/hactar
 def test_metadata_timezones(self):
     self.skipTest('added/modified fields are not timezone aware')
     action0 = Action(self.text)
     hour_utc = dtime.utcnow().hour
     hour_local = dtime.now().hour
     self.assertEqual(action0.dt('added', 'utc').hour, hour_utc)
     self.assertEqual(action0.dt('modified', 'utc').hour, hour_utc)
     self.assertEqual(action0.dt('added', 'local').hour, hour_local)
     self.assertEqual(action0.dt('modified', 'local').hour, hour_local)
コード例 #2
0
ファイル: testmodels.py プロジェクト: findgriffin/hactar
 def test_dictify(self):
     action0 = Action(self.text)
     action_dict = action0.dictify()
     fields = ['added', 'due', 'finish_time', 'id', 'modified', 'points',
             'priority', 'start_time', 'text']
     self.assertEqual(len(action_dict.keys()), len(fields),
             msg='wrong number of fields in %s' % action_dict)
     for field in fields:
         self.assertIn(field, action_dict, 
                 msg='action dict is missing field %s' % field)
     self.assertEqual(action_dict['text'], self.text)
コード例 #3
0
ファイル: testmodels.py プロジェクト: findgriffin/hactar
 def test_dictify(self):
     action0 = Action(self.text)
     action_dict = action0.dictify()
     fields = [
         'added', 'due', 'finish_time', 'id', 'modified', 'points',
         'priority', 'start_time', 'text'
     ]
     self.assertEqual(len(action_dict.keys()),
                      len(fields),
                      msg='wrong number of fields in %s' % action_dict)
     for field in fields:
         self.assertIn(field,
                       action_dict,
                       msg='action dict is missing field %s' % field)
     self.assertEqual(action_dict['text'], self.text)
コード例 #4
0
def actions_handler():
    """Call the various helper methods, be used by api and html"""
    if request.method == 'POST':
        post_actions()
    terms = request.args.get('q')
    finish = request.args.get('finish')
    start = request.args.get('start')
    due = request.args.get('due')
    if terms:
        current_app.logger.debug('looking for memes with terms: %s' % terms)
        query = Action.search_query(terms)
    else:
        # this produces an SAWarning when db is empty (empty sequence)
        query = Action.query
        terms = False
    if finish:
        f_start, f_end = parse_iso8601(finish)
        current_app.logger.debug('getting actions finished between %s and %s' %
                                 (f_start, f_end))
        query = query.filter(Action.finish_time.between(f_start, f_end))
    if start:
        f_start, f_end = parse_iso8601(start)
        current_app.logger.debug('getting actions finished between %s and %s' %
                                 (f_start, f_end))
        query = query.filter(Action.start_time.between(f_start, f_end))
    if due:
        f_start, f_end = parse_iso8601(due)
        current_app.logger.debug('getting actions finished between %s and %s' %
                                 (f_start, f_end))
        query = query.filter(Action.due.between(f_start, f_end))
    query = query.order_by(Action.modified.desc())
    if not terms and not finish:
        query = query.limit(10)
    return query, terms
コード例 #5
0
ファイル: actions.py プロジェクト: findgriffin/hactar
def actions_handler():
    """Call the various helper methods, be used by api and html"""
    if request.method == 'POST':
        post_actions()
    terms = request.args.get('q')
    finish = request.args.get('finish')
    start = request.args.get('start')
    due = request.args.get('due')
    if terms:
        current_app.logger.debug('looking for memes with terms: %s' % terms)
        query = Action.search_query(terms)
    else:
        # this produces an SAWarning when db is empty (empty sequence)
        query = Action.query
        terms = False
    if finish:
        f_start, f_end = parse_iso8601(finish)
        current_app.logger.debug('getting actions finished between %s and %s' % (f_start, f_end))
        query = query.filter(Action.finish_time.between(f_start, f_end))
    if start:
        f_start, f_end = parse_iso8601(start)
        current_app.logger.debug('getting actions finished between %s and %s' % (f_start, f_end))
        query = query.filter(Action.start_time.between(f_start, f_end))
    if due:
        f_start, f_end = parse_iso8601(due)
        current_app.logger.debug('getting actions finished between %s and %s' % (f_start, f_end))
        query = query.filter(Action.due.between(f_start, f_end))
    query = query.order_by(Action.modified.desc())
    if not terms and not finish:
        query = query.limit(10)
    return query, terms
コード例 #6
0
ファイル: testmodels.py プロジェクト: findgriffin/hactar
 def test_timezones(self):
     due0 = dtime(2013, 11, 2, 5, 3, 3, tzinfo=pytz.utc)
     start0 = dtime(2013, 11, 1, 20, 20, 15, tzinfo=pytz.utc)
     finish0 = dtime(2013, 11, 3, 5, 9, 3, tzinfo=pytz.utc)
     action0 = Action(self.text, due=due0, start=start0, finish=finish0)
     self.assertEqual(action0.dt('due', 'utc').day, 2)
     self.assertEqual(action0.dt('start_time', 'utc').hour, 20)
     self.assertEqual(action0.dt('finish_time', 'utc').hour, 5)
     self.assertEqual(action0.dt('due', 'local').day, 1)
     self.assertEqual(action0.dt('start_time', 'local').hour, 13)
     self.assertEqual(action0.dt('finish_time', 'local').hour, 22)
コード例 #7
0
ファイル: testmodels.py プロジェクト: findgriffin/hactar
 def test_create(self):
     action0 = Action(self.text)
     self.assertEqual(action0.text, self.text)
     self.assertEqual(action0.due, None)
     self.assertEqual(action0.start_time, None)
     self.assertEqual(action0.finish_time, None)
     self.assertEqual(action0.is_task, False)
     self.assertEqual(action0.is_event, False)
     self.assertEqual(action0.completed, False)
     self.assertEqual(action0.duration, None)
     self.assertEqual(action0.latent, False)
     self.assertEqual(action0.ongoing, False)
コード例 #8
0
ファイル: testmodels.py プロジェクト: findgriffin/hactar
 def test_latent(self):
     due_date = get_day(1)
     action0 = Action(self.text, due=due_date)
     self.assertEqual(action0.text, self.text)
     self.assertEqual(action0.due, due_date)
     self.assertEqual(action0.start_time, None)
     self.assertEqual(action0.finish_time, None)
     self.assertEqual(action0.is_task, True)
     self.assertEqual(action0.is_event, False)
     self.assertEqual(action0.completed, False)
     self.assertEqual(action0.duration, None)
     self.assertEqual(action0.latent, True)
     self.assertEqual(action0.ongoing, False)
コード例 #9
0
ファイル: testmodels.py プロジェクト: findgriffin/hactar
 def test_timezones(self):
     due0 = dtime(2013, 11, 2, 5, 3, 3, tzinfo=pytz.utc)
     start0 = dtime(2013, 11, 1, 20, 20, 15, tzinfo=pytz.utc)
     finish0 = dtime(2013, 11, 3, 5, 9, 3, tzinfo=pytz.utc)
     action0 = Action(self.text, due=due0, start=start0,
             finish=finish0)
     self.assertEqual(action0.dt('due', 'utc').day, 2)
     self.assertEqual(action0.dt('start_time', 'utc').hour, 20)
     self.assertEqual(action0.dt('finish_time', 'utc').hour, 5)
     self.assertEqual(action0.dt('due', 'local').day, 1)
     self.assertEqual(action0.dt('start_time', 'local').hour, 13)
     self.assertEqual(action0.dt('finish_time', 'local').hour, 22)
コード例 #10
0
ファイル: testmodels.py プロジェクト: findgriffin/hactar
 def test_metadata_timezones(self):
     self.skipTest('added/modified fields are not timezone aware')
     action0 = Action(self.text)
     hour_utc = dtime.utcnow().hour
     hour_local = dtime.now().hour
     self.assertEqual(action0.dt('added', 'utc').hour, hour_utc)
     self.assertEqual(action0.dt('modified', 'utc').hour, hour_utc)
     self.assertEqual(action0.dt('added', 'local').hour, hour_local)
     self.assertEqual(action0.dt('modified', 'local').hour, hour_local)
コード例 #11
0
ファイル: testmodels.py プロジェクト: findgriffin/hactar
 def test_completed(self):
     due_date = get_day(-1)
     start_date = get_day(-2)
     finish_date = start_date + tdelta(days=1)
     action0 = Action(self.text,
                      due=due_date,
                      start=start_date,
                      finish=finish_date)
     self.assertEqual(action0.text, self.text)
     self.assertEqual(action0.due, due_date)
     self.assertEqual(action0.start_time, start_date)
     self.assertEqual(action0.finish_time, finish_date)
     self.assertEqual(action0.is_task, True)
     self.assertEqual(action0.is_event, True)
     self.assertEqual(action0.completed, True)
     self.assertEqual(action0.duration, tdelta(days=1))
     self.assertEqual(action0.latent, False)
     self.assertEqual(action0.ongoing, False)
コード例 #12
0
def post_actions():
    """This is actually kind of the home page."""
    if not session.get('logged_in'):
        abort(401)
    newargs = {}
    form = request.form

    def parse_date_field(name):
        try:
            if len(form[name]) < 3:
                raise KeyError  # dont give to parser if it's not a datetime
            newargs[name] = parse_user_dt(form[name])
        except ValueError:
            flash('Unable to parse %s date: %s' % (name, form[name]))
        except KeyError as err:
            current_app.logger.debug(err.message)
            pass

    newargs['text'] = unicode(form['what'])
    parse_date_field('due')
    parse_date_field('start')
    parse_date_field('finish')
    if 'points' in form:
        newargs['points'] = int(form['points'])
    if 'just_finished' in form and 'finish' not in newargs:
        newargs['finish'] = dtime.now()
    try:
        newaction = Action(**newargs)
        db.session.add(newaction)
        db.session.commit()
        flash('New action was successfully added')
    except ValueError as err:
        current_app.logger.debug('got error: %s' % err.message)
        db.session.rollback()
        flash(err.message)
    except IntegrityError as err:
        db.session.rollback()
        if 'primary key must be unique' in err.message.lower():
            current_app.logger.debug("can't add duplicate action: %s" % uri)
            flash('action with that URI or description already exists')
        else:
            abort(500)