From aacfe285fa0bd4fa4d395e292e73a2b4bf52c1d3 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Mon, 27 Apr 2020 16:00:38 +0200
Subject: [PATCH] Rename abbrev to short_name

Close AlekSIS-App-Chronos#70
---
 aleksis/apps/chronos/admin.py                 |  6 ++---
 .../0015_rename_abbrev_to_short_name.py       | 23 +++++++++++++++++++
 aleksis/apps/chronos/models.py                | 10 ++++----
 .../templates/chronos/partials/subject.html   |  2 +-
 .../chronos/partials/subs/subject.html        |  6 ++---
 5 files changed, 34 insertions(+), 13 deletions(-)
 create mode 100644 aleksis/apps/chronos/migrations/0015_rename_abbrev_to_short_name.py

diff --git a/aleksis/apps/chronos/admin.py b/aleksis/apps/chronos/admin.py
index a734e60f..9de7113a 100644
--- a/aleksis/apps/chronos/admin.py
+++ b/aleksis/apps/chronos/admin.py
@@ -151,10 +151,10 @@ admin.site.register(Room, RoomAdmin)
 
 class SubjectAdmin(admin.ModelAdmin):
     def _colour(self, obj):
-        return colour_badge(obj.colour_fg, obj.colour_bg, obj.abbrev,)
+        return colour_badge(obj.colour_fg, obj.colour_bg, obj.short_name, )
 
-    list_display = ("abbrev", "name", "_colour")
-    list_display_links = ("abbrev", "name")
+    list_display = ("short_name", "name", "_colour")
+    list_display_links = ("short_name", "name")
 
 
 admin.site.register(Subject, SubjectAdmin)
diff --git a/aleksis/apps/chronos/migrations/0015_rename_abbrev_to_short_name.py b/aleksis/apps/chronos/migrations/0015_rename_abbrev_to_short_name.py
new file mode 100644
index 00000000..5d79636e
--- /dev/null
+++ b/aleksis/apps/chronos/migrations/0015_rename_abbrev_to_short_name.py
@@ -0,0 +1,23 @@
+# Generated by Django 3.0.5 on 2020-04-27 13:52
+
+from django.db import migrations, models
+from django.db.models import F
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('chronos', '0014_extra_lesson'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='subject',
+            old_name='abbrev',
+            new_name='short_name',
+        ),
+        migrations.AlterModelOptions(
+            name='subject',
+            options={'ordering': ['name', 'short_name']},
+        ),
+    ]
diff --git a/aleksis/apps/chronos/models.py b/aleksis/apps/chronos/models.py
index b0c487c9..d2dc9fa1 100644
--- a/aleksis/apps/chronos/models.py
+++ b/aleksis/apps/chronos/models.py
@@ -390,9 +390,7 @@ class TimePeriod(ExtensibleModel):
 
 
 class Subject(ExtensibleModel):
-    abbrev = models.CharField(
-        verbose_name=_("Abbreviation of subject in timetable"), max_length=10, unique=True,
-    )
+    short_name = models.CharField(verbose_name=_("Short name of subject"), max_length=10, unique=True)
     name = models.CharField(verbose_name=_("Long name of subject"), max_length=30, unique=True)
 
     colour_fg = models.CharField(
@@ -409,10 +407,10 @@ class Subject(ExtensibleModel):
     )
 
     def __str__(self) -> str:
-        return "{} ({})".format(self.abbrev, self.name)
+        return "{} ({})".format(self.short_name, self.name)
 
     class Meta:
-        ordering = ["name", "abbrev"]
+        ordering = ["name", "short_name"]
 
 
 class Room(ExtensibleModel):
@@ -471,7 +469,7 @@ class Lesson(ExtensibleModel, GroupPropertiesMixin, TeacherPropertiesMixin):
     def __str__(self):
         return "{}, {}, {}".format(
             format_m2m(self.groups),
-            self.subject.abbrev,
+            self.subject.short_name,
             format_m2m(self.teachers),
         )
 
diff --git a/aleksis/apps/chronos/templates/chronos/partials/subject.html b/aleksis/apps/chronos/templates/chronos/partials/subject.html
index 9bfc42ee..e326c75a 100644
--- a/aleksis/apps/chronos/templates/chronos/partials/subject.html
+++ b/aleksis/apps/chronos/templates/chronos/partials/subject.html
@@ -1,3 +1,3 @@
 <strong>
-  <span data-position="bottom" class="tooltipped" data-tooltip="{{ subject.name }}">{{ subject.abbrev }}</span>
+  <span data-position="bottom" class="tooltipped" data-tooltip="{{ subject.name }}">{{ subject.short_name }}</span>
 </strong>
diff --git a/aleksis/apps/chronos/templates/chronos/partials/subs/subject.html b/aleksis/apps/chronos/templates/chronos/partials/subs/subject.html
index 1210528a..1b7a3c5c 100644
--- a/aleksis/apps/chronos/templates/chronos/partials/subs/subject.html
+++ b/aleksis/apps/chronos/templates/chronos/partials/subs/subject.html
@@ -4,15 +4,15 @@
   {% if not el.lesson_period.lesson.subject and not el.subject %}
   {% elif el.cancelled or el.cancelled_for_teachers %}
     <span data-position="bottom" class="tooltipped" data-tooltip="{{ el.lesson_period.lesson.subject.name }}">
-    <s>{{ el.lesson_period.lesson.subject.abbrev }}</s>
+    <s>{{ el.lesson_period.lesson.subject.short_name }}</s>
   </span>
   {% elif el.subject and el.lesson_period.lesson.subject %}
     <span data-position="bottom" class="tooltipped" data-tooltip="{{ el.lesson_period.lesson.subject.name }}">
-    <s>{{ el.lesson_period.lesson.subject.abbrev }}</s>
+    <s>{{ el.lesson_period.lesson.subject.short_name }}</s>
   </span>
     →
     <span data-position="bottom" class="tooltipped" data-tooltip="{{ el.subject.name }}">
-    <strong>{{ el.subject.abbrev }}</strong>
+    <strong>{{ el.subject.short_name }}</strong>
   </span>
   {% elif el.subject and not el.lesson_period.lesson.subject %}
     {% include "chronos/partials/subject.html" with subject=el.subject %}
-- 
GitLab