This repository has been archived by the owner on Aug 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
{% if request.user.is_authenticated %} | ||
<form method="POST"> | ||
{{ form.body }} | ||
<input type="submit" value="Post Tweet" /> | ||
</form> | ||
{% else %} | ||
<a href="{% url login %}">Log in to post a tweet</a> | ||
{% endif %} | ||
<ul> | ||
{% for tweet in tweets %} | ||
<li> | ||
<span class="username">{{ tweet.user.username }}</span> | ||
<span class="body">{{ tweet.body }}</span> | ||
</li> | ||
{% empty %} | ||
<li>There are no tweets yet. Make sure to post one!</li> | ||
{% endfor %} | ||
</ul> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from django import forms | ||
|
||
class TweetForm(forms.Form): | ||
body = forms.CharField(max_length=140) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.conf.urls.defaults import patterns, url | ||
|
||
urlpatterns = patterns('tweets.views', | ||
url('^/?$', 'timeline', name='timeline'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import uuid | ||
|
||
from django.shortcuts import render_to_response | ||
from django.template import RequestContext | ||
from django.http import HttpResponseRedirect | ||
from django.core.urlresolvers import reverse | ||
|
||
from tweets.forms import TweetForm | ||
|
||
from lib.database import save_tweet, get_timeline | ||
|
||
def timeline(request): | ||
form = TweetForm(request.POST or None) | ||
if request.user['is_authenticated'] and form.is_valid(): | ||
tweet_id = str(uuid.uuid1()) | ||
save_tweet(tweet_id, request.user['id'], { | ||
'id': tweet_id, | ||
'user_id': request.user['id'], | ||
'body': form.cleaned_data['body'], | ||
}) | ||
return HttpResponseRedirect(reverse('timeline')) | ||
tweets = get_timeline(request.user['id']) | ||
context = { | ||
'form': form, | ||
'tweets': tweets, | ||
} | ||
return render_to_response('tweets/timeline.html', context, | ||
context_instance=RequestContext(request)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters