corrections
[turniej.git] / apps / poetry / models.py
index b0d15b1..63bf8f2 100644 (file)
@@ -30,7 +30,7 @@ class Poet(models.Model):
             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         os.chdir(curdir)
         stdout, stderr = proc.communicate()
             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:
         slug = get_hash(text)
         title = ''
         if self.first_line_title:
@@ -53,6 +53,9 @@ class Poet(models.Model):
             p.save()
         return self.poem_set.filter(for_contest=True)
 
             p.save()
         return self.poem_set.filter(for_contest=True)
 
+    def contest_poems(self):
+        return self.poem_set.filter(in_contest=True)
+
 
 class Poem(models.Model):
     slug = models.SlugField(max_length=50, db_index=True)
 
 class Poem(models.Model):
     slug = models.SlugField(max_length=50, db_index=True)
@@ -68,8 +71,7 @@ class Poem(models.Model):
 
     def __unicode__(self):
         oneliner = u"%s, %s" % (self.poet.name, self.pretty_title())
 
     def __unicode__(self):
         oneliner = u"%s, %s" % (self.poet.name, self.pretty_title())
-        if not self.title:
-            oneliner += u" [%s…]" % self.text[:20]
+        oneliner += u" [%s…]" % (u" ".join(self.text.split()[:5]))
         return oneliner
 
     def get_absolute_url(self):
         return oneliner
 
     def get_absolute_url(self):