Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup syntax and linting issues for backend code #577

Merged
merged 3 commits into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
'''
import os
import socket
from datetime import datetime

from django.http import Http404

import rollbar
from pytz import utc

HOSTNAME = socket.gethostname()

Expand Down
1 change: 1 addition & 0 deletions app/app/sitemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


class StaticViewSitemap(sitemaps.Sitemap):

priority = 0.5
changefreq = 'weekly'

Expand Down
4 changes: 2 additions & 2 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'''
from django.conf import settings
from django.conf.urls import handler400, handler403, handler404, handler500, include, url
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.sitemaps.views import sitemap
from django.urls import path, re_path
Expand All @@ -43,7 +43,7 @@
url(r'^api/v0.1/funding/save/?', dashboard.ios.save, name='save'),
url(r'^api/v0.1/faucet/save/?', faucet.views.save_faucet, name='save_faucet'),
url(r'^api/v0.1/', include(router.urls)),
url(r'^actions/api/v0.1/', include(router.urls)), # same as active, but not cached in cluodfront
url(r'^actions/api/v0.1/', include(router.urls)), # same as active, but not cached in cluodfront

# dashboard views

Expand Down
3 changes: 0 additions & 3 deletions app/credits/admin.py

This file was deleted.

1 change: 1 addition & 0 deletions app/credits/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@


class CreditsConfig(AppConfig):

name = 'credits'
3 changes: 0 additions & 3 deletions app/credits/models.py

This file was deleted.

3 changes: 0 additions & 3 deletions app/credits/tests.py

This file was deleted.

6 changes: 2 additions & 4 deletions app/credits/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
from linkshortener.models import Link


#TODO: delete this view (and the app) after ETHDenver
# TODO: delete this view (and the app) after ETHDenver
def credits(request, shortcode):

num_credits = 5

try:
link = Link.objects.get(shortcode=shortcode)
num_remaining = num_credits - link.uses
if num_remaining >= 0:
return HttpResponse("<h1>Success</h1>")
else:
return HttpResponse("<h1>FAIL. You're out of credits!</h1>")
return HttpResponse("<h1>FAIL. You're out of credits!</h1>")
except Exception as e:
print(e)
raise Http404
5 changes: 2 additions & 3 deletions app/dashboard/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def resend(self, instance):


# Register your models here.
class Bounty_Admin(admin.ModelAdmin):
class BountyAdmin(admin.ModelAdmin):
ordering = ['-id']

search_fields = ['raw_data', 'title', 'bounty_owner_github_username', 'token_name']
Expand Down Expand Up @@ -80,12 +80,11 @@ def network_link(self, instance):
return mark_safe(f"<a href={url}>{copy}</a>")



admin.site.register(Subscription, GeneralAdmin)
admin.site.register(UserAction, GeneralAdmin)
admin.site.register(Interest, GeneralAdmin)
admin.site.register(Profile, ProfileAdmin)
admin.site.register(Bounty, Bounty_Admin)
admin.site.register(Bounty, BountyAdmin)
admin.site.register(BountyFulfillment, GeneralAdmin)
admin.site.register(BountySyncRequest, GeneralAdmin)
admin.site.register(Tip, TipAdmin)
Expand Down
45 changes: 23 additions & 22 deletions app/dashboard/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def stat(request, key):
from django.utils import timezone
limit = 10
weekly_stats = Stat.objects.filter(key=key).order_by('created_on')
weekly_stats = weekly_stats.filter(created_on__hour=1, created_on__week_day=1).filter(created_on__gt=(timezone.now() - timezone.timedelta(weeks=7))) #weekly stats only
weekly_stats = weekly_stats.filter(created_on__hour=1, created_on__week_day=1).filter(created_on__gt=(timezone.now() - timezone.timedelta(weeks=7))) # weekly stats only

daily_stats = Stat.objects.filter(key=key).filter(created_on__gt=(timezone.now() - timezone.timedelta(days=7))).order_by('created_on')
daily_stats = daily_stats.filter(created_on__hour=1) #daily stats only
daily_stats = daily_stats.filter(created_on__hour=1) # daily stats only

stats = weekly_stats if weekly_stats.count() < limit else daily_stats

Expand All @@ -73,6 +73,7 @@ def stat(request, key):
canvas.print_png(response)
return response


