Skip to content

Commit

Permalink
Merge pull request #2431 from dotkom/upgrade/django-3.0
Browse files Browse the repository at this point in the history
Upgrade/django 3.0
  • Loading branch information
oleast authored Mar 29, 2020
2 parents 66a4c9e + 0c6d711 commit 872d1d6
Show file tree
Hide file tree
Showing 51 changed files with 149 additions and 105 deletions.
2 changes: 1 addition & 1 deletion apps/approval/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.shortcuts import render
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic import (
CreateView,
Expand Down
2 changes: 1 addition & 1 deletion apps/approval/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django import forms
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from apps.authentication.constants import FieldOfStudyType

Expand Down
2 changes: 1 addition & 1 deletion apps/approval/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db.models import Case, ExpressionWrapper, F, Q, When
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from apps.approval import settings as approval_settings
from apps.authentication.constants import FieldOfStudyType
Expand Down
2 changes: 1 addition & 1 deletion apps/approval/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.http import Http404
from django.shortcuts import get_object_or_404, redirect
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from apps.approval.forms import FieldOfStudyApplicationForm
from apps.approval.models import MembershipApproval
Expand Down
2 changes: 1 addition & 1 deletion apps/article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.db.models import SET_NULL
from django.template.defaultfilters import slugify
from django.urls import reverse
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from taggit.managers import TaggableManager
from unidecode import unidecode

Expand Down
2 changes: 1 addition & 1 deletion apps/authentication/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from reversion.admin import VersionAdmin

from apps.authentication.models import (
Expand Down
8 changes: 4 additions & 4 deletions apps/authentication/api/tests/user_data_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_user_cannot_create_an_email_with_an_existing_address(self):
def test_user_can_change_primary_email(self):
self.assertTrue(self.email.primary)

email: Email = G(Email, user=self.user, verfied=False)
email: Email = G(Email, user=self.user, verified=False)

response = self.client.patch(
self.id_url(email.id), {"primary": True}, **self.headers
Expand All @@ -89,7 +89,7 @@ def test_user_can_change_primary_email(self):
def test_user_cannot_remove_primary_email_without_selecting_a_new_primary(self):
self.assertTrue(self.email.primary)

email: Email = G(Email, user=self.user, verfied=False)
email: Email = G(Email, user=self.user, verified=False)

response = self.client.patch(
self.id_url(email.id), {"primary": False}, **self.headers
Expand All @@ -108,7 +108,7 @@ def test_user_cannot_remove_primary_email_without_selecting_a_new_primary(self):
self.assertTrue(self.email.primary)

def test_user_cannot_verify_emails_without_token(self):
email: Email = G(Email, user=self.user, verfied=False)
email: Email = G(Email, user=self.user, verified=False)
response = self.client.patch(
self.id_url(email.id), {"verified": True}, **self.headers
)
Expand All @@ -121,7 +121,7 @@ def test_user_cannot_verify_emails_without_token(self):
def test_user_cannot_change_the_address_of_an_existing_email(self):
address = "[email protected]"
other_address = "[email protected]"
email: Email = G(Email, user=self.user, verfied=False, email=address)
email: Email = G(Email, user=self.user, verified=False, email=address)
self.client.patch(
self.id_url(email.id), {"email": other_address}, **self.headers
)
Expand Down
2 changes: 1 addition & 1 deletion apps/authentication/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _


class GroupType:
Expand Down
2 changes: 1 addition & 1 deletion apps/authentication/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django import forms
from django.contrib import auth
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from apps.authentication.models import Email
from apps.authentication.models import OnlineUser as User
Expand Down
2 changes: 1 addition & 1 deletion apps/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.urls import reverse
from django.utils import timezone
from django.utils.html import strip_tags
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from rest_framework.exceptions import NotAcceptable

from apps.authentication.constants import FieldOfStudyType, GroupType, RoleType
Expand Down
2 changes: 1 addition & 1 deletion apps/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.shortcuts import get_object_or_404, redirect, render
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from django.views.decorators.debug import sensitive_post_parameters

from apps.authentication.forms import (
Expand Down
2 changes: 1 addition & 1 deletion apps/careeropportunity/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from taggit.managers import TaggableManager

from apps.companyprofile.models import Company
Expand Down
2 changes: 1 addition & 1 deletion apps/companyprofile/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from apps.gallery.models import ResponsiveImage

Expand Down
32 changes: 16 additions & 16 deletions apps/dashboard/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.forms.utils import format_html
from django.forms.widgets import TextInput
from django.utils.encoding import force_text
from django.utils.encoding import force_str

DATEPICKER_WIDGET_STRING = """
<div class="input-group dp">\r\n
Expand Down Expand Up @@ -105,7 +105,7 @@ def render(self, name, value, attrs=None, renderer=None):
final_attrs = self.build_attrs(attrs, {"type": self.input_type, "name": name})
if value != "":
final_attrs["value"] = format_html(
'value="{}"', force_text(self.format_value(value))
'value="{}"', force_str(self.format_value(value))
)
else:
final_attrs["value"] = ""
Expand All @@ -114,13 +114,13 @@ def render(self, name, value, attrs=None, renderer=None):
final_attrs["placeholder"] = "Vennligst velg en dato ..."
if attrs.get("placeholder", False):
# Update the placeholder text if supplied.
final_attrs["placeholder"] = force_text(attrs.get("placeholder"))
final_attrs["placeholder"] = force_str(attrs.get("placeholder"))

return format_html(
DATEPICKER_WIDGET_STRING,
id=force_text(final_attrs["id"]),
name=force_text(final_attrs["name"]),
placeholder=force_text(final_attrs["placeholder"]),
id=force_str(final_attrs["id"]),
name=force_str(final_attrs["name"]),
placeholder=force_str(final_attrs["placeholder"]),
value=final_attrs["value"],
)

Expand Down Expand Up @@ -149,21 +149,21 @@ def render(self, name, value, attrs=None, renderer=None):
attrs = self.build_attrs(self.attrs, attrs)
final_attrs = self.build_attrs(attrs, {"type": self.input_type, "name": name})
if value != "":
final_attrs["value"] = force_text(self.format_value(value))
final_attrs["value"] = force_str(self.format_value(value))
else:
final_attrs["value"] = ""

# Kept for backwards compatibility with existing forms.
final_attrs["placeholder"] = "Vennligst velg dato og klokkeslett ..."
if self.attrs.get("placeholder", False):
# Update the placeholder text if supplied.
final_attrs["placeholder"] = force_text(self.attrs.get("placeholder"))
final_attrs["placeholder"] = force_str(self.attrs.get("placeholder"))

return format_html(
DATETIMEPICKER_WIDGET_STRING,
id=force_text(final_attrs["id"]),
name=force_text(final_attrs["name"]),
placeholder=force_text(final_attrs["placeholder"]),
id=force_str(final_attrs["id"]),
name=force_str(final_attrs["name"]),
placeholder=force_str(final_attrs["placeholder"]),
value=final_attrs["value"],
)

Expand Down Expand Up @@ -193,7 +193,7 @@ def render(self, name, value, attrs=None, renderer=None):
final_attrs = self.build_attrs(attrs, {"type": self.input_type, "name": name})
if value != "":
final_attrs["value"] = format_html(
'value="{}"', force_text(self.format_value(value))
'value="{}"', force_str(self.format_value(value))
)
else:
final_attrs["value"] = ""
Expand All @@ -202,12 +202,12 @@ def render(self, name, value, attrs=None, renderer=None):
final_attrs["placeholder"] = "Vennligst velg klokkeslett ..."
if attrs.get("placeholder", False):
# Update the placeholder text if supplied.
final_attrs["placeholder"] = force_text(attrs.get("placeholder"))
final_attrs["placeholder"] = force_str(attrs.get("placeholder"))

return format_html(
TIMEPICKER_WIDGET_STRING,
id=force_text(final_attrs["id"]),
name=force_text(final_attrs["name"]),
placeholder=force_text(final_attrs["placeholder"]),
id=force_str(final_attrs["id"]),
name=force_str(final_attrs["name"]),
placeholder=force_str(final_attrs["placeholder"]),
value=final_attrs["value"],
)
4 changes: 2 additions & 2 deletions apps/dataporten/study/tests/task_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_fetch_groups_information(self, mocked_request):

class StudyUpdatingTestCase(TestCase):
def test_find_user_study_and_update_1st_grader(self):
user = G(OnlineUser)
user = G(OnlineUser, ntnu_username="testesen")
groups = [
INFORMATICS_BACHELOR_STUDY_PROGRAMME,
load_course(ITGK_ACTIVE, years_ago=0),
Expand All @@ -57,7 +57,7 @@ def test_find_user_study_and_update_1st_grader(self):
self.assertEqual(len(mail.outbox), 0)

def test_find_user_study_and_update_5th_grader(self):
user = G(OnlineUser)
user = G(OnlineUser, ntnu_username="testesen")
groups = [
INFORMATICS_MASTER_STUDY_PROGRAMME,
load_course(PVS_ACTIVE, active=True),
Expand Down
2 changes: 1 addition & 1 deletion apps/events/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

from django.contrib import admin, messages
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from guardian.admin import GuardedModelAdmin
from reversion.admin import VersionAdmin

Expand Down
2 changes: 1 addition & 1 deletion apps/events/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from django.views.generic import CreateView, DeleteView, UpdateView
from guardian.decorators import permission_required
from guardian.shortcuts import get_objects_for_user
Expand Down
2 changes: 1 addition & 1 deletion apps/events/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from captcha.fields import ReCaptchaField
from django import forms
from django.conf import settings
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from apps.authentication.models import OnlineUser as User
from apps.marks.models import MarkRuleSet
Expand Down
2 changes: 1 addition & 1 deletion apps/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from guardian.shortcuts import assign_perm
from unidecode import unidecode

Expand Down
6 changes: 4 additions & 2 deletions apps/events/tests/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def test_event_with_group_restriction(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)

restricted_to_group: Group = G(Group)
G(GroupRestriction, event=self.event, group=restricted_to_group)
G(GroupRestriction, event=self.event, groups=[restricted_to_group])

response = self.client.get(self.id_url(self.event.id), **self.headers)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Expand All @@ -502,7 +502,9 @@ def test_event_with_group_restriction(self):
class AttendAPITestCase(OIDCTestCase):
def setUp(self):
self.committee = G(Group, name="Arrkom")
self.user = G(OnlineUser, name="test_user", groups=[self.committee])
self.user = G(
OnlineUser, first_name="Test", last_name="Testesen", groups=[self.committee]
)
self.token = self.generate_access_token(self.user)
self.headers = {
**self.generate_headers(),
Expand Down
4 changes: 3 additions & 1 deletion apps/events/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def add_payment_delay(payment: Payment, user: OnlineUser) -> PaymentDelay:


def generate_user(username: str) -> OnlineUser:
user = G(OnlineUser, username=username, ntnu_username=username)
user = G(
OnlineUser, username=username, ntnu_username=username, phone_number="12345678"
)
G(Email, user=user)
return user

Expand Down
2 changes: 1 addition & 1 deletion apps/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from guardian.shortcuts import get_objects_for_user
from rest_framework import mixins, permissions, status, viewsets
from rest_framework.decorators import action
Expand Down
2 changes: 1 addition & 1 deletion apps/feedback/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.urls import reverse
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from apps.authentication.constants import FieldOfStudyType
from apps.authentication.models import OnlineUser
Expand Down
2 changes: 1 addition & 1 deletion apps/feedback/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from collections import OrderedDict

from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from rest_framework import serializers

from .models import (
Expand Down
2 changes: 1 addition & 1 deletion apps/feedback/tests/base_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.test.client import Client
from django.urls import reverse
from django.utils import timezone as timezone
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django_dynamic_fixture import G

from apps.authentication.models import Email, OnlineGroup
Expand Down
2 changes: 1 addition & 1 deletion apps/feedback/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.db.models import Prefetch
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from rest_framework import mixins, permissions, status, viewsets
from rest_framework.decorators import action
from rest_framework.response import Response
Expand Down
2 changes: 1 addition & 1 deletion apps/gallery/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from taggit.managers import TaggableManager

from apps.gallery import settings as gallery_settings
Expand Down
4 changes: 2 additions & 2 deletions apps/gallery/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.forms import HiddenInput, TextInput
from django.forms.utils import flatatt, format_html
from django.urls import reverse_lazy
from django.utils.encoding import force_text
from django.utils.encoding import force_str

from apps.gallery.models import ResponsiveImage

Expand Down Expand Up @@ -62,7 +62,7 @@ def render(self, name, value, attrs=None, renderer=None):
final_attrs = self.build_attrs(attrs, {"type": self.input_type, "name": name})
if value != "":
# Only add the value attribute if the value is non-empty
final_attrs["value"] = force_text(self.format_value(value))
final_attrs["value"] = force_str(self.format_value(value))
img = ResponsiveImage.objects.get(pk=value)
img_thumb = format_html(
'<img src="{}" alt title="{}"/>',
Expand Down
Loading

0 comments on commit 872d1d6

Please sign in to comment.