blog

Temporarily disable comment model

Author
Maarten 'Vngngdn' Vangeneugden
Date
Oct. 19, 2017, 5:59 a.m.
Hash
157c956b2575553e2a52ceaea98ed5fcee36e858
Parent
bb491800b73980c262e7e68f93529f36a56a4076
Modified file
models.py

models.py

5 additions and 5 deletions.

View changes Hide changes
1
1
from django.db import models
2
2
import datetime
3
3
import os
4
4
5
5
def post_title_directory(instance, filename):
6
6
    """ Files will be uploaded to MEDIA_ROOT/blog/<year of publishing>/<blog
7
7
    title>
8
8
    The blog title is determined by the text before the first period (".") in
9
9
    the filename. So if the file has the name "Trains are bæ.en.md", the file
10
10
    will be stored in "blog/<this year>/Trains are bæ". Name your files
11
11
    properly!
12
12
    It should also be noted that all files are stored in the same folder if they
13
13
    belong to the same blogpost, regardless of language. The titles that are
14
14
    displayed to the user however, should be the titles of the files themselves,
15
15
    which should be in the native language. So if a blog post is titled
16
16
    "Universities of Belgium", its Dutch counterpart should be titled
17
17
    "Universiteiten van België", so the correct title can be derived from the
18
18
    filename.
19
19
20
20
    Recommended way to name the uploaded file: "<name of blog post in language
21
21
    it's written>.md". This removes the maximum amount of redundancy (e.g. the
22
22
    language of the file can be derived from the title, no ".fr.md" or something
23
23
    like that necessary), and can directly be used for the end user (the title
24
24
    is what should be displayed).
25
25
    """
26
26
    english_file_name = os.path.basename(instance.english_file.name) # TODO: Test if this returns the file name!
27
27
    english_title = english_file_name.rpartition(".")[0] 
28
28
    year = datetime.date.today().year
29
29
30
30
    return "blog/{0}/{1}/{2}".format(year, english_title, filename)
31
31
32
32
class Post(models.Model):
33
33
    """ Represents a blog post. The title of the blog post is determnined by the name
34
34
    of the files.
35
35
    A blog post can be in 5 different languages: German, Spanish, English, French,
36
36
    and Dutch. For all these languages, a seperate field exists. Thus, a
37
37
    translated blog post has a seperate file for each translation, and is
38
38
    seperated from Django's internationalization/localization system.
39
39
    Only the English field is mandatory. The others may contain a value if a
40
40
    translated version exists, which will be displayed accordingly.
41
41
    """
42
42
    published = models.DateTimeField(auto_now_add=True)
43
43
    english_file = models.FileField(upload_to=post_title_directory, unique=True, blank=False)
44
44
    dutch_file = models.FileField(upload_to=post_title_directory, blank=True)
45
45
    french_file = models.FileField(upload_to=post_title_directory, blank=True)
46
46
    german_file = models.FileField(upload_to=post_title_directory, blank=True)
47
47
    spanish_file = models.FileField(upload_to=post_title_directory, blank=True)
48
48
    # Only the English file can be unique, because apparantly, there can't be
49
49
    # two blank fields in a unique column. Okay then.
50
50
51
51
    def __str__(self):
52
52
        return os.path.basename(self.english_file.name).rpartition(".")[0]
53
53
54
54
class Comment(models.model):
55
-
    """ Represents a comment on a blog post.
+
55
    """ Represents a comment on a blog post.
56
56
57
57
    Comments are not linked to an account or anything, I'm trusting the
58
58
    commenter that he is honest with his credentials. That being said:
59
59
    XXX: Remember to put up a notification that comments are not checked for
60
60
    identity, and, unless verified by a trustworthy source, cannot be seen as
61
61
    being an actual statement from the commenter.
62
62
    Comments are linked to a blogpost, and are not filtered by language. (So a
63
63
    comment made by someone reading the article in Dutch, that's written in
64
64
    Dutch, will show up (unedited) for somebody whom's reading the Spanish
65
65
    version.
66
66
    XXX: Remember to notify (tiny footnote or something) that comments showing
67
67
    up in a foreign language is by design, and not a bug.
68
68
    """
69
69
    date = models.DateTimeField(auto_now_add=True)
70
-
    name = models.TextField()
71
-
    mail = models.EmailField()
72
-
    post = models.ForeignKey(Post) # TODO: Finish this class and the shit...
73
-
+
70
    #name = models.TextField()
+
71
    #mail = models.EmailField()
+
72
    #post = models.ForeignKey(Post) # TODO: Finish this class and the shit...
+
73