Skip to content

Commit

Permalink
Added the story form view and template
Browse files Browse the repository at this point in the history
  • Loading branch information
croach committed Dec 15, 2012
1 parent 7691055 commit 6d55a67
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions stories/templates/stories/story.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "base.html" %}

{% block content %}
<form action="/story/" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
{% endblock content %}
16 changes: 14 additions & 2 deletions stories/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import datetime

from django.shortcuts import render_to_response
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.utils.timezone import utc

from stories.models import Story
from stories.forms import StoryForm

def score(story, gravity=1.8, timebase=120):
points = (story.points - 1)**0.8
Expand All @@ -19,4 +21,14 @@ def top_stories(top=180, consider=1000):

def index(request):
stories = top_stories(top=30)
return render_to_response('stories/index.html', {'stories': stories})
return render(request, 'stories/index.html', {'stories': stories})

def story(request):
if request.method == 'POST':
form = StoryForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/')
else:
form = StoryForm()
return render(request, 'stories/story.html', {'form': form})

0 comments on commit 6d55a67

Please sign in to comment.