Esempio n. 1
0
def edit_date_query(new_value, entry_id):
    """Update a row's date column with a new value.

    :param new_value: string that is date format
    :param entry_id: entry's primary key
    :return: edited entry
    """
    q = Entry.update(date=new_value).where(Entry.id == entry_id).execute()
    return Entry.select().where(Entry.id == entry_id).get()
Esempio n. 2
0
def edit_notes_query(new_value, entry_id):
    """Update a row's ntoes column with a new value.

    :param new_value: string
    :param entry_id: entry's primary key
    :return: edited entry
    """
    q = Entry.update(notes=new_value).where(Entry.id == entry_id).execute()
    return Entry.select().where(Entry.id == entry_id).get()
Esempio n. 3
0
def edit_time_query(new_value, entry_id):
    """Update a row's time_spent column with a new value.

    :param new_value: int
    :param entry_id: entry's primary key
    :return: edited entry
    """
    q = Entry.update(time_spent=new_value).where(
        Entry.id == entry_id).execute()
    return Entry.select().where(Entry.id == entry_id).get()
Esempio n. 4
0
def add_route():
    """Add an entry"""

    Entry.create(user=get_user(),
                 date=get_date(),
                 title=get_title(),
                 time_spent=get_time(),
                 notes=get_notes())
    clear_screen()
    input("The entry has been added!\n")
    return None
Esempio n. 5
0
    def setUpClass(cls):
        cls.test_db = SqliteDatabase(":memory:")
        test_db.bind_ctx(Entry)

        cls.test_db.connect()
        test_db.create_tables([Entry], safe=True)

        Entry.create(
            user='******',
            date='12/12/2002',
            title='Building additional pylons',
            time_spent=32,
            notes='' 
    )
Esempio n. 6
0
def del_entry(user_id):
    """Delte a row

    :param user_id: selected entry's primary key
    :return: None
    """
    q = Entry.get(Entry.id == user_id)
    q.delete_instance()
    return None
Esempio n. 7
0
def time_search(search):
    """Search the DB for all entries that match time spent.

    :param search: int containing user's search criteria
    :return: a list of the found entries
    """

    entries = Entry.select().order_by(
        Entry.date.desc()).where(Entry.time_spent == (search))
    return entries
Esempio n. 8
0
def user_search(search):
    """Search the DB for all entries that match user.

    :param search: a string containing user's search criteria
    :return: a list of the found entries
    """

    entries = Entry.select().order_by(Entry.date.desc()).where(
        Entry.user.contains(search))
    return entries
Esempio n. 9
0
def date_search(search):
    """Search the DB for all entries that match date(s)

    :param search: a string or list containing user's search criteria
    :return: a list of the found entries
    """

    entries = []

    if type(search) == list:
        for range_date in search:
            try:
                entries.append(
                    Entry.select().where(Entry.date == range_date).get())
            except Entry.DoesNotExist:
                continue
        return entries
    else:
        return Entry.select().where(Entry.date.contains(search))
Esempio n. 10
0
def keyword_search(search):
    """Search the DB for all entries that match keyword.

    :param search: a string containing user's search criteria
    :return: a list of the found entries
    """

    entries = []
    for entry in Entry.select().order_by(
            Entry.date.desc()).where((Entry.title.contains(search))
                                     | (Entry.notes.contains(search))):
        entries.append(entry)
    return entries
Esempio n. 11
0
    def test_edit_value(self, mock_input): 

        result = edit_value(self.entry_id, 'Title', get_title, edit_title_query)
        compare = Entry.select().where(Entry.title.contains('Rolling in the dough')).get()
        self.assertEqual(result.id, compare.id)
Esempio n. 12
0
 def test_edit_time(self):
     result = edit_time_query(35, 1)
     compare = Entry.select().where(Entry.id == 1).get()
     self.assertEqual(result.id, compare.id)
Esempio n. 13
0
 def test_edit_notes(self):
     result = edit_notes_query('Tidying up!', 1)
     compare = Entry.select().where(Entry.id == 1).get()
     self.assertEqual(result.id, compare.id)        
Esempio n. 14
0
 def test_date_list_search(self):
     result = date_search(['12/12/2002', '13/12/2002', '14/12/2002'])
     compare = Entry.select().where(Entry.date.contains('12/12/2002'))
     self.assertEqual(len(result), len(compare))
Esempio n. 15
0
 def test_edit_date(self):
     result = edit_date_query('12/10/2003', 1)
     compare = Entry.select().where(Entry.id == 1).get()
     self.assertEqual(result.id, compare.id)
Esempio n. 16
0
 def test_user_search(self):
     result = user_search('Jay')
     compare = Entry.select().where(Entry.user.contains('Jay'))
     self.assertEqual(len(result), len(compare))
Esempio n. 17
0
 def test_time_search(self):
     result = time_search(32)
     compare = Entry.select().where(Entry.time_spent == 32)
     self.assertEqual(len(result), len(compare))
Esempio n. 18
0
 def test_keyword_search(self):
     result = keyword_search('pylons')
     compare = Entry.select().where(Entry.title.contains('pylons'))
     self.assertEqual(len(result), len(compare))