actually i need to call this ircbot

so i don't collide with the django dr_botzo
This commit is contained in:
2014-03-16 09:18:17 -05:00
parent 43a73f368f
commit e7b132348f
53 changed files with 0 additions and 0 deletions

View File

View File

@@ -0,0 +1,64 @@
from django.db import models
class StorycraftGame(models.Model):
id = models.IntegerField(primary_key=True)
round_mode = models.IntegerField()
game_length = models.IntegerField()
line_length = models.IntegerField()
random_method = models.IntegerField()
lines_per_turn = models.IntegerField()
status = models.CharField()
owner_nick = models.CharField()
owner_userhost = models.CharField()
start_time = models.DateTimeField()
end_time = models.DateTimeField()
class Meta:
db_table = 'storycraft_game'
ordering = ['id']
managed = False
def __unicode__(self):
"""Return a terse summary of the vital game info."""
return '#{0:d} - created on {1:s} by {2:s}, {3:s}'.format(self.id, self.start_time, self.owner_nick, self.status)
def is_completed(self):
"""Return if this game is completed."""
return self.status == 'COMPLETED' and self.end_time
class StorycraftPlayer(models.Model):
id = models.IntegerField(primary_key=True)
game = models.ForeignKey(StorycraftGame)
nick = models.CharField()
userhost = models.CharField()
class Meta:
db_table = 'storycraft_player'
ordering = ['id']
managed = False
def __unicode__(self):
"""Return the nick!user@host."""
return '{0:s}!{1:s}'.format(self.nick, self.userhost)
class StorycraftLine(models.Model):
id = models.IntegerField(primary_key=True)
game = models.ForeignKey(StorycraftGame)
player = models.ForeignKey(StorycraftPlayer)
line = models.TextField()
time = models.DateTimeField()
class Meta:
db_table = 'storycraft_line'
ordering = ['id']
managed = False
def __unicode__(self):
"""Just return the line."""
return '{0:s}'.format(self.line)
# vi:tabstop=4:expandtab:autoindent

View File

@@ -0,0 +1,8 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('storycraft.views',
(r'^$', 'index'),
(r'^games/(?P<game_id>\d+)/$', 'game_index', dict(), 'game_index'),
)
# vi:tabstop=4:expandtab:autoindent

View File

@@ -0,0 +1,48 @@
from django.contrib import messages
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
def index(request):
"""Display a short list of each game (and its summary) in the system.
TODO: add paginator.
"""
games = StorycraftGame.objects.all()
return render_to_response('storycraft/index.html', {'games': games}, context_instance=RequestContext(request))
def game_index(request, game_id):
"""Display one individual game's details, including the story, if it's done."""
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 = []
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