Skip to content

Commit

Permalink
Upgrade django to 2.1, modify field defaults, and address deprecations (
Browse files Browse the repository at this point in the history
gitcoinco#1915)

* Upgrade django to 2.1 and address deprecations

* Remove commented out imports

* fix: sticker issue

* Update reqs

* Remove unused import
  • Loading branch information
Mark Beacom authored Aug 9, 2018
1 parent c12244f commit 2e72d86
Show file tree
Hide file tree
Showing 28 changed files with 73 additions and 76 deletions.
2 changes: 1 addition & 1 deletion app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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')
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand Down
2 changes: 1 addition & 1 deletion app/dataviz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion app/dataviz/templates/cohort.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{% endcomment %}

{% load i18n admin_static static %}
{% load i18n static %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}">{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion app/dataviz/templates/dataviz/calendar.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n admin_static static %}
{% load i18n static %}
<!DOCTYPE html>
<body>
<a href="..">&lt; back</a>
Expand Down
4 changes: 2 additions & 2 deletions app/dataviz/templates/dataviz/chord.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n admin_static static %}
{% load i18n static %}
<!DOCTYPE html>
<meta charset="utf-8">
<style>
Expand Down Expand Up @@ -165,4 +165,4 @@ <h1> payers (top) / payees (top) </h1>
return this.amount;
}

</script>
</script>
2 changes: 1 addition & 1 deletion app/dataviz/templates/dataviz/circles.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{% endcomment %}

{% load i18n admin_static static %}
{% load i18n static %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}">{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion app/dataviz/templates/dataviz/heatmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{% endcomment %}

{% load i18n admin_static static %}
{% load i18n static %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}">{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion app/dataviz/templates/dataviz/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{% endcomment %}

{% load i18n admin_static static %}
{% load i18n static %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}">{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion app/dataviz/templates/dataviz/spiral.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{% endcomment %}

{% load i18n admin_static static %}
{% load i18n static %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}">{% endblock %}

Expand Down
48 changes: 24 additions & 24 deletions app/dataviz/templates/dataviz/square_graph.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n admin_static static %}
{% load i18n static %}

<style>
body {
Expand Down Expand Up @@ -99,12 +99,12 @@
sankey.layout = function(iterations) {
computeNodeLinks();
computeNodeValues();

// big changes here
// change the order and depths (y pos) won't need iterations
computeNodeDepths();
computeNodeBreadths(iterations);

computeLinkDepths();
return sankey;
};
Expand All @@ -119,13 +119,13 @@

// x0 = line start X
// y0 = line start Y

// x1 = line end X
// y1 = line end Y

// y2 = control point 1 (Y pos)
// y3 = control point 2 (Y pos)

function link(d) {

// big changes here obviously, more comments to follow
Expand All @@ -139,7 +139,7 @@

// ToDo - nice to have - allow flow up or down! Plenty of use cases for starting at the bottom,
// but main one is trickle down (economics, budgets etc), not up

return 'M' + x0 + ',' + y0 + // start (of SVG path)
'C' + x0 + ',' + y2 + // CP1 (curve control point)
' ' + x1 + ',' + y3 + // CP2
Expand Down Expand Up @@ -220,19 +220,19 @@
links.forEach(function(link) {
link.dy = link.value * ky;
});

resolveCollisions();

for (var alpha = 1; iterations > 0; --iterations) {
relaxLeftToRight(alpha);
resolveCollisions();

relaxRightToLeft(alpha *= .99);
resolveCollisions();
}

// these relax methods should probably be operating on one level of the nodes, not all!?

function relaxLeftToRight(alpha) {
nodesByBreadth.forEach(function(nodes, breadth) {
nodes.forEach(function(node) {
Expand Down Expand Up @@ -264,7 +264,7 @@
return center(link.target) * link.value;
}
}

function resolveCollisions() {
nodesByBreadth.forEach(function(nodes) {
var node,
Expand Down Expand Up @@ -299,14 +299,14 @@
}
});
}

function ascendingDepth(a, b) {
// return a.y - b.y; // flows go up
return b.x - a.x; // flows go down
// return a.x - b.x;
}
}

// this moves all end points (sinks!) to the most extreme bottom
function moveSinksDown(y) {
nodes.forEach(function(node) {
Expand Down Expand Up @@ -345,10 +345,10 @@

// move end points to the very bottom
moveSinksDown(y);

scaleNodeBreadths((size[1] - nodeWidth) / (y - 1));
}

// .ty is the offset in terms of node position of the link (target)
function computeLinkDepths() {
nodes.forEach(function(node) {
Expand Down Expand Up @@ -400,9 +400,9 @@
<body>
<a href="..">&lt; back</a>
{% include "dataviz/shared/nav.html" %}

<p id="chart">

<script>

var margin = {top: 1, right: 1, bottom: 6, left: 1},
Expand All @@ -428,7 +428,7 @@
var path = sankey.link();

var url = document.location.href + '?data=1&format=json';
d3.json(url, function(energy) {
d3.json(url, function(energy) {
sankey
.nodes(energy.nodes)
.links(energy.links)
Expand All @@ -446,13 +446,13 @@
link.append("title")
.text(function(d) { return d.source.name + " → " + d.target.name + "\n" + format(d.value); });
// title is an SVG standard way of providing tooltips, up to the browser how to render this, so changing the style is tricky

var node = svg.append("g").selectAll(".node")
.data(energy.nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")";
return "translate(" + d.x + "," + d.y + ")";
})
.call(d3.behavior.drag()
.origin(function(d) { return d; })
Expand All @@ -466,15 +466,15 @@
.style("stroke", function(d) { return d3.rgb(d.color).darker(2); })
.append("title")
.text(function(d) { return d.name + "\n" + format(d.value); });

node.append("text")
.attr("text-anchor", "middle")
.attr("x", function (d) { return d.dy / 2 })
.attr("y", sankey.nodeWidth() / 2)
.attr("dy", ".35em")
.text(function(d) { return d.name; })
.filter(function(d) { return d.x < width / 2; });

function dragmove(d) {
//d3.select(this).attr("transform", "translate(" + d.x + "," + (d.y = Math.max(0, Math.min(height - d.dy, d3.event.y))) + ")");
d3.select(this).attr("transform", "translate(" + (d.x = Math.max(0, Math.min(width - d.dy, d3.event.x))) + "," + d.y + ")");
Expand Down
2 changes: 1 addition & 1 deletion app/dataviz/templates/dataviz/steamgraph.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{% endcomment %}

{% load i18n admin_static static %}
{% load i18n static %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}">{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion app/dataviz/templates/dataviz/sunburst.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{% endcomment %}

{% load i18n admin_static static %}
{% load i18n static %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}">{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion app/dataviz/templates/funnel.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{% endcomment %}

{% load i18n admin_static static %}
{% load i18n static %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}">{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion app/dataviz/templates/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
{% endcomment %}
{% load i18n admin_static static %}
{% load i18n static %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}">{% endblock %}
{% block coltype %}colMS{% endblock %}
{% block bodyclass %}{{ block.super }} dashboard{% endblock %}
Expand Down
Loading

0 comments on commit 2e72d86

Please sign in to comment.