Skip to content

Commit

Permalink
- 2020-01-16: Python 3 / Django 2 Compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Jan 16, 2020
1 parent 66bb13d commit 2f086e9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion announcements/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.13"
__version__ = "2.0.0b"
2 changes: 1 addition & 1 deletion announcements/auth_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ def authenticate(self, **kwargs):

def has_perm(self, user, perm, obj=None):
if perm == "announcements.can_manage":
return user.is_authenticated() and user.is_staff
return user.is_authenticated and user.is_staff
9 changes: 6 additions & 3 deletions announcements/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class Migration(migrations.Migration):
('publish_start',
models.DateTimeField(default=django.utils.timezone.now, verbose_name='publish_start')),
('publish_end', models.DateTimeField(null=True, verbose_name='publish_end', blank=True)),
('creator', models.ForeignKey(verbose_name='creator', to=settings.AUTH_USER_MODEL)),
('creator', models.ForeignKey(verbose_name='creator',
to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
options={
'verbose_name': 'announcement',
Expand All @@ -65,8 +66,10 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('dismissed_at', models.DateTimeField(default=django.utils.timezone.now)),
('announcement', models.ForeignKey(related_name='dismissals', to='announcements.Announcement')),
('user', models.ForeignKey(related_name='announcement_dismissals', to=settings.AUTH_USER_MODEL)),
('announcement', models.ForeignKey(related_name='dismissals',
to='announcements.Announcement', on_delete=models.CASCADE)),
('user', models.ForeignKey(related_name='announcement_dismissals',
to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
),
]
10 changes: 6 additions & 4 deletions announcements/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.db import models
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _

Expand Down Expand Up @@ -44,7 +44,7 @@ class Announcement(models.Model):
default=LEVEL_GENERAL
)
content = models.TextField(_("content"))
creator = models.ForeignKey(User, verbose_name=_("creator"))
creator = models.ForeignKey(User, verbose_name=_("creator"), on_delete=models.CASCADE)
creation_date = models.DateTimeField(_("creation_date"), default=timezone.now)
site_wide = models.BooleanField(_("site wide"), default=False)
members_only = models.BooleanField(_("members only"), default=False)
Expand Down Expand Up @@ -88,12 +88,14 @@ class Dismissal(models.Model):
user = models.ForeignKey(
User,
related_name="announcement_dismissals",
verbose_name=_("user")
verbose_name=_("user"),
on_delete=models.CASCADE
)
announcement = models.ForeignKey(
Announcement,
related_name="dismissals",
verbose_name=_("announcement")
verbose_name=_("announcement"),
on_delete=models.CASCADE
)
dismissed_at = models.DateTimeField(
_("dismissed at"),
Expand Down
8 changes: 6 additions & 2 deletions announcements/templatetags/announcements_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ def render(self, context):
site_wide=True
)

exclusions = request.session.get("excluded_announcements", set())
if request.user.is_authenticated():
if hasattr(request, 'session'):
exclusions = request.session.get(
"excluded_announcements", set())
else:
exclusions = set()
if hasattr(request, 'user') and request.user.is_authenticated:
for dismissal in request.user.announcement_dismissals.all():
exclusions.add(dismissal.announcement.pk)
else:
Expand Down
4 changes: 2 additions & 2 deletions announcements/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from django.core.urlresolvers import reverse
from django.urls import reverse
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
Expand All @@ -26,7 +26,7 @@ def dismiss(request, pk):
request.session["excluded_announcements"] = excluded
status = 200
elif announcement.dismissal_type == Announcement.DISMISSAL_PERMANENT and \
request.user.is_authenticated():
request.user.is_authenticated:
announcement.dismissals.create(user=request.user)
status = 200
else:
Expand Down

0 comments on commit 2f086e9

Please sign in to comment.