Skip to main content

Agora

Agora is a forum for ideas. It is a simple, blog-like application, with support for multiple authors.

It is developed for a class curriculum, and is not intended for real deployment, although it could serve some purpose.

There are two classes–Author and Idea. A forum can have zero or more authors. Each author can have zero or more ideas.

Agora uses SQLAlchemy for a persistence layer. You need a valid SQLAlchemy session to initialize agora.

Usage

Set up SQLAlchemy session

>>> from agora.models import Base

>>> from sqlalchemy import create_engine
>>> from sqlalchemy.orm import scoped_session, sessionmaker

>>> engine = create_engine('sqlite:///:memory:')
>>> Base.metadata.create_all(engine)

>>> DBSession = scoped_session(sessionmaker())
>>> DBSession.configure(bind=engine)

Forum Basics

>>> from agora import Forum
>>> forum = Forum(DBSession)

A new forum has no authors or ideas.

>>> forum.get_authors()
[]
>>> forum.get_ideas()
[]

To add an idea, you first need an author.

To add a new author, pass a username, fullname, and email to the add_author method.

>>> forum.add_author(username='schmoe', fullname='Joe Schmoe', email='schmoe@example.com')
1
>>> forum.add_author(username='misinformation', fullname='Miss Information', email='misinformation@example.com')
2

Notice that the method returns the author’s id.

We now have authors.

>>> forum.get_authors()
[Joe Schmoe, March 02, 2016, Miss Information, March 02, 2016]

You can access authors by id.

>>> forum.get_author(1)
Joe Schmoe, March 02, 2016

To add a new idea, pass a title, idea, and author_id to the add_idea method.

>>> forum.add_idea(title='First Idea!', idea='This is my idea.', author_id=1)
1

>>> forum.add_idea(title='My First Idea!', idea='This is my idea.', author_id=2)
2

>>> forum.add_idea(title='Another Idea!', idea='This is my idea.', author_id=1)
3

>>> forum.add_idea(title='Another Idea!', idea='This is my idea.', author_id=2)
4

We now have ideas.

>>> forum.get_ideas()
[First Idea!, Joe Schmoe, March 02, 2016, My First Idea!, Miss Information, March 02, 2016, Another Idea!, Joe Schmoe, March 02, 2016, Another Idea!, Miss Information, March 02, 2016]

You can access ideas by id.

>>> forum.get_idea(1)
First Idea!, Joe Schmoe, March 02, 2016

You can also access ideas with filters.

>>> forum.get_ideas(filters={'author': forum.get_author(1)})
[First Idea!, Joe Schmoe, March 02, 2016, Another Idea!, Joe Schmoe, March 02, 2016]

>>> forum.get_ideas(filters={'title': 'First Idea!'})
[First Idea!, Joe Schmoe, March 02, 2016]

>>> forum.get_ideas(filters={'title': 'Another Idea!'})
[Another Idea!, Joe Schmoe, March 02, 2016, Another Idea!, Miss Information, March 02, 2016]

>>> forum.get_ideas(filters={'author': forum.get_author(2), 'title': 'Another Idea!'})
[Another Idea!, Miss Information, March 02, 2016]

You can delete ideas by id.

>>> forum.delete_idea(1)
1

>>> forum.get_ideas()
[My First Idea!, Miss Information, March 02, 2016, Another Idea!, Joe Schmoe, March 02, 2016, Another Idea!, Miss Information, March 02, 2016]

Initialize Database

There is a script provided to initialize the database. It is installed into the bin directory of your virtualenv. You must pass it a valid SQLAlchemy database URI.

$ initialize_agora_db <database_uri>

$ initialize_agora_db sqlite:///agora.sqlite

You can also use the script to seed the database with a sample author and two ideas, if you append the word seed to the command.

$ initialize_agora_db sqlite:///agora.sqlite seed

Metadata

Release files for cullerton.agora 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cullerton.agora 0.0.2
File Size Uploaded
cullerton.agora-0.0.2.tar.gz 6.8 kB Details

Release files / cullerton.agora-0.0.2.tar.gz

Download URL cullerton.agora-0.0.2.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b1305b62359bb955828fe025535aa6241a809145752e0ba1cabe99d770dcff03
BLAKE2b-256 checksum
How to use checksums
c837224a156f70503b658f2bdf421f58642902158c9a06a84920b6bdf8580a02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file

0.0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page