»
S
I
D
E
B
A
R
«
WriteBite's Django Architecture
Feb 11th, 2010 by Ahmed

WriteBite is going open-source soon! Follow us on GitHub to track the code development of the site. Once we publish our project code, we hope others will use our model to make other interesting writing contest sites. The possibilities are endless.

The following document is an introduction to WriteBite’s Django-powered architecture. As the site’s code base grows, we’ll be updating this page as necessary.

Introduction to Django and the MTV

If you are unfamiliar with Django’s MTV setup (model-template-view), you should read this intro to Django.  From here on this document assumes familiarity with Django’s MTV setup.

Models:

  • Person: Extends Django’s User model and stores user info about the user, such as username, email address, join date, and much more. Note that user’s password is not stored in the model because authentication is done using Django User model and built-in authentication.
  • Rant: Stores rants. This includes their content, title, author, publication status, and url. The url field is basically the rant’s title processed as URL friendly (see makeRant). The rant content is stored as raw HTML so that it can be outputted with formatting latter.
  • CommentRant: Simple stores comments made on RANTS.
  • ComentUser: Stores comments made on users.
  • VoteRant: Keeps track of user’s voting record for rants. This is to avoid users from voting more than once on a rant.
  • VoteUser: Keeps track of user’s voting record for USERS. Users will be able to rate other users in the future.
  • VoteComment: Keeps track of user’s voting record for comments. Users will be able to rate comments in the future.
  • Topic: Stores the weekly topic, its publication date, and its winners. Note that weekly topics are updated manually via the site’s admin panel.

Main Templates:

  • base.html: This is our base template. All other templates inherit this one. It contains blocks for the title, header, top-right navigation (based on whether the user is logged in or not), body, footer. These content blocks can be replaced by other templates that inherit base.html.
  • index.html: Our home page. Displays top 5 rants and some information about last week’s topic and winners.
  • login.html: Displays a form to login the user (username and password)
  • register.html: Displays a form to register the user (username, password and email)
  • singlerant.html: Displays a single rant with metadata.
  • makerant.html: Displays form (TinyMCE) for rant creation.
  • profile.html: Displays user profile.

Views:

  • index: Handles processing for the main page, such as getting the top 5 rants from the DB and returning them. It also returns data about last week’s topic and contest winners.
  • register: Handles registration forms. Creates a new User and Person using built-in Django views with some customization for our Person model.
  • makeRant: Processes and adds rants to the DB. Processing including checking for a valid form and parsing the rant title into a clean url (no spaces).
  • singleRant: Handles the display of a single rant. Also displays rants comments.
  • voteRant: Handles voting for a rant. Checks to see if user has voted before. If not, let them vote and change the rant’s rating.
  • logout_view: Logs out the user with a Django function.

Note: I used the a built-in decorator called @login_required to check to see if a user is logged in before allowing voting and rant creation.

Other Python Files: There are a few other default .py files that come with Django and are not of interest to this document. Their are however three custom .py files:

  • forms.py
  • auth_login.py
  • auth_backends.py

See urls.py for an insight as to how our urls are mapped to our views. Simply put, a regex check is done on urls and when a match is found, python is sent to a view, sometimes with strings from urls being passed into views as parameters (other times the request object contains all the data that the view needs, i.e. POST data)

WriteBite 2.0 Update
Sep 18th, 2009 by Ahmed

Hello WriteBite users,

Glad to see that some of you are still with us!

It’s been a while since we announced the temporary suspension of the Cash For Rants contest. Since then, we’ve been working (admittedly on and off) to improve the contest and the site design.

Here are some of the ideas we have for WriteBite 2.0:

  • Rant themes: Each week, WriteBite will announce a certain rant theme that users’ rants will adhere to.
  • Voting for weekly themes: Possible rant themes for the following week will be posted in advance by WriteBite and voted on by users. Users will have a large say in choosing the following week’s rant theme.
  • Rant-by-Rant moderation: WriteBite editors will review all rants before they are published on the site. Rants must be unique, interesting, and on-topic with the week’s theme in order to be accepted.
  • Encourage use of images: All rants should have at least one relevant image (preferably near the top). Editors may add or edit images before a rant is accepted and published.
  • Increased weekly cash prizes: The monthly cash prize budget will increase by almost 10%, from $220 to $240. The #1 winner, based on user votes, will receive $30, #2 will get $20, and #3 will get $10.
  • Give away extra prizes along with cash: Some weeks, sponsors will “sponsor” our rant contest by giving away extra prizes or coupons to contest winners. In return, we will run advertisements on WriteBite for these sponsors.

If you would like to suggest a sponsor or would like to become a sponsor of our Cash For Rants contest, please contact us at ads@writebite.com.

We would love it if you guys could provide us some feedback on our ideas. A WriteBite 2.0 beta is in progress and private invites may be sent to users who provide particularly helpful commentary.

Thanks,

WriteBite Team

»  Substance: WordPress   »  Style: Ahren Ahimsa