From 9b7fbbd51b2ce9d877414b0289e06fd3b69cf05f Mon Sep 17 00:00:00 2001
From: Geert Kapteijns <ghkapteijns@gmail.com>
Date: Wed, 14 Dec 2016 23:16:43 +0100
Subject: [PATCH] Define THESIS_TYPES in ThesisLink model itself

This is recommended. Also give names like
MASTER_THESIS = 'MA' to avoid magic strings and allow for easy
reference, e.g. thesis.type = ThesisLink.MASTER_THESIS. This sort
of thing helps in maintainability of the codebase, since if we want
to change the abbreviation to 'MASTER' for some reason, we have it
defined in one place, and not in 100 places in the code.
---
 requirements.txt    |  4 ++++
 theses/factories.py | 10 ++++++++++
 theses/models.py    | 19 +++++++++++--------
 3 files changed, 25 insertions(+), 8 deletions(-)
 create mode 100644 theses/factories.py

diff --git a/requirements.txt b/requirements.txt
index 1dbfb2123..b25c7e2fb 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -10,14 +10,18 @@ django-mptt==0.8.6
 django-simple-captcha==0.5.3
 djangorestframework==3.5.3
 docutils==0.12
+factory-boy==2.7.0
+fake-factory==0.7.2
 feedparser==5.2.1
 imagesize==0.7.1
 Jinja2==2.8
 Markdown==2.6.7
 MarkupSafe==0.23
+pep8==1.7.0
 Pillow==3.4.2
 psycopg2==2.6.2
 Pygments==2.1.3
+python-dateutil==2.6.0
 pytz==2016.7
 requests==2.12.1
 six==1.10.0
diff --git a/theses/factories.py b/theses/factories.py
new file mode 100644
index 000000000..926d1c192
--- /dev/null
+++ b/theses/factories.py
@@ -0,0 +1,10 @@
+import factory
+from . import models
+
+
+class ThesisLinkFactory(factory.django.DjangoModelFactory):
+    class Meta:
+        model = models.ThesisLink
+
+    vetted = True
+    type = models
diff --git a/theses/models.py b/theses/models.py
index 21d717e98..b2bfe6242 100644
--- a/theses/models.py
+++ b/theses/models.py
@@ -8,15 +8,18 @@ from .models import *
 from journals.models import *
 from scipost.models import *
 
-THESIS_TYPES = (
-    ('MA', 'Master\'s'),
-    ('PhD', 'Ph.D.'),
-    ('Hab', 'Habilitation'),
-    )
-thesis_type_dict = dict(THESIS_TYPES)
-
 
 class ThesisLink(models.Model):
+    MASTER_THESIS = 'MA'
+    PHD_THESIS = 'PhD'
+    HABILITATION_THESIS = 'Hab'
+    THESIS_TYPES = (
+        (MASTER_THESIS, 'Master\'s'),
+        (PHD_THESIS, 'Ph.D.'),
+        (HABILITATION_THESIS, 'Habilitation'),
+    )
+    thesis_type_dict = dict(THESIS_TYPES)
+
     """ An URL pointing to a thesis """
     requested_by = models.ForeignKey(
         Contributor, blank=True, null=True,
@@ -26,7 +29,7 @@ class ThesisLink(models.Model):
     vetted_by = models.ForeignKey(
         Contributor, blank=True, null=True,
         on_delete=models.CASCADE)
-    type = models.CharField(max_length=3, choices=THESIS_TYPES)
+    type = models.CharField(choices=THESIS_TYPES)
     discipline = models.CharField(
         max_length=20, choices=SCIPOST_DISCIPLINES,
         default='physics')
-- 
GitLab