We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Sort list of users when adding marks
When adding a mark, the list of user which the mark should relate to is not sorted. It should be. (It is probably sorted on realname instead of username)
- Change the list to display realname instead of username.
- Make sure it's sorted.

(Bonus would be to have a select2js-ish search on it as well, but don't use time on it.)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `apps/authentication/models.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 import datetime
4 from pytz import timezone
5 
6 from django.conf import settings
7 from django.contrib.auth.models import AbstractUser
8 from django.db import models
9 from django.utils.translation import ugettext as _
10 from django.utils import timezone
11 
12 
13 # If this list is changed, remember to check that the year property on
14 # OnlineUser is still correct!
15 FIELD_OF_STUDY_CHOICES = [
16     (0, _(u'Gjest')),
17     (1, _(u'Bachelor i Informatikk (BIT)')),
18     # master degrees take up the interval [10,30>
19     (10, _(u'Software (SW)')),
20     (11, _(u'Informasjonsforvaltning (DIF)')),
21     (12, _(u'Komplekse Datasystemer (KDS)')),
22     (13, _(u'Spillteknologi (SPT)')),
23     (14, _(u'Intelligente Systemer (IRS)')),
24     (15, _(u'Helseinformatikk (MSMEDTEK)')),
25     (30, _(u'Annen mastergrad')),
26     (80, _(u'PhD')),
27     (90, _(u'International')),
28     (100, _(u'Annet Onlinemedlem')),
29 ]
30 
31 class OnlineUser(AbstractUser):
32 
33     IMAGE_FOLDER = "images/profiles"
34     IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.gif', '.png']
35     
36     # Online related fields
37     field_of_study = models.SmallIntegerField(_(u"studieretning"), choices=FIELD_OF_STUDY_CHOICES, default=0)
38     started_date = models.DateField(_(u"startet studie"), default=timezone.now().date())
39     compiled = models.BooleanField(_(u"kompilert"), default=False)
40 
41     # Email
42     infomail = models.BooleanField(_(u"vil ha infomail"), default=True)
43 
44     # Address
45     phone_number = models.CharField(_(u"telefonnummer"), max_length=20, blank=True, null=True)
46     address = models.CharField(_(u"adresse"), max_length=30, blank=True, null=True)
47     zip_code = models.CharField(_(u"postnummer"), max_length=4, blank=True, null=True)
48 
49     # Other
50     allergies = models.TextField(_(u"allergier"), blank=True, null=True)
51     mark_rules = models.BooleanField(_(u"godtatt prikkeregler"), default=False)
52     rfid = models.CharField(_(u"RFID"), max_length=50, blank=True, null=True)
53     nickname = models.CharField(_(u"nickname"), max_length=50, blank=True, null=True)
54     website = models.URLField(_(u"hjemmeside"), blank=True, null=True)
55 
56 
57     image = models.ImageField(_(u"bilde"), max_length=200, upload_to=IMAGE_FOLDER, blank=True, null=True,
58                               default=settings.DEFAULT_PROFILE_PICTURE_URL)
59 
60     # NTNU credentials
61     ntnu_username = models.CharField(_(u"NTNU-brukernavn"), max_length=10, blank=True, null=True)
62 
63     # TODO profile pictures
64     # TODO checkbox for forwarding of @online.ntnu.no mail
65         
66     @property
67     def is_member(self):
68         """
69         Returns true if the User object is associated with Online.
70         """
71         if AllowedUsername.objects.filter(username=self.ntnu_username).filter(expiration_date__gte=timezone.now()).count() > 0:
72             return True
73         return False
74 
75     def get_full_name(self):
76         """
77         Returns the first_name plus the last_name, with a space in between.
78         """
79         full_name = u'%s %s' % (self.first_name, self.last_name)
80         return full_name.strip()
81 
82     def get_email(self):
83         return self.get_emails().filter(primary = True)[0]
84 
85     def get_emails(self):
86         return Email.objects.all().filter(user = self)
87 
88     @property
89     def year(self):
90         today = timezone.now().date()
91         started = self.started_date
92 
93         # We say that a year is 360 days incase we are a bit slower to
94         # add users one year.
95         year = ((today - started).days / 360) + 1
96 
97         if self.field_of_study == 0 or self.field_of_study == 100:  # others
98             return 0
99         # dont return a bachelor student as 4th or 5th grade
100         elif self.field_of_study == 1:  # bachelor
101             if year > 3:
102                 return 3
103             return year
104         elif 9 < self.field_of_study < 30:  # 10-29 is considered master
105             if year >= 2:
106                 return 5
107             return 4
108         elif self.field_of_study == 80:  # phd
109             return year + 5
110         elif self.field_of_study == 90:  # international
111             if year == 1:
112                 return 1
113             return 4
114 
115     def __unicode__(self):
116         return self.get_full_name()
117 
118     class Meta:
119         verbose_name = _(u"brukerprofil")
120         verbose_name_plural = _(u"brukerprofiler")
121 
122 
123 class Email(models.Model):
124     user = models.ForeignKey(OnlineUser, related_name="email_user")
125     email = models.EmailField(_(u"epostadresse"), unique=True)
126     primary = models.BooleanField(_(u"aktiv"), default=False)
127     verified = models.BooleanField(_(u"verifisert"), default=False)
128 
129     def __unicode__(self):
130         return self.email
131 
132     class Meta:
133         verbose_name = _(u"epostadresse")
134         verbose_name_plural = _(u"epostadresser")
135 
136 
137 class RegisterToken(models.Model):
138     user = models.ForeignKey(OnlineUser, related_name="register_user")
139     email = models.EmailField(_(u"epost"), max_length=254)
140     token = models.CharField(_(u"token"), max_length=32)
141     created = models.DateTimeField(_(u"opprettet dato"), editable=False, auto_now_add=True)
142 
143     @property
144     def is_valid(self):
145         valid_period = datetime.timedelta(days=1)
146         now = timezone.now()
147         return now < self.created + valid_period 
148 
149 
150 class AllowedUsername(models.Model):
151     """
152     Holds usernames that are considered valid members of Online and the time they expire.
153     """
154     username = models.CharField(_(u"brukernavn"), max_length=10)
155     registered = models.DateField(_(u"registrert"))
156     note = models.CharField(_(u"notat"), max_length=100)
157     description = models.TextField(_(u"beskrivelse"), blank=True, null=True)
158     expiration_date = models.DateField(_(u"utløpsdato"))
159 
160     @property
161     def is_active(self):
162         return timezone.now().date() < self.expiration_date
163 
164     def __unicode__(self):
165         return self.username
166 
167     class Meta:
168         verbose_name = _(u"tillatt brukernavn")
169         verbose_name_plural = _(u"tillatte brukernavn")
170         ordering = (u"username",)
171
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/apps/authentication/models.py b/apps/authentication/models.py
--- a/apps/authentication/models.py
+++ b/apps/authentication/models.py
@@ -116,6 +116,7 @@
         return self.get_full_name()
 
     class Meta:
+        ordering = ['first_name', 'last_name']
         verbose_name = _(u"brukerprofil")
         verbose_name_plural = _(u"brukerprofiler")

{"golden_diff": "diff --git a/apps/authentication/models.py b/apps/authentication/models.py\n--- a/apps/authentication/models.py\n+++ b/apps/authentication/models.py\n@@ -116,6 +116,7 @@\n         return self.get_full_name()\n \n     class Meta:\n+        ordering = ['first_name', 'last_name']\n         verbose_name = _(u\"brukerprofil\")\n         verbose_name_plural = _(u\"brukerprofiler\")\n", "issue": "Sort list of users when adding marks\nWhen adding a mark, the list of user which the mark should relate to is not sorted. It should be. (It is probably sorted on realname instead of username)\n- Change the list to display realname instead of username.\n- Make sure it's sorted.\n\n(Bonus would be to have a select2js-ish search on it as well, but don't use time on it.)\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport datetime\nfrom pytz import timezone\n\nfrom django.conf import settings\nfrom django.contrib.auth.models import AbstractUser\nfrom django.db import models\nfrom django.utils.translation import ugettext as _\nfrom django.utils import timezone\n\n\n# If this list is changed, remember to check that the year property on\n# OnlineUser is still correct!\nFIELD_OF_STUDY_CHOICES = [\n    (0, _(u'Gjest')),\n    (1, _(u'Bachelor i Informatikk (BIT)')),\n    # master degrees take up the interval [10,30>\n    (10, _(u'Software (SW)')),\n    (11, _(u'Informasjonsforvaltning (DIF)')),\n    (12, _(u'Komplekse Datasystemer (KDS)')),\n    (13, _(u'Spillteknologi (SPT)')),\n    (14, _(u'Intelligente Systemer (IRS)')),\n    (15, _(u'Helseinformatikk (MSMEDTEK)')),\n    (30, _(u'Annen mastergrad')),\n    (80, _(u'PhD')),\n    (90, _(u'International')),\n    (100, _(u'Annet Onlinemedlem')),\n]\n\nclass OnlineUser(AbstractUser):\n\n    IMAGE_FOLDER = \"images/profiles\"\n    IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.gif', '.png']\n    \n    # Online related fields\n    field_of_study = models.SmallIntegerField(_(u\"studieretning\"), choices=FIELD_OF_STUDY_CHOICES, default=0)\n    started_date = models.DateField(_(u\"startet studie\"), default=timezone.now().date())\n    compiled = models.BooleanField(_(u\"kompilert\"), default=False)\n\n    # Email\n    infomail = models.BooleanField(_(u\"vil ha infomail\"), default=True)\n\n    # Address\n    phone_number = models.CharField(_(u\"telefonnummer\"), max_length=20, blank=True, null=True)\n    address = models.CharField(_(u\"adresse\"), max_length=30, blank=True, null=True)\n    zip_code = models.CharField(_(u\"postnummer\"), max_length=4, blank=True, null=True)\n\n    # Other\n    allergies = models.TextField(_(u\"allergier\"), blank=True, null=True)\n    mark_rules = models.BooleanField(_(u\"godtatt prikkeregler\"), default=False)\n    rfid = models.CharField(_(u\"RFID\"), max_length=50, blank=True, null=True)\n    nickname = models.CharField(_(u\"nickname\"), max_length=50, blank=True, null=True)\n    website = models.URLField(_(u\"hjemmeside\"), blank=True, null=True)\n\n\n    image = models.ImageField(_(u\"bilde\"), max_length=200, upload_to=IMAGE_FOLDER, blank=True, null=True,\n                              default=settings.DEFAULT_PROFILE_PICTURE_URL)\n\n    # NTNU credentials\n    ntnu_username = models.CharField(_(u\"NTNU-brukernavn\"), max_length=10, blank=True, null=True)\n\n    # TODO profile pictures\n    # TODO checkbox for forwarding of @online.ntnu.no mail\n        \n    @property\n    def is_member(self):\n        \"\"\"\n        Returns true if the User object is associated with Online.\n        \"\"\"\n        if AllowedUsername.objects.filter(username=self.ntnu_username).filter(expiration_date__gte=timezone.now()).count() > 0:\n            return True\n        return False\n\n    def get_full_name(self):\n        \"\"\"\n        Returns the first_name plus the last_name, with a space in between.\n        \"\"\"\n        full_name = u'%s %s' % (self.first_name, self.last_name)\n        return full_name.strip()\n\n    def get_email(self):\n        return self.get_emails().filter(primary = True)[0]\n\n    def get_emails(self):\n        return Email.objects.all().filter(user = self)\n\n    @property\n    def year(self):\n        today = timezone.now().date()\n        started = self.started_date\n\n        # We say that a year is 360 days incase we are a bit slower to\n        # add users one year.\n        year = ((today - started).days / 360) + 1\n\n        if self.field_of_study == 0 or self.field_of_study == 100:  # others\n            return 0\n        # dont return a bachelor student as 4th or 5th grade\n        elif self.field_of_study == 1:  # bachelor\n            if year > 3:\n                return 3\n            return year\n        elif 9 < self.field_of_study < 30:  # 10-29 is considered master\n            if year >= 2:\n                return 5\n            return 4\n        elif self.field_of_study == 80:  # phd\n            return year + 5\n        elif self.field_of_study == 90:  # international\n            if year == 1:\n                return 1\n            return 4\n\n    def __unicode__(self):\n        return self.get_full_name()\n\n    class Meta:\n        verbose_name = _(u\"brukerprofil\")\n        verbose_name_plural = _(u\"brukerprofiler\")\n\n\nclass Email(models.Model):\n    user = models.ForeignKey(OnlineUser, related_name=\"email_user\")\n    email = models.EmailField(_(u\"epostadresse\"), unique=True)\n    primary = models.BooleanField(_(u\"aktiv\"), default=False)\n    verified = models.BooleanField(_(u\"verifisert\"), default=False)\n\n    def __unicode__(self):\n        return self.email\n\n    class Meta:\n        verbose_name = _(u\"epostadresse\")\n        verbose_name_plural = _(u\"epostadresser\")\n\n\nclass RegisterToken(models.Model):\n    user = models.ForeignKey(OnlineUser, related_name=\"register_user\")\n    email = models.EmailField(_(u\"epost\"), max_length=254)\n    token = models.CharField(_(u\"token\"), max_length=32)\n    created = models.DateTimeField(_(u\"opprettet dato\"), editable=False, auto_now_add=True)\n\n    @property\n    def is_valid(self):\n        valid_period = datetime.timedelta(days=1)\n        now = timezone.now()\n        return now < self.created + valid_period \n\n\nclass AllowedUsername(models.Model):\n    \"\"\"\n    Holds usernames that are considered valid members of Online and the time they expire.\n    \"\"\"\n    username = models.CharField(_(u\"brukernavn\"), max_length=10)\n    registered = models.DateField(_(u\"registrert\"))\n    note = models.CharField(_(u\"notat\"), max_length=100)\n    description = models.TextField(_(u\"beskrivelse\"), blank=True, null=True)\n    expiration_date = models.DateField(_(u\"utl\u00f8psdato\"))\n\n    @property\n    def is_active(self):\n        return timezone.now().date() < self.expiration_date\n\n    def __unicode__(self):\n        return self.username\n\n    class Meta:\n        verbose_name = _(u\"tillatt brukernavn\")\n        verbose_name_plural = _(u\"tillatte brukernavn\")\n        ordering = (u\"username\",)\n", "path": "apps/authentication/models.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport datetime\nfrom pytz import timezone\n\nfrom django.conf import settings\nfrom django.contrib.auth.models import AbstractUser\nfrom django.db import models\nfrom django.utils.translation import ugettext as _\nfrom django.utils import timezone\n\n\n# If this list is changed, remember to check that the year property on\n# OnlineUser is still correct!\nFIELD_OF_STUDY_CHOICES = [\n    (0, _(u'Gjest')),\n    (1, _(u'Bachelor i Informatikk (BIT)')),\n    # master degrees take up the interval [10,30>\n    (10, _(u'Software (SW)')),\n    (11, _(u'Informasjonsforvaltning (DIF)')),\n    (12, _(u'Komplekse Datasystemer (KDS)')),\n    (13, _(u'Spillteknologi (SPT)')),\n    (14, _(u'Intelligente Systemer (IRS)')),\n    (15, _(u'Helseinformatikk (MSMEDTEK)')),\n    (30, _(u'Annen mastergrad')),\n    (80, _(u'PhD')),\n    (90, _(u'International')),\n    (100, _(u'Annet Onlinemedlem')),\n]\n\nclass OnlineUser(AbstractUser):\n\n    IMAGE_FOLDER = \"images/profiles\"\n    IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.gif', '.png']\n    \n    # Online related fields\n    field_of_study = models.SmallIntegerField(_(u\"studieretning\"), choices=FIELD_OF_STUDY_CHOICES, default=0)\n    started_date = models.DateField(_(u\"startet studie\"), default=timezone.now().date())\n    compiled = models.BooleanField(_(u\"kompilert\"), default=False)\n\n    # Email\n    infomail = models.BooleanField(_(u\"vil ha infomail\"), default=True)\n\n    # Address\n    phone_number = models.CharField(_(u\"telefonnummer\"), max_length=20, blank=True, null=True)\n    address = models.CharField(_(u\"adresse\"), max_length=30, blank=True, null=True)\n    zip_code = models.CharField(_(u\"postnummer\"), max_length=4, blank=True, null=True)\n\n    # Other\n    allergies = models.TextField(_(u\"allergier\"), blank=True, null=True)\n    mark_rules = models.BooleanField(_(u\"godtatt prikkeregler\"), default=False)\n    rfid = models.CharField(_(u\"RFID\"), max_length=50, blank=True, null=True)\n    nickname = models.CharField(_(u\"nickname\"), max_length=50, blank=True, null=True)\n    website = models.URLField(_(u\"hjemmeside\"), blank=True, null=True)\n\n\n    image = models.ImageField(_(u\"bilde\"), max_length=200, upload_to=IMAGE_FOLDER, blank=True, null=True,\n                              default=settings.DEFAULT_PROFILE_PICTURE_URL)\n\n    # NTNU credentials\n    ntnu_username = models.CharField(_(u\"NTNU-brukernavn\"), max_length=10, blank=True, null=True)\n\n    # TODO profile pictures\n    # TODO checkbox for forwarding of @online.ntnu.no mail\n        \n    @property\n    def is_member(self):\n        \"\"\"\n        Returns true if the User object is associated with Online.\n        \"\"\"\n        if AllowedUsername.objects.filter(username=self.ntnu_username).filter(expiration_date__gte=timezone.now()).count() > 0:\n            return True\n        return False\n\n    def get_full_name(self):\n        \"\"\"\n        Returns the first_name plus the last_name, with a space in between.\n        \"\"\"\n        full_name = u'%s %s' % (self.first_name, self.last_name)\n        return full_name.strip()\n\n    def get_email(self):\n        return self.get_emails().filter(primary = True)[0]\n\n    def get_emails(self):\n        return Email.objects.all().filter(user = self)\n\n    @property\n    def year(self):\n        today = timezone.now().date()\n        started = self.started_date\n\n        # We say that a year is 360 days incase we are a bit slower to\n        # add users one year.\n        year = ((today - started).days / 360) + 1\n\n        if self.field_of_study == 0 or self.field_of_study == 100:  # others\n            return 0\n        # dont return a bachelor student as 4th or 5th grade\n        elif self.field_of_study == 1:  # bachelor\n            if year > 3:\n                return 3\n            return year\n        elif 9 < self.field_of_study < 30:  # 10-29 is considered master\n            if year >= 2:\n                return 5\n            return 4\n        elif self.field_of_study == 80:  # phd\n            return year + 5\n        elif self.field_of_study == 90:  # international\n            if year == 1:\n                return 1\n            return 4\n\n    def __unicode__(self):\n        return self.get_full_name()\n\n    class Meta:\n        ordering = ['first_name', 'last_name']\n        verbose_name = _(u\"brukerprofil\")\n        verbose_name_plural = _(u\"brukerprofiler\")\n\n\nclass Email(models.Model):\n    user = models.ForeignKey(OnlineUser, related_name=\"email_user\")\n    email = models.EmailField(_(u\"epostadresse\"), unique=True)\n    primary = models.BooleanField(_(u\"aktiv\"), default=False)\n    verified = models.BooleanField(_(u\"verifisert\"), default=False)\n\n    def __unicode__(self):\n        return self.email\n\n    class Meta:\n        verbose_name = _(u\"epostadresse\")\n        verbose_name_plural = _(u\"epostadresser\")\n\n\nclass RegisterToken(models.Model):\n    user = models.ForeignKey(OnlineUser, related_name=\"register_user\")\n    email = models.EmailField(_(u\"epost\"), max_length=254)\n    token = models.CharField(_(u\"token\"), max_length=32)\n    created = models.DateTimeField(_(u\"opprettet dato\"), editable=False, auto_now_add=True)\n\n    @property\n    def is_valid(self):\n        valid_period = datetime.timedelta(days=1)\n        now = timezone.now()\n        return now < self.created + valid_period \n\n\nclass AllowedUsername(models.Model):\n    \"\"\"\n    Holds usernames that are considered valid members of Online and the time they expire.\n    \"\"\"\n    username = models.CharField(_(u\"brukernavn\"), max_length=10)\n    registered = models.DateField(_(u\"registrert\"))\n    note = models.CharField(_(u\"notat\"), max_length=100)\n    description = models.TextField(_(u\"beskrivelse\"), blank=True, null=True)\n    expiration_date = models.DateField(_(u\"utl\u00f8psdato\"))\n\n    @property\n    def is_active(self):\n        return timezone.now().date() < self.expiration_date\n\n    def __unicode__(self):\n        return self.username\n\n    class Meta:\n        verbose_name = _(u\"tillatt brukernavn\")\n        verbose_name_plural = _(u\"tillatte brukernavn\")\n        ordering = (u\"username\",)\n", "path": "apps/authentication/models.py"}]}