From 2e72d86bb0cdf51db5e3edb614b7b486d9b72761 Mon Sep 17 00:00:00 2001 From: Mark Beacom Date: Thu, 9 Aug 2018 00:30:51 -0400 Subject: [PATCH] Upgrade django to 2.1, modify field defaults, and address deprecations (#1915) * Upgrade django to 2.1 and address deprecations * Remove commented out imports * fix: sticker issue * Update reqs * Remove unused import --- app/app/urls.py | 2 +- app/dashboard/models.py | 24 +++++----- app/dashboard/views.py | 2 +- app/dataviz/models.py | 2 +- app/dataviz/templates/cohort.html | 2 +- app/dataviz/templates/dataviz/calendar.html | 2 +- app/dataviz/templates/dataviz/chord.html | 4 +- app/dataviz/templates/dataviz/circles.html | 2 +- app/dataviz/templates/dataviz/heatmap.html | 2 +- app/dataviz/templates/dataviz/index.html | 2 +- app/dataviz/templates/dataviz/spiral.html | 2 +- .../templates/dataviz/square_graph.html | 48 +++++++++---------- app/dataviz/templates/dataviz/steamgraph.html | 2 +- app/dataviz/templates/dataviz/sunburst.html | 2 +- app/dataviz/templates/funnel.html | 2 +- app/dataviz/templates/stats.html | 2 +- app/economy/models.py | 2 +- app/external_bounties/models.py | 2 +- app/faucet/models.py | 2 +- .../templates/process_faucet_request.html | 2 +- app/marketing/models.py | 14 +++--- app/retail/templates/admin/index.html | 2 +- .../templates/process_accesscode_request.html | 2 +- app/retail/templates/resend_tip.html | 2 +- app/retail/views.py | 2 +- requirements/base.txt | 14 +++--- requirements/test.txt | 1 - setup.cfg | 2 - 28 files changed, 73 insertions(+), 76 deletions(-) diff --git a/app/app/urls.py b/app/app/urls.py index f7880f8ef4a..0745846821d 100644 --- a/app/app/urls.py +++ b/app/app/urls.py @@ -351,7 +351,7 @@ # Legacy Support path('legacy/', include('legacy.urls', namespace='legacy')), - re_path(r'^logout/$', auth_views.logout, name='logout'), + path('logout/', auth_views.LogoutView.as_view(), name='logout'), re_path(r'^gh-login/$', dashboard.views.gh_login, name='gh_login'), path('', include('social_django.urls', namespace='social')), # webhook routes diff --git a/app/dashboard/models.py b/app/dashboard/models.py index 8c3bbed4009..ad8aede1d80 100644 --- a/app/dashboard/models.py +++ b/app/dashboard/models.py @@ -28,11 +28,11 @@ from django.contrib.auth.signals import user_logged_in, user_logged_out from django.contrib.humanize.templatetags.humanize import naturalday, naturaltime from django.contrib.postgres.fields import ArrayField, JSONField -from django.contrib.staticfiles.templatetags.staticfiles import static from django.db import models from django.db.models import Q, Sum from django.db.models.signals import m2m_changed, post_delete, post_save, pre_save from django.dispatch import receiver +from django.templatetags.static import static from django.urls import reverse from django.urls.exceptions import NoReverseMatch from django.utils import timezone @@ -222,7 +222,7 @@ class Bounty(SuperModel): project_length = models.CharField(max_length=50, choices=PROJECT_LENGTHS, blank=True) experience_level = models.CharField(max_length=50, choices=EXPERIENCE_LEVELS, blank=True) github_url = models.URLField(db_index=True) - github_issue_details = JSONField(default={}, blank=True, null=True) + github_issue_details = JSONField(default=dict, blank=True, null=True) github_comments = models.IntegerField(default=0) bounty_owner_address = models.CharField(max_length=50) bounty_owner_email = models.CharField(max_length=255, blank=True) @@ -234,7 +234,7 @@ class Bounty(SuperModel): is_open = models.BooleanField(help_text=_('Whether the bounty is still open for fulfillments.')) expires_date = models.DateTimeField() raw_data = JSONField() - metadata = JSONField(default={}, blank=True) + metadata = JSONField(default=dict, blank=True) current_bounty = models.BooleanField( default=False, help_text=_('Whether this bounty is the most current revision one or not')) _val_usd_db = models.DecimalField(default=0, decimal_places=2, max_digits=50) @@ -267,7 +267,7 @@ class Bounty(SuperModel): value_in_usdt = models.DecimalField(default=0, decimal_places=2, max_digits=50, blank=True, null=True) value_in_eth = models.DecimalField(default=0, decimal_places=2, max_digits=50, blank=True, null=True) value_true = models.DecimalField(default=0, decimal_places=2, max_digits=50, blank=True, null=True) - privacy_preferences = JSONField(default={}, blank=True) + privacy_preferences = JSONField(default=dict, blank=True) admin_override_and_hide = models.BooleanField( default=False, help_text=_('Admin override to hide the bounty from the system') ) @@ -939,7 +939,7 @@ class BountyFulfillment(SuperModel): fulfiller_email = models.CharField(max_length=255, blank=True) fulfiller_github_username = models.CharField(max_length=255, blank=True) fulfiller_name = models.CharField(max_length=255, blank=True) - fulfiller_metadata = JSONField(default={}, blank=True) + fulfiller_metadata = JSONField(default=dict, blank=True) fulfillment_id = models.IntegerField(null=True, blank=True) fulfiller_hours_worked = models.DecimalField(null=True, blank=True, decimal_places=2, max_digits=50) fulfiller_github_url = models.CharField(max_length=255, blank=True, null=True) @@ -1031,7 +1031,7 @@ class Tip(SuperModel): sender_profile = models.ForeignKey( 'dashboard.Profile', related_name='sent_tips', on_delete=models.SET_NULL, null=True, blank=True ) - metadata = JSONField(default={}, blank=True) + metadata = JSONField(default=dict, blank=True) is_for_bounty_fulfiller = models.BooleanField( default=False, help_text='If this option is chosen, this tip will be automatically paid to the bounty' @@ -1418,7 +1418,7 @@ class Activity(models.Model): tip = models.ForeignKey('dashboard.Tip', related_name='activities', on_delete=models.CASCADE, blank=True, null=True) created = models.DateTimeField(auto_now_add=True, blank=True, null=True) activity_type = models.CharField(max_length=50, choices=ACTIVITY_TYPES, blank=True) - metadata = JSONField(default={}) + metadata = JSONField(default=dict) needs_review = models.BooleanField(default=False) # Activity QuerySet Manager @@ -1488,10 +1488,10 @@ class Profile(SuperModel): email = models.CharField(max_length=255, blank=True, db_index=True) github_access_token = models.CharField(max_length=255, blank=True, db_index=True) pref_lang_code = models.CharField(max_length=2, choices=settings.LANGUAGES, blank=True) - slack_repos = ArrayField(models.CharField(max_length=200), blank=True, default=[]) + slack_repos = ArrayField(models.CharField(max_length=200), blank=True, default=list) slack_token = models.CharField(max_length=255, default='', blank=True) slack_channel = models.CharField(max_length=255, default='', blank=True) - discord_repos = ArrayField(models.CharField(max_length=200), blank=True, default=[]) + discord_repos = ArrayField(models.CharField(max_length=200), blank=True, default=list) discord_webhook_url = models.CharField(max_length=400, default='', blank=True) suppress_leaderboard = models.BooleanField( default=False, @@ -1505,7 +1505,7 @@ class Profile(SuperModel): default=False, help_text='If this option is chosen, the user is able to submit a faucet/ens domain registration even if they are new to github', ) - form_submission_records = JSONField(default=[], blank=True) + form_submission_records = JSONField(default=list, blank=True) # Sample data: https://gist.github.com/mbeacom/ee91c8b0d7083fa40d9fa065125a8d48 max_num_issues_start_work = models.IntegerField(default=3) preferred_payout_address = models.CharField(max_length=255, default='', blank=True) @@ -2302,8 +2302,8 @@ class UserAction(SuperModel): user = models.ForeignKey(User, related_name='actions', on_delete=models.SET_NULL, null=True) profile = models.ForeignKey('dashboard.Profile', related_name='actions', on_delete=models.CASCADE, null=True) ip_address = models.GenericIPAddressField(null=True) - location_data = JSONField(default={}) - metadata = JSONField(default={}) + location_data = JSONField(default=dict) + metadata = JSONField(default=dict) def __str__(self): return f"{self.action} by {self.profile} at {self.created_on}" diff --git a/app/dashboard/views.py b/app/dashboard/views.py index 0cfea23d79c..915f43f29a3 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -26,11 +26,11 @@ from django.contrib import messages from django.contrib.admin.views.decorators import staff_member_required from django.contrib.auth.models import User -from django.contrib.staticfiles.templatetags.staticfiles import static from django.core.cache import cache from django.http import Http404, JsonResponse from django.shortcuts import redirect from django.template.response import TemplateResponse +from django.templatetags.static import static from django.utils import timezone from django.utils.text import slugify from django.utils.translation import gettext_lazy as _ diff --git a/app/dataviz/models.py b/app/dataviz/models.py index cec93fe3664..2a7f1639f3e 100644 --- a/app/dataviz/models.py +++ b/app/dataviz/models.py @@ -29,7 +29,7 @@ class DataPayload(SuperModel): key = models.CharField(db_index=True, max_length=255, help_text=_("key for this data report")) report = models.CharField(max_length=255, blank=True, help_text=_("The report associated with this project")) - payload = JSONField(default={}, blank=True) + payload = JSONField(default=dict, blank=True) comments = models.TextField(blank=True) def __str__(self): diff --git a/app/dataviz/templates/cohort.html b/app/dataviz/templates/cohort.html index 00edebc047a..0f48b1f2bb0 100644 --- a/app/dataviz/templates/cohort.html +++ b/app/dataviz/templates/cohort.html @@ -18,7 +18,7 @@ {% endcomment %} -{% load i18n admin_static static %} +{% load i18n static %} {% block extrastyle %}{{ block.super }}{% endblock %} diff --git a/app/dataviz/templates/dataviz/calendar.html b/app/dataviz/templates/dataviz/calendar.html index 99619267f40..471759f84bb 100644 --- a/app/dataviz/templates/dataviz/calendar.html +++ b/app/dataviz/templates/dataviz/calendar.html @@ -1,4 +1,4 @@ -{% load i18n admin_static static %} +{% load i18n static %} < back diff --git a/app/dataviz/templates/dataviz/chord.html b/app/dataviz/templates/dataviz/chord.html index 1d1c6706453..ecfd9104125 100644 --- a/app/dataviz/templates/dataviz/chord.html +++ b/app/dataviz/templates/dataviz/chord.html @@ -1,4 +1,4 @@ -{% load i18n admin_static static %} +{% load i18n static %}