From be4fbda2a631381c2704c5599cd7a1d580e3e32e Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 4 Nov 2016 09:00:03 -0400 Subject: [PATCH] more --- .../nntpchan/nntpchan/frontend/models.py | 25 ++++++++++++++++--- .../django/nntpchan/nntpchan/frontend/util.py | 5 ++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 contrib/frontends/django/nntpchan/nntpchan/frontend/util.py diff --git a/contrib/frontends/django/nntpchan/nntpchan/frontend/models.py b/contrib/frontends/django/nntpchan/nntpchan/frontend/models.py index 6d830c2..989e012 100644 --- a/contrib/frontends/django/nntpchan/nntpchan/frontend/models.py +++ b/contrib/frontends/django/nntpchan/nntpchan/frontend/models.py @@ -1,10 +1,29 @@ from django.db import models -class Attachment(models.Model): - pass +from . import util +class Attachment(models.Model): + filename = models.CharField(max_length=256) + filepath = models.CharField(max_length=256) + width = models.IntegerField() + height = models.IntegerField() + class Post(models.Model): - pass + msgid = models.CharField(max_length=256, primary_key=True) + reference = models.CharField(max_length=256) + message = models.TextField() + subject = models.CharField(max_length=256) + name = models.CharField(max_length=256) + pubkey = models.CharField(max_length=64) + signature = models.CharField(max_length=64) + + def get_absolute_url(self): + from django.urls import reverse + op = self.msgid + if self.reference != self.msgid: + op = self.reference + + return reverse('frontend.views.threadpage', args=[util.hashid(op)]) class Board(models.Model): pass diff --git a/contrib/frontends/django/nntpchan/nntpchan/frontend/util.py b/contrib/frontends/django/nntpchan/nntpchan/frontend/util.py new file mode 100644 index 0000000..53c2d05 --- /dev/null +++ b/contrib/frontends/django/nntpchan/nntpchan/frontend/util.py @@ -0,0 +1,5 @@ +import hashlib + + +def hashid(msgid): + return hashlib.sha1().hexdigest('%s' % msgid).decode('ascii')