@ratelimit(key='ip', rate='50/m', method=ratelimit.UNSAFE, block=True)
def embed(request):
# default response
Expand Down Expand Up @@ -111,14 +112,14 @@ def embed(request):
# make transparent
datas = avatar.getdata()

newData = []
new_data = []
for item in datas:
if item[0] == 255 and item[1] == 255 and item[2] == 255:
newData.append((255, 255, 255, 0))
new_data.append((255, 255, 255, 0))
else:
newData.append(item)
new_data.append(item)

avatar.putdata(newData)
avatar.putdata(new_data)
avatar.save(filepath, "PNG")

# get issues
Expand Down Expand Up @@ -146,29 +147,29 @@ def embed(request):
p = ImageFont.truetype(font_path + 'Futura-LightBT.ttf', 20, encoding="unic")

# background
## config
# config
logo = 'assets/v2/images/header-bg-light.jpg'
## execute
# execute
back = Image.open(logo, 'r').convert("RGBA")
img_w, img_h = back.size
bg_w, bg_h = img.size
offset = 0, 0
img.paste(back, offset)

# repo logo
## config
# config
icon_size = (215, 215)
## execute
# execute
img_w, img_h = avatar.size
avatar.thumbnail(icon_size, Image.ANTIALIAS)
bg_w, bg_h = img.size
offset = 10, 10
img.paste(avatar, offset, avatar)

# gitcoin logo
## config
# config
logo = 'assets/v2/images/gitcoinco.png'
## execute
# execute
back = Image.open(logo, 'r').convert("RGBA")
back.thumbnail(icon_size, Image.ANTIALIAS)
img_w, img_h = back.size
Expand All @@ -178,7 +179,7 @@ def embed(request):
img.paste(back, offset, back)

# plus sign
## config
# config
if not is_org_gitcoin:
text = '+'
# execute
Expand All @@ -191,7 +192,7 @@ def embed(request):
draw = ImageDraw.Draw(img)

# header
## config
# config
text = '{} Supports Funded Issues'.format(_org_name.title())
# execute
text = wrap_text(text, 30)
Expand All @@ -202,7 +203,7 @@ def embed(request):
draw.multiline_text(align="left", xy=(x, y), text=text, fill=black, font=h1, spacing=spacing)
draw = ImageDraw.Draw(img)

## config
# config
show_value, value = summarize_bounties(super_bounties)
text = '{}\nGrow Open Source | Powered by Gitcoin.co'.format(wrap_text(value, 45) if show_value else "")
# execute
Expand Down Expand Up @@ -241,7 +242,7 @@ def embed(request):
draw = ImageDraw.Draw(img)

if bounties.count() != 0:
## config
# config
text = 'Browse Issues @ https://gitcoin.co/explorer'
# execute
text = wrap_text(text, 20)
Expand Down Expand Up @@ -296,22 +297,22 @@ def avatar(request):
# make transparent
datas = avatar.getdata()

newData = []
new_data = []
for item in datas:
if item[0] == 255 and item[1] == 255 and item[2] == 255:
newData.append((255, 255, 255, 0))
new_data.append((255, 255, 255, 0))
else:
newData.append(item)
new_data.append(item)

avatar.putdata(newData)
avatar.putdata(new_data)
avatar.save(filepath, "PNG")

width, height = (215, 215)
img = Image.new("RGBA", (width, height), (255, 255, 255))

## config
# config
icon_size = (215, 215)
## execute
# execute
avatar = ImageOps.fit(avatar, icon_size, Image.ANTIALIAS)
bg_w, bg_h = img.size
offset = 0, 0
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def save(request):
body = {}
try:
body = json.loads(request.body)
except:
except Exception:
status = 400
message = 'Bad Request'

Expand Down
5 changes: 2 additions & 3 deletions app/dashboard/management/commands/activity_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
from django.core.management.base import BaseCommand

import boto
from app.utils import itermerge
from boto.s3.key import Key
from dashboard.models import Bounty, Tip
from marketing.mails import send_mail

DATE_FORMAT = '%Y/%m/%d'
DATE_FORMAT_HYPHENATED = '%Y-%m-%d'
REPORT_URL_EXPIRATION_TIME = 60 * 60 * 24 * 30 # seconds
REPORT_URL_EXPIRATION_TIME = 60 * 60 * 24 * 30 # seconds

