X-Git-Url: https://git.mdrn.pl/turniej.git/blobdiff_plain/c9d036f4b17b01b352e3a1d20b31fac6fff9b26b..43cf331626ab12c2f76d19c0c545b0a0ae685db6:/apps/poetry/models.py?ds=sidebyside diff --git a/apps/poetry/models.py b/apps/poetry/models.py index 244538a..ef8bf94 100644 --- a/apps/poetry/models.py +++ b/apps/poetry/models.py @@ -3,6 +3,7 @@ import os import subprocess from django.db import models from django.core.urlresolvers import reverse +from django.conf import settings from poetry.utils import get_hash @@ -29,7 +30,7 @@ class Poet(models.Model): stdout=subprocess.PIPE, stderr=subprocess.PIPE) os.chdir(curdir) stdout, stderr = proc.communicate() - text = stdout.decode("utf-8")[:1000] + text = unicode(stdout, "utf-8", errors="ignore")[:1000] slug = get_hash(text) title = '' if self.first_line_title: @@ -44,6 +45,14 @@ class Poet(models.Model): ) return poem + def make_for_contest(self): + assert not self.poem_set.filter(for_contest=True).exists() + for i in range(settings.POETRY_POEMS_FOR_CONTEST): + p = self.write() + p.for_contest = True + p.save() + return self.poem_set.filter(for_contest=True) + class Poem(models.Model): slug = models.SlugField(max_length=50, db_index=True)