예제 #1
0
def get_entry_by_id(user):
    entries = JournalEntry.select().where(JournalEntry.author == user)
    if not entries:
        print("there are no journals")
    elif entries:
        entry_id = int(input("choose any entry id"))
        entry = JournalEntry.select().where(JournalEntry.id == entry_id).get()
        print("-" * 20)
        print(entry.content)
        print("-" * 20)
예제 #2
0
def get_all_entries(user):
    entries = JournalEntry.select().where(JournalEntry.author == user)

    print("-" * 20)
    for entry in entries:
        print(entry.id, entry.timestamp, entry.content[:20], "...")
    print("-" * 20)
예제 #3
0
def delete_journal(user, id):
    entry = JournalEntry.select().where(JournalEntry.id == id).get()
    print("Delete the journal--", id)
    a = input("(y/n)-->")
    if a == "y":
        entry.delete_instance()
        print("Entry deleted")
    elif a == "n":
        print("Journal not deleted")
        return user.get()
 def test_journal_entry_creation(self):
     """Test creating a JournalEntry"""
     with test_database(TEST_DB, (User, JournalEntry)):
         UserModelTestCase.create_users()
         user = User.select().get()
         JournalEntry.create(
             user=user,
             title='Testing Journal Entries',
             date=datetime.datetime.now().strftime('%Y-%m-%d'),
             time_spent='22',
             what_i_learned='Hopefully, I learn if this works or not!',
             resources_to_remember='teamtreehouse.com')
         self.assertEqual(JournalEntry.select().count(), 1)
         self.assertEqual(JournalEntry.user, user)
    def test_journal_entry_create(self):
        """Test can create new JournalEntry, redirects to homepage, and adds to the database."""
        journal_entry_data = {
            'title':
            'testing new journal entries',
            'date':
            datetime.datetime.now().strftime('%Y-%m-%d'),
            'time_spent':
            '2',
            'what_i_learned':
            'how to test flask views',
            'resources_to_remember':
            'teamtreehouse.com, stackoverflow.com, flask.pocoo.org'
        }
        with test_database(TEST_DB, (User, JournalEntry)):
            UserModelTestCase.create_users(1)
            self.app.post('/login', data=USER_DATA)

            journal_entry_data['user'] = User.select().get()
            rv = self.app.post('/entry', data=journal_entry_data)
            self.assertEqual(rv.status_code, 302)
            self.assertEqual(rv.location, 'http://localhost/')
            self.assertEqual(JournalEntry.select().count(), 1)
예제 #6
0
def title_exists(form, field):
    if JournalEntry.select().where(JournalEntry.title**field.data).exists():
        raise ValidationError('An entry with that title already exists.')
예제 #7
0
def get_entry_by_id(id):
    entry = JournalEntry.select().where(JournalEntry.id == id).get()
    print("-" * 20)
    print(entry.content)
    print("-" * 20)