GITHUB_REPO_PATTERN = re.compile('github.com/[\w-]+/([\w-]+)')

imap = map


def valid_date(v):
try:
return datetime.datetime.strptime(v, DATE_FORMAT)
Expand Down Expand Up @@ -118,7 +118,6 @@ def upload_to_s3(self, filename, contents):

return key.generate_url(expires_in=REPORT_URL_EXPIRATION_TIME)


def handle(self, *args, **options):
bounties = Bounty.objects.prefetch_related('fulfillments').filter(
network='mainnet',
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/management/commands/post_to_craigslist.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ def handle(self, *args, **options):
for bounty in bounties_to_post:
# print(bounty)
link = maybe_post_on_craigslist(bounty)
print("Posted {}".format(link))
print("Posted", link)
2 changes: 1 addition & 1 deletion app/dashboard/management/commands/sync_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def does_need_refresh(handle):
try:
org = Profile.objects.get(handle=handle)
org.last_sync_date > timezone.now() - timezone.timedelta(weeks=1)
except:
except Exception:
needs_refresh = True

return needs_refresh
Expand Down
11 changes: 5 additions & 6 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def get_relative_url(self, preceding_slash=True):
_issue_num = issue_number(self.github_url)
_repo_name = repo_name(self.github_url)
return f"{'/' if preceding_slash else ''}{'legacy/' if self.is_legacy else ''}issue/{_org_name}/{_repo_name}/{_issue_num}"
except:
except Exception:
return f"{'/' if preceding_slash else ''}{'legacy/' if self.is_legacy else ''}funding/details?url={self.github_url}"

def get_natural_value(self):
Expand Down Expand Up @@ -509,7 +509,7 @@ class Tip(SuperModel):
from_name = models.CharField(max_length=255, default='', blank=True)
from_email = models.CharField(max_length=255, default='', blank=True)
from_username = models.CharField(max_length=255, default='', blank=True)
username = models.CharField(max_length=255, default='') #to username
username = models.CharField(max_length=255, default='') # to username
network = models.CharField(max_length=255, default='')
txid = models.CharField(max_length=255, default='')
receive_txid = models.CharField(max_length=255, default='', blank=True)
Expand All @@ -523,7 +523,7 @@ def __str__(self):
f"{self.tokenName} to {self.username}, created: {naturalday(self.created_on)}, " \
f"expires: {naturalday(self.expires_date)}"

#TODO: DRY
# TODO: DRY
def get_natural_value(self):
token = addr_to_token(self.tokenAddress)
decimals = token['decimals']
Expand All @@ -533,7 +533,7 @@ def get_natural_value(self):
def value_true(self):
return self.get_natural_value()

#TODO: DRY
# TODO: DRY
@property
def value_in_eth(self):
if self.tokenName == 'ETH':
Expand Down Expand Up @@ -610,7 +610,7 @@ def __str__(self):
@receiver(post_save, sender=Interest, dispatch_uid="psave_interest")
@receiver(post_delete, sender=Interest, dispatch_uid="pdel_interest")
def psave_interest(sender, instance, **kwargs):
#when a new interest is saved, update the status on frontend
# when a new interest is saved, update the status on frontend
print("updating bounties")
for bounty in Bounty.objects.filter(interested=instance):
bounty.save()
Expand Down Expand Up @@ -764,7 +764,6 @@ def desc(self):
def stats(self):
bounties = self.bounties
loyalty_rate = 0
claimees = []
total_funded = sum([bounty.value_in_usdt if bounty.value_in_usdt else 0 for bounty in bounties if bounty.is_funder(self.handle)])
total_fulfilled = sum([bounty.value_in_usdt if bounty.value_in_usdt else 0 for bounty in bounties if bounty.is_hunter(self.handle)])
print(total_funded, total_fulfilled)
Expand Down
3 changes: 0 additions & 3 deletions app/dashboard/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
"""
import logging

from django.db.models.signals import m2m_changed
from django.dispatch import receiver

from .notifications import maybe_market_to_github

logger = logging.getLogger(__name__)
Expand Down
23 changes: 0 additions & 23 deletions app/dashboard/tests.py

This file was deleted.