We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Wrong links to images from entry page
If I open an entry page, for example 
    http://changelog.linfiniti.com/qgis/2.8/entry/more-responsive-browser/ and then click on the image I get server error 404 because the link is pointing to 
    /qgis/2.8/entry/<entry name>/images/entries/<hash>.<ext>
instead of 
    /media/images/entries/<hash>.<ext>


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `django_project/core/settings/base.py`
Content:
```
1 # coding=utf-8
2 """
3 core.settings.base
4 """
5 # Django settings for projecta project.
6 
7 from .utils import absolute_path
8 
9 ADMINS = (
10     ('Tim Sutton', 'tim@linfiniti.com'),
11 )
12 SERVER_EMAIL = 'tim@linfiniti.com'
13 EMAIL_HOST = 'localhost'
14 DEFAULT_FROM_EMAIL = 'tim@linfiniti.com'
15 
16 MANAGERS = ADMINS
17 
18 # Local time zone for this installation. Choices can be found here:
19 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
20 # although not all choices may be available on all operating systems.
21 # In a Windows environment this must be set to your system time zone.
22 TIME_ZONE = 'America/Chicago'
23 
24 # Language code for this installation. All choices can be found here:
25 # http://www.i18nguy.com/unicode/language-identifiers.html
26 LANGUAGE_CODE = 'en-us'
27 
28 SITE_ID = 1
29 
30 # If you set this to False, Django will make some optimizations so as not
31 # to load the internationalization machinery.
32 USE_I18N = True
33 
34 # If you set this to False, Django will not format dates, numbers and
35 # calendars according to the current locale.
36 USE_L10N = True
37 
38 # If you set this to False, Django will not use timezone-aware datetimes.
39 USE_TZ = True
40 
41 # Absolute filesystem path to the directory that will hold user-uploaded files.
42 # Example: "/var/www/example.com/media/"
43 MEDIA_ROOT = absolute_path('media')
44 
45 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
46 # trailing slash.
47 # Examples: "http://example.com/media/", "http://media.example.com/"
48 # MEDIA_URL = '/media/'
49 # setting full MEDIA_URL to be able to use it for the feeds
50 MEDIA_URL = '/media/'
51 
52 # Absolute path to the directory static files should be collected to.
53 # Don't put anything in this directory yourself; store your static files
54 # in apps' "static/" subdirectories and in STATICFILES_DIRS.
55 # Example: "/var/www/example.com/static/"
56 STATIC_ROOT = absolute_path('static')
57 
58 # URL prefix for static files.
59 # Example: "http://example.com/static/", "http://static.example.com/"
60 STATIC_URL = '/static/'
61 
62 # Additional locations of static files
63 STATICFILES_DIRS = (
64     # Put strings here, like "/home/html/static" or "C:/www/django/static".
65     # Always use forward slashes, even on Windows.
66     # Don't forget to use absolute paths, not relative paths.
67     absolute_path('core', 'base_static'),
68 )
69 
70 # List of finder classes that know how to find static files in
71 # various locations.
72 STATICFILES_FINDERS = (
73     'django.contrib.staticfiles.finders.FileSystemFinder',
74     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
75     # 'django.contrib.staticfiles.finders.DefaultStorageFinder',
76 )
77 
78 # import SECRET_KEY into current namespace
79 # noinspection PyUnresolvedReferences
80 from .secret import SECRET_KEY  # noqa
81 
82 # List of callables that know how to import templates from various sources.
83 TEMPLATE_LOADERS = (
84     'django.template.loaders.filesystem.Loader',
85     'django.template.loaders.app_directories.Loader',
86     # 'django.template.loaders.eggs.Loader',
87 )
88 
89 TEMPLATE_CONTEXT_PROCESSORS = (
90     'django.contrib.auth.context_processors.auth',
91     'django.core.context_processors.request',
92     'core.context_processors.add_intercom_app_id'
93 )
94 
95 MIDDLEWARE_CLASSES = (
96     'django.middleware.common.CommonMiddleware',
97     'django.contrib.sessions.middleware.SessionMiddleware',
98     'django.middleware.csrf.CsrfViewMiddleware',
99     'django.contrib.auth.middleware.AuthenticationMiddleware',
100     'django.contrib.messages.middleware.MessageMiddleware',
101     # Uncomment the next line for simple clickjacking protection:
102     # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
103     'core.custom_middleware.NavContextMiddleware'
104 )
105 
106 ROOT_URLCONF = 'core.urls'
107 
108 # Python dotted path to the WSGI application used by Django's runserver.
109 WSGI_APPLICATION = 'core.wsgi.application'
110 
111 TEMPLATE_DIRS = (
112     # project level templates
113     absolute_path('core', 'base_templates'),
114     absolute_path('vota', 'templates'),
115     absolute_path('changes', 'templates'),
116 
117 )
118 
119 INSTALLED_APPS = (
120     'django.contrib.auth',
121     'django.contrib.contenttypes',
122     'django.contrib.sessions',
123     'django.contrib.sites',
124     'django.contrib.messages',
125     'django.contrib.staticfiles',
126     'django.contrib.admin',
127     'django.contrib.syndication',
128 )
129 
130 # A sample logging configuration. The only tangible logging
131 # performed by this configuration is to send an email to
132 # the site admins on every HTTP 500 error when DEBUG=False.
133 # See http://docs.djangoproject.com/en/dev/topics/logging for
134 # more details on how to customize your logging configuration.
135 LOGGING = {
136     'version': 1,
137     'disable_existing_loggers': False,
138     'filters': {
139         'require_debug_false': {
140             '()': 'django.utils.log.RequireDebugFalse'
141         }
142     },
143     'handlers': {
144         'mail_admins': {
145             'level': 'ERROR',
146             'filters': ['require_debug_false'],
147             'class': 'django.utils.log.AdminEmailHandler'
148         }
149     },
150     'loggers': {
151         'django.request': {
152             'handlers': ['mail_admins'],
153             'level': 'ERROR',
154             'propagate': True,
155         },
156     }
157 }
158
```

Path: `django_project/vota/models/ballot.py`
Content:
```
1 """
2 This model is to create "ballots" i.e. questions/proposals/changes which a
3 Committee can vote on.
4 
5 After voting is complete, a ballot should be marked as either Denied or Passed.
6 
7 If no quorum is reached, no_quorum should be True
8 
9 A ballot has one Committee.
10 """
11 from django.core.urlresolvers import reverse
12 from django.utils.text import slugify
13 import logging
14 from core.settings.contrib import STOP_WORDS
15 
16 logger = logging.getLogger(__name__)
17 from django.db import models
18 from audited_models.models import AuditedModel
19 from django.utils.translation import ugettext_lazy as _
20 from django.utils import timezone
21 from vota.models.vote import Vote
22 import datetime
23 from django.contrib.auth.models import User
24 
25 
26 class ApprovedCategoryManager(models.Manager):
27     """Custom category manager that shows only approved ballots."""
28 
29     def get_query_set(self):
30         """Query set generator"""
31         return super(
32             ApprovedCategoryManager, self).get_query_set().filter(
33                 approved=True)
34 
35 
36 class DeniedCategoryManager(models.Manager):
37     """Custom version manager that shows only denied ballots."""
38 
39     def get_query_set(self):
40         """Query set generator"""
41         return super(
42             DeniedCategoryManager, self).get_query_set().filter(
43                 denied=True)
44 
45 
46 class OpenBallotManager(models.Manager):
47     """Custom version manager that shows only open ballots."""
48 
49     def get_query_set(self):
50         """Query set generator"""
51         return super(
52             OpenBallotManager, self).get_query_set().filter(
53                 open_from__lt=timezone.now()).filter(closes__gt=timezone.now())
54 
55 
56 class ClosedBallotManager(models.Manager):
57     """Custom version manager that shows only closed ballots."""
58 
59     def get_query_set(self):
60         """Query set generator"""
61         return super(
62             ClosedBallotManager, self).get_query_set().filter(
63                 closes__gt=timezone.now())
64 
65 
66 class Ballot(AuditedModel):
67     """A category model e.g. gui, backend, web site etc."""
68     name = models.CharField(
69         help_text=_('Name of this ballot.'),
70         max_length=255,
71         null=False,
72         blank=False,
73         unique=False
74     )  # there is a unique together rule in meta class below
75 
76     summary = models.CharField(
77         help_text=_('A brief overview of the ballot.'),
78         max_length=250,
79         blank=False,
80         null=False
81     )
82 
83     description = models.TextField(
84         help_text=_('A full description of the proposal if a summary is not '
85                     'enough!'),
86         max_length=3000,
87         null=True,
88         blank=True,
89     )
90 
91     approved = models.BooleanField(
92         help_text=_(
93             'Whether this ballot has been approved.'),
94         default=False
95     )
96 
97     denied = models.BooleanField(
98         help_text=_(
99             'Whether this ballot has been denied.'),
100         default=False
101     )
102 
103     no_quorum = models.BooleanField(
104         help_text=_('Whether the ballot was denied because no quorum was '
105                     'reached'),
106         default=False
107     )
108 
109     open_from = models.DateTimeField(
110         help_text=_('Date the ballot opens'),
111         default=timezone.now()
112     )
113 
114     closes = models.DateTimeField(
115         help_text=_('Date the ballot closes'),
116         default=timezone.now() + datetime.timedelta(days=7)
117     )
118 
119     private = models.BooleanField(
120         help_text=_('Should members be prevented from viewing results before '
121                     'voting?'),
122         default=False
123     )
124 
125     proposer = models.ForeignKey(User)
126     # noinspection PyUnresolvedReferences
127     committee = models.ForeignKey('Committee')
128     slug = models.SlugField()
129     objects = models.Manager()
130     approved_objects = ApprovedCategoryManager()
131     denied_objects = DeniedCategoryManager()
132     open_objects = OpenBallotManager()
133     closed_objects = ClosedBallotManager()
134 
135     # noinspection PyClassicStyleClass
136     class Meta:
137         """Meta options for the category class."""
138         unique_together = (
139             ('name', 'committee'),
140             ('committee', 'slug')
141         )
142         app_label = 'vota'
143 
144     def save(self, *args, **kwargs):
145         if not self.pk:
146             words = self.name.split()
147             filtered_words = [t for t in words if t.lower() not in STOP_WORDS]
148             new_list = ' '.join(filtered_words)
149             self.slug = slugify(new_list)[:50]
150         super(Ballot, self).save(*args, **kwargs)
151 
152     def __unicode__(self):
153         return u'%s : %s' % (self.committee.name, self.name)
154 
155     def get_absolute_url(self):
156         return reverse('ballot-detail', kwargs={
157             'project_slug': self.committee.project.slug,
158             'committee_slug': self.committee.slug,
159             'slug': self.slug
160         })
161 
162     def get_user_voted(self, user=None):
163         voted = False
164         if Vote.objects.filter(ballot=self).filter(user=user).exists():
165             voted = True
166         return voted
167 
168     def get_positive_vote_count(self):
169         votes = Vote.objects.filter(ballot=self).filter(choice='y').count()
170         return votes
171 
172     def get_negative_vote_count(self):
173         votes = Vote.objects.filter(ballot=self).filter(choice='n').count()
174         return votes
175 
176     def get_abstainer_count(self):
177         votes = Vote.objects.filter(ballot=self).filter(choice='-').count()
178         return votes
179 
180     def get_current_tally(self):
181         positive = self.get_positive_vote_count()
182         negative = self.get_negative_vote_count()
183         tally = 0
184         tally += positive
185         tally -= negative
186         return tally
187 
188     def get_total_vote_count(self):
189         vote_count = Vote.objects.filter(ballot=self).count()
190         return vote_count
191 
192     def has_quorum(self):
193         vote_count = self.get_total_vote_count()
194         committee_user_count = self.committee.users.all().count()
195         if committee_user_count != 0:
196             quorum_percent = self.committee.quorum_setting
197             percentage = 100 * float(vote_count) / float(committee_user_count)
198             if percentage > quorum_percent:
199                 return True
200         else:
201             return False
202 
203     def is_open(self):
204         open_date = self.open_from
205         close_date = self.closes
206         if open_date < timezone.now() < close_date:
207             return True
208         return False
209
```
--- 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/django_project/core/settings/base.py b/django_project/core/settings/base.py
--- a/django_project/core/settings/base.py
+++ b/django_project/core/settings/base.py
@@ -89,6 +89,7 @@
 TEMPLATE_CONTEXT_PROCESSORS = (
     'django.contrib.auth.context_processors.auth',
     'django.core.context_processors.request',
+    'django.core.context_processors.media',
     'core.context_processors.add_intercom_app_id'
 )
 
diff --git a/django_project/vota/models/ballot.py b/django_project/vota/models/ballot.py
--- a/django_project/vota/models/ballot.py
+++ b/django_project/vota/models/ballot.py
@@ -108,7 +108,7 @@
 
     open_from = models.DateTimeField(
         help_text=_('Date the ballot opens'),
-        default=timezone.now()
+        default=timezone.now
     )
 
     closes = models.DateTimeField(

{"golden_diff": "diff --git a/django_project/core/settings/base.py b/django_project/core/settings/base.py\n--- a/django_project/core/settings/base.py\n+++ b/django_project/core/settings/base.py\n@@ -89,6 +89,7 @@\n TEMPLATE_CONTEXT_PROCESSORS = (\n     'django.contrib.auth.context_processors.auth',\n     'django.core.context_processors.request',\n+    'django.core.context_processors.media',\n     'core.context_processors.add_intercom_app_id'\n )\n \ndiff --git a/django_project/vota/models/ballot.py b/django_project/vota/models/ballot.py\n--- a/django_project/vota/models/ballot.py\n+++ b/django_project/vota/models/ballot.py\n@@ -108,7 +108,7 @@\n \n     open_from = models.DateTimeField(\n         help_text=_('Date the ballot opens'),\n-        default=timezone.now()\n+        default=timezone.now\n     )\n \n     closes = models.DateTimeField(\n", "issue": "Wrong links to images from entry page\nIf I open an entry page, for example \n    http://changelog.linfiniti.com/qgis/2.8/entry/more-responsive-browser/ and then click on the image I get server error 404 because the link is pointing to \n    /qgis/2.8/entry/<entry name>/images/entries/<hash>.<ext>\ninstead of \n    /media/images/entries/<hash>.<ext>\n\n", "before_files": [{"content": "# coding=utf-8\n\"\"\"\ncore.settings.base\n\"\"\"\n# Django settings for projecta project.\n\nfrom .utils import absolute_path\n\nADMINS = (\n    ('Tim Sutton', 'tim@linfiniti.com'),\n)\nSERVER_EMAIL = 'tim@linfiniti.com'\nEMAIL_HOST = 'localhost'\nDEFAULT_FROM_EMAIL = 'tim@linfiniti.com'\n\nMANAGERS = ADMINS\n\n# Local time zone for this installation. Choices can be found here:\n# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name\n# although not all choices may be available on all operating systems.\n# In a Windows environment this must be set to your system time zone.\nTIME_ZONE = 'America/Chicago'\n\n# Language code for this installation. All choices can be found here:\n# http://www.i18nguy.com/unicode/language-identifiers.html\nLANGUAGE_CODE = 'en-us'\n\nSITE_ID = 1\n\n# If you set this to False, Django will make some optimizations so as not\n# to load the internationalization machinery.\nUSE_I18N = True\n\n# If you set this to False, Django will not format dates, numbers and\n# calendars according to the current locale.\nUSE_L10N = True\n\n# If you set this to False, Django will not use timezone-aware datetimes.\nUSE_TZ = True\n\n# Absolute filesystem path to the directory that will hold user-uploaded files.\n# Example: \"/var/www/example.com/media/\"\nMEDIA_ROOT = absolute_path('media')\n\n# URL that handles the media served from MEDIA_ROOT. Make sure to use a\n# trailing slash.\n# Examples: \"http://example.com/media/\", \"http://media.example.com/\"\n# MEDIA_URL = '/media/'\n# setting full MEDIA_URL to be able to use it for the feeds\nMEDIA_URL = '/media/'\n\n# Absolute path to the directory static files should be collected to.\n# Don't put anything in this directory yourself; store your static files\n# in apps' \"static/\" subdirectories and in STATICFILES_DIRS.\n# Example: \"/var/www/example.com/static/\"\nSTATIC_ROOT = absolute_path('static')\n\n# URL prefix for static files.\n# Example: \"http://example.com/static/\", \"http://static.example.com/\"\nSTATIC_URL = '/static/'\n\n# Additional locations of static files\nSTATICFILES_DIRS = (\n    # Put strings here, like \"/home/html/static\" or \"C:/www/django/static\".\n    # Always use forward slashes, even on Windows.\n    # Don't forget to use absolute paths, not relative paths.\n    absolute_path('core', 'base_static'),\n)\n\n# List of finder classes that know how to find static files in\n# various locations.\nSTATICFILES_FINDERS = (\n    'django.contrib.staticfiles.finders.FileSystemFinder',\n    'django.contrib.staticfiles.finders.AppDirectoriesFinder',\n    # 'django.contrib.staticfiles.finders.DefaultStorageFinder',\n)\n\n# import SECRET_KEY into current namespace\n# noinspection PyUnresolvedReferences\nfrom .secret import SECRET_KEY  # noqa\n\n# List of callables that know how to import templates from various sources.\nTEMPLATE_LOADERS = (\n    'django.template.loaders.filesystem.Loader',\n    'django.template.loaders.app_directories.Loader',\n    # 'django.template.loaders.eggs.Loader',\n)\n\nTEMPLATE_CONTEXT_PROCESSORS = (\n    'django.contrib.auth.context_processors.auth',\n    'django.core.context_processors.request',\n    'core.context_processors.add_intercom_app_id'\n)\n\nMIDDLEWARE_CLASSES = (\n    'django.middleware.common.CommonMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'django.middleware.csrf.CsrfViewMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'django.contrib.messages.middleware.MessageMiddleware',\n    # Uncomment the next line for simple clickjacking protection:\n    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n    'core.custom_middleware.NavContextMiddleware'\n)\n\nROOT_URLCONF = 'core.urls'\n\n# Python dotted path to the WSGI application used by Django's runserver.\nWSGI_APPLICATION = 'core.wsgi.application'\n\nTEMPLATE_DIRS = (\n    # project level templates\n    absolute_path('core', 'base_templates'),\n    absolute_path('vota', 'templates'),\n    absolute_path('changes', 'templates'),\n\n)\n\nINSTALLED_APPS = (\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.sites',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n    'django.contrib.admin',\n    'django.contrib.syndication',\n)\n\n# A sample logging configuration. The only tangible logging\n# performed by this configuration is to send an email to\n# the site admins on every HTTP 500 error when DEBUG=False.\n# See http://docs.djangoproject.com/en/dev/topics/logging for\n# more details on how to customize your logging configuration.\nLOGGING = {\n    'version': 1,\n    'disable_existing_loggers': False,\n    'filters': {\n        'require_debug_false': {\n            '()': 'django.utils.log.RequireDebugFalse'\n        }\n    },\n    'handlers': {\n        'mail_admins': {\n            'level': 'ERROR',\n            'filters': ['require_debug_false'],\n            'class': 'django.utils.log.AdminEmailHandler'\n        }\n    },\n    'loggers': {\n        'django.request': {\n            'handlers': ['mail_admins'],\n            'level': 'ERROR',\n            'propagate': True,\n        },\n    }\n}\n", "path": "django_project/core/settings/base.py"}, {"content": "\"\"\"\nThis model is to create \"ballots\" i.e. questions/proposals/changes which a\nCommittee can vote on.\n\nAfter voting is complete, a ballot should be marked as either Denied or Passed.\n\nIf no quorum is reached, no_quorum should be True\n\nA ballot has one Committee.\n\"\"\"\nfrom django.core.urlresolvers import reverse\nfrom django.utils.text import slugify\nimport logging\nfrom core.settings.contrib import STOP_WORDS\n\nlogger = logging.getLogger(__name__)\nfrom django.db import models\nfrom audited_models.models import AuditedModel\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.utils import timezone\nfrom vota.models.vote import Vote\nimport datetime\nfrom django.contrib.auth.models import User\n\n\nclass ApprovedCategoryManager(models.Manager):\n    \"\"\"Custom category manager that shows only approved ballots.\"\"\"\n\n    def get_query_set(self):\n        \"\"\"Query set generator\"\"\"\n        return super(\n            ApprovedCategoryManager, self).get_query_set().filter(\n                approved=True)\n\n\nclass DeniedCategoryManager(models.Manager):\n    \"\"\"Custom version manager that shows only denied ballots.\"\"\"\n\n    def get_query_set(self):\n        \"\"\"Query set generator\"\"\"\n        return super(\n            DeniedCategoryManager, self).get_query_set().filter(\n                denied=True)\n\n\nclass OpenBallotManager(models.Manager):\n    \"\"\"Custom version manager that shows only open ballots.\"\"\"\n\n    def get_query_set(self):\n        \"\"\"Query set generator\"\"\"\n        return super(\n            OpenBallotManager, self).get_query_set().filter(\n                open_from__lt=timezone.now()).filter(closes__gt=timezone.now())\n\n\nclass ClosedBallotManager(models.Manager):\n    \"\"\"Custom version manager that shows only closed ballots.\"\"\"\n\n    def get_query_set(self):\n        \"\"\"Query set generator\"\"\"\n        return super(\n            ClosedBallotManager, self).get_query_set().filter(\n                closes__gt=timezone.now())\n\n\nclass Ballot(AuditedModel):\n    \"\"\"A category model e.g. gui, backend, web site etc.\"\"\"\n    name = models.CharField(\n        help_text=_('Name of this ballot.'),\n        max_length=255,\n        null=False,\n        blank=False,\n        unique=False\n    )  # there is a unique together rule in meta class below\n\n    summary = models.CharField(\n        help_text=_('A brief overview of the ballot.'),\n        max_length=250,\n        blank=False,\n        null=False\n    )\n\n    description = models.TextField(\n        help_text=_('A full description of the proposal if a summary is not '\n                    'enough!'),\n        max_length=3000,\n        null=True,\n        blank=True,\n    )\n\n    approved = models.BooleanField(\n        help_text=_(\n            'Whether this ballot has been approved.'),\n        default=False\n    )\n\n    denied = models.BooleanField(\n        help_text=_(\n            'Whether this ballot has been denied.'),\n        default=False\n    )\n\n    no_quorum = models.BooleanField(\n        help_text=_('Whether the ballot was denied because no quorum was '\n                    'reached'),\n        default=False\n    )\n\n    open_from = models.DateTimeField(\n        help_text=_('Date the ballot opens'),\n        default=timezone.now()\n    )\n\n    closes = models.DateTimeField(\n        help_text=_('Date the ballot closes'),\n        default=timezone.now() + datetime.timedelta(days=7)\n    )\n\n    private = models.BooleanField(\n        help_text=_('Should members be prevented from viewing results before '\n                    'voting?'),\n        default=False\n    )\n\n    proposer = models.ForeignKey(User)\n    # noinspection PyUnresolvedReferences\n    committee = models.ForeignKey('Committee')\n    slug = models.SlugField()\n    objects = models.Manager()\n    approved_objects = ApprovedCategoryManager()\n    denied_objects = DeniedCategoryManager()\n    open_objects = OpenBallotManager()\n    closed_objects = ClosedBallotManager()\n\n    # noinspection PyClassicStyleClass\n    class Meta:\n        \"\"\"Meta options for the category class.\"\"\"\n        unique_together = (\n            ('name', 'committee'),\n            ('committee', 'slug')\n        )\n        app_label = 'vota'\n\n    def save(self, *args, **kwargs):\n        if not self.pk:\n            words = self.name.split()\n            filtered_words = [t for t in words if t.lower() not in STOP_WORDS]\n            new_list = ' '.join(filtered_words)\n            self.slug = slugify(new_list)[:50]\n        super(Ballot, self).save(*args, **kwargs)\n\n    def __unicode__(self):\n        return u'%s : %s' % (self.committee.name, self.name)\n\n    def get_absolute_url(self):\n        return reverse('ballot-detail', kwargs={\n            'project_slug': self.committee.project.slug,\n            'committee_slug': self.committee.slug,\n            'slug': self.slug\n        })\n\n    def get_user_voted(self, user=None):\n        voted = False\n        if Vote.objects.filter(ballot=self).filter(user=user).exists():\n            voted = True\n        return voted\n\n    def get_positive_vote_count(self):\n        votes = Vote.objects.filter(ballot=self).filter(choice='y').count()\n        return votes\n\n    def get_negative_vote_count(self):\n        votes = Vote.objects.filter(ballot=self).filter(choice='n').count()\n        return votes\n\n    def get_abstainer_count(self):\n        votes = Vote.objects.filter(ballot=self).filter(choice='-').count()\n        return votes\n\n    def get_current_tally(self):\n        positive = self.get_positive_vote_count()\n        negative = self.get_negative_vote_count()\n        tally = 0\n        tally += positive\n        tally -= negative\n        return tally\n\n    def get_total_vote_count(self):\n        vote_count = Vote.objects.filter(ballot=self).count()\n        return vote_count\n\n    def has_quorum(self):\n        vote_count = self.get_total_vote_count()\n        committee_user_count = self.committee.users.all().count()\n        if committee_user_count != 0:\n            quorum_percent = self.committee.quorum_setting\n            percentage = 100 * float(vote_count) / float(committee_user_count)\n            if percentage > quorum_percent:\n                return True\n        else:\n            return False\n\n    def is_open(self):\n        open_date = self.open_from\n        close_date = self.closes\n        if open_date < timezone.now() < close_date:\n            return True\n        return False\n", "path": "django_project/vota/models/ballot.py"}], "after_files": [{"content": "# coding=utf-8\n\"\"\"\ncore.settings.base\n\"\"\"\n# Django settings for projecta project.\n\nfrom .utils import absolute_path\n\nADMINS = (\n    ('Tim Sutton', 'tim@linfiniti.com'),\n)\nSERVER_EMAIL = 'tim@linfiniti.com'\nEMAIL_HOST = 'localhost'\nDEFAULT_FROM_EMAIL = 'tim@linfiniti.com'\n\nMANAGERS = ADMINS\n\n# Local time zone for this installation. Choices can be found here:\n# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name\n# although not all choices may be available on all operating systems.\n# In a Windows environment this must be set to your system time zone.\nTIME_ZONE = 'America/Chicago'\n\n# Language code for this installation. All choices can be found here:\n# http://www.i18nguy.com/unicode/language-identifiers.html\nLANGUAGE_CODE = 'en-us'\n\nSITE_ID = 1\n\n# If you set this to False, Django will make some optimizations so as not\n# to load the internationalization machinery.\nUSE_I18N = True\n\n# If you set this to False, Django will not format dates, numbers and\n# calendars according to the current locale.\nUSE_L10N = True\n\n# If you set this to False, Django will not use timezone-aware datetimes.\nUSE_TZ = True\n\n# Absolute filesystem path to the directory that will hold user-uploaded files.\n# Example: \"/var/www/example.com/media/\"\nMEDIA_ROOT = absolute_path('media')\n\n# URL that handles the media served from MEDIA_ROOT. Make sure to use a\n# trailing slash.\n# Examples: \"http://example.com/media/\", \"http://media.example.com/\"\n# MEDIA_URL = '/media/'\n# setting full MEDIA_URL to be able to use it for the feeds\nMEDIA_URL = '/media/'\n\n# Absolute path to the directory static files should be collected to.\n# Don't put anything in this directory yourself; store your static files\n# in apps' \"static/\" subdirectories and in STATICFILES_DIRS.\n# Example: \"/var/www/example.com/static/\"\nSTATIC_ROOT = absolute_path('static')\n\n# URL prefix for static files.\n# Example: \"http://example.com/static/\", \"http://static.example.com/\"\nSTATIC_URL = '/static/'\n\n# Additional locations of static files\nSTATICFILES_DIRS = (\n    # Put strings here, like \"/home/html/static\" or \"C:/www/django/static\".\n    # Always use forward slashes, even on Windows.\n    # Don't forget to use absolute paths, not relative paths.\n    absolute_path('core', 'base_static'),\n)\n\n# List of finder classes that know how to find static files in\n# various locations.\nSTATICFILES_FINDERS = (\n    'django.contrib.staticfiles.finders.FileSystemFinder',\n    'django.contrib.staticfiles.finders.AppDirectoriesFinder',\n    # 'django.contrib.staticfiles.finders.DefaultStorageFinder',\n)\n\n# import SECRET_KEY into current namespace\n# noinspection PyUnresolvedReferences\nfrom .secret import SECRET_KEY  # noqa\n\n# List of callables that know how to import templates from various sources.\nTEMPLATE_LOADERS = (\n    'django.template.loaders.filesystem.Loader',\n    'django.template.loaders.app_directories.Loader',\n    # 'django.template.loaders.eggs.Loader',\n)\n\nTEMPLATE_CONTEXT_PROCESSORS = (\n    'django.contrib.auth.context_processors.auth',\n    'django.core.context_processors.request',\n    'django.core.context_processors.media',\n    'core.context_processors.add_intercom_app_id'\n)\n\nMIDDLEWARE_CLASSES = (\n    'django.middleware.common.CommonMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'django.middleware.csrf.CsrfViewMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'django.contrib.messages.middleware.MessageMiddleware',\n    # Uncomment the next line for simple clickjacking protection:\n    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n    'core.custom_middleware.NavContextMiddleware'\n)\n\nROOT_URLCONF = 'core.urls'\n\n# Python dotted path to the WSGI application used by Django's runserver.\nWSGI_APPLICATION = 'core.wsgi.application'\n\nTEMPLATE_DIRS = (\n    # project level templates\n    absolute_path('core', 'base_templates'),\n    absolute_path('vota', 'templates'),\n    absolute_path('changes', 'templates'),\n\n)\n\nINSTALLED_APPS = (\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.sites',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n    'django.contrib.admin',\n    'django.contrib.syndication',\n)\n\n# A sample logging configuration. The only tangible logging\n# performed by this configuration is to send an email to\n# the site admins on every HTTP 500 error when DEBUG=False.\n# See http://docs.djangoproject.com/en/dev/topics/logging for\n# more details on how to customize your logging configuration.\nLOGGING = {\n    'version': 1,\n    'disable_existing_loggers': False,\n    'filters': {\n        'require_debug_false': {\n            '()': 'django.utils.log.RequireDebugFalse'\n        }\n    },\n    'handlers': {\n        'mail_admins': {\n            'level': 'ERROR',\n            'filters': ['require_debug_false'],\n            'class': 'django.utils.log.AdminEmailHandler'\n        }\n    },\n    'loggers': {\n        'django.request': {\n            'handlers': ['mail_admins'],\n            'level': 'ERROR',\n            'propagate': True,\n        },\n    }\n}\n", "path": "django_project/core/settings/base.py"}, {"content": "\"\"\"\nThis model is to create \"ballots\" i.e. questions/proposals/changes which a\nCommittee can vote on.\n\nAfter voting is complete, a ballot should be marked as either Denied or Passed.\n\nIf no quorum is reached, no_quorum should be True\n\nA ballot has one Committee.\n\"\"\"\nfrom django.core.urlresolvers import reverse\nfrom django.utils.text import slugify\nimport logging\nfrom core.settings.contrib import STOP_WORDS\n\nlogger = logging.getLogger(__name__)\nfrom django.db import models\nfrom audited_models.models import AuditedModel\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.utils import timezone\nfrom vota.models.vote import Vote\nimport datetime\nfrom django.contrib.auth.models import User\n\n\nclass ApprovedCategoryManager(models.Manager):\n    \"\"\"Custom category manager that shows only approved ballots.\"\"\"\n\n    def get_query_set(self):\n        \"\"\"Query set generator\"\"\"\n        return super(\n            ApprovedCategoryManager, self).get_query_set().filter(\n                approved=True)\n\n\nclass DeniedCategoryManager(models.Manager):\n    \"\"\"Custom version manager that shows only denied ballots.\"\"\"\n\n    def get_query_set(self):\n        \"\"\"Query set generator\"\"\"\n        return super(\n            DeniedCategoryManager, self).get_query_set().filter(\n                denied=True)\n\n\nclass OpenBallotManager(models.Manager):\n    \"\"\"Custom version manager that shows only open ballots.\"\"\"\n\n    def get_query_set(self):\n        \"\"\"Query set generator\"\"\"\n        return super(\n            OpenBallotManager, self).get_query_set().filter(\n                open_from__lt=timezone.now()).filter(closes__gt=timezone.now())\n\n\nclass ClosedBallotManager(models.Manager):\n    \"\"\"Custom version manager that shows only closed ballots.\"\"\"\n\n    def get_query_set(self):\n        \"\"\"Query set generator\"\"\"\n        return super(\n            ClosedBallotManager, self).get_query_set().filter(\n                closes__gt=timezone.now())\n\n\nclass Ballot(AuditedModel):\n    \"\"\"A category model e.g. gui, backend, web site etc.\"\"\"\n    name = models.CharField(\n        help_text=_('Name of this ballot.'),\n        max_length=255,\n        null=False,\n        blank=False,\n        unique=False\n    )  # there is a unique together rule in meta class below\n\n    summary = models.CharField(\n        help_text=_('A brief overview of the ballot.'),\n        max_length=250,\n        blank=False,\n        null=False\n    )\n\n    description = models.TextField(\n        help_text=_('A full description of the proposal if a summary is not '\n                    'enough!'),\n        max_length=3000,\n        null=True,\n        blank=True,\n    )\n\n    approved = models.BooleanField(\n        help_text=_(\n            'Whether this ballot has been approved.'),\n        default=False\n    )\n\n    denied = models.BooleanField(\n        help_text=_(\n            'Whether this ballot has been denied.'),\n        default=False\n    )\n\n    no_quorum = models.BooleanField(\n        help_text=_('Whether the ballot was denied because no quorum was '\n                    'reached'),\n        default=False\n    )\n\n    open_from = models.DateTimeField(\n        help_text=_('Date the ballot opens'),\n        default=timezone.now\n    )\n\n    closes = models.DateTimeField(\n        help_text=_('Date the ballot closes'),\n        default=timezone.now() + datetime.timedelta(days=7)\n    )\n\n    private = models.BooleanField(\n        help_text=_('Should members be prevented from viewing results before '\n                    'voting?'),\n        default=False\n    )\n\n    proposer = models.ForeignKey(User)\n    # noinspection PyUnresolvedReferences\n    committee = models.ForeignKey('Committee')\n    slug = models.SlugField()\n    objects = models.Manager()\n    approved_objects = ApprovedCategoryManager()\n    denied_objects = DeniedCategoryManager()\n    open_objects = OpenBallotManager()\n    closed_objects = ClosedBallotManager()\n\n    # noinspection PyClassicStyleClass\n    class Meta:\n        \"\"\"Meta options for the category class.\"\"\"\n        unique_together = (\n            ('name', 'committee'),\n            ('committee', 'slug')\n        )\n        app_label = 'vota'\n\n    def save(self, *args, **kwargs):\n        if not self.pk:\n            words = self.name.split()\n            filtered_words = [t for t in words if t.lower() not in STOP_WORDS]\n            new_list = ' '.join(filtered_words)\n            self.slug = slugify(new_list)[:50]\n        super(Ballot, self).save(*args, **kwargs)\n\n    def __unicode__(self):\n        return u'%s : %s' % (self.committee.name, self.name)\n\n    def get_absolute_url(self):\n        return reverse('ballot-detail', kwargs={\n            'project_slug': self.committee.project.slug,\n            'committee_slug': self.committee.slug,\n            'slug': self.slug\n        })\n\n    def get_user_voted(self, user=None):\n        voted = False\n        if Vote.objects.filter(ballot=self).filter(user=user).exists():\n            voted = True\n        return voted\n\n    def get_positive_vote_count(self):\n        votes = Vote.objects.filter(ballot=self).filter(choice='y').count()\n        return votes\n\n    def get_negative_vote_count(self):\n        votes = Vote.objects.filter(ballot=self).filter(choice='n').count()\n        return votes\n\n    def get_abstainer_count(self):\n        votes = Vote.objects.filter(ballot=self).filter(choice='-').count()\n        return votes\n\n    def get_current_tally(self):\n        positive = self.get_positive_vote_count()\n        negative = self.get_negative_vote_count()\n        tally = 0\n        tally += positive\n        tally -= negative\n        return tally\n\n    def get_total_vote_count(self):\n        vote_count = Vote.objects.filter(ballot=self).count()\n        return vote_count\n\n    def has_quorum(self):\n        vote_count = self.get_total_vote_count()\n        committee_user_count = self.committee.users.all().count()\n        if committee_user_count != 0:\n            quorum_percent = self.committee.quorum_setting\n            percentage = 100 * float(vote_count) / float(committee_user_count)\n            if percentage > quorum_percent:\n                return True\n        else:\n            return False\n\n    def is_open(self):\n        open_date = self.open_from\n        close_date = self.closes\n        if open_date < timezone.now() < close_date:\n            return True\n        return False\n", "path": "django_project/vota/models/ballot.py"}]}