Web (Storycraft): format the story a bit by adding <p> tags, for readability

This commit is contained in:
Brian S. Stephan 2011-02-20 19:35:37 -06:00
parent 07b76f3e5e
commit 865a39204f
3 changed files with 25 additions and 13 deletions

View File

@ -137,11 +137,8 @@ body {
line-height: 1.5em;
}
.gamestory p:first-letter {
font-size: 3.5em;
line-height: 0.8em;
float: left;
margin: 0 3px 3px 0;
.gamestory p {
margin-bottom: 20px;
}
#footer {

View File

@ -3,6 +3,8 @@ from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.utils.html import escape
from django.utils.safestring import mark_safe
from storycraft.models import StorycraftGame, StorycraftLine, StorycraftPlayer
@ -21,7 +23,26 @@ def game_index(request, game_id):
game = get_object_or_404(StorycraftGame, pk=game_id)
players = StorycraftPlayer.objects.filter(game=game.id)
lines = StorycraftLine.objects.filter(game=game.id)
pretty_story = []
return render_to_response('storycraft/game_index.html', {'game': game, 'players': players, 'lines': lines}, context_instance=RequestContext(request))
if game.is_completed():
# make a HTML-formatted string that is the entire story, in
# which we've added paragraphs and such.
period_count = 0
pretty_story.append('<p>')
for line in lines:
period_count = period_count + line.line.count('.')
if period_count > 6:
period_count = 0
split = line.line.rsplit('.', 1)
pretty_story.append('<span title="' + line.player.nick + ' @ ' + line.time + '">' + escape(split[0]) + '.</span></p>')
pretty_story.append('<p><span title="' + line.player.nick + ' @ ' + line.time + '">' + escape(split[1]) + '</span>')
else:
pretty_story.append('<span title="' + line.player.nick + ' @ ' + line.time + '">' + escape(line.line) + '</span>')
pretty_story.append('</p>')
pretty_story_text = ' '.join(pretty_story)
mark_safe(pretty_story_text)
return render_to_response('storycraft/game_index.html', {'game': game, 'players': players, 'lines': lines, 'prettystory': pretty_story_text}, context_instance=RequestContext(request))
# vi:tabstop=4:expandtab:autoindent

View File

@ -1,13 +1,7 @@
{% autoescape on %}
<div class="storyblock">
{% if game.is_completed %}
<div class="gamestory">
<p>
{% for line in lines %}
<span title="{{ line.player.nick }} @ {{ line.time }}">{{ line }}</span>
{% endfor %}
</p>
</div>
<div class="gamestory">{{ prettystory|safe }}</div>
{% else %}
<div class="gamenostory">
<p>This game has not been completed yet. Come back later (or get to work).</p>