Skip to content

Commit

Permalink
Blacken
Browse files Browse the repository at this point in the history
  • Loading branch information
symroe committed Apr 29, 2020
1 parent 43398d2 commit 90d5eae
Show file tree
Hide file tree
Showing 48 changed files with 485 additions and 434 deletions.
2 changes: 1 addition & 1 deletion democracy_club/apps/backlog/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class BacklogConfig(AppConfig):
name = 'backlog'
name = "backlog"
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def handle(self, *args, **options):
url = url_fmt.format(self.base_url, self.list_id, self.key, self.token)
list_data = requests.get(url).json()

self.initial_ids = set(Card.objects.values_list('pk', flat=True))
self.initial_ids = set(Card.objects.values_list("pk", flat=True))
self.seen_ids = set()

self.setup_board_info()
Expand All @@ -29,52 +29,52 @@ def handle(self, *args, **options):
self.clean_up()

def setup_board_info(self):
req = requests.get("{}/boards/{}/customFields?key={}&token={}".format(
self.base_url,
settings.BACKLOG_TRELLO_BOARD_ID,
self.key,
self.token,
))
req = requests.get(
"{}/boards/{}/customFields?key={}&token={}".format(
self.base_url,
settings.BACKLOG_TRELLO_BOARD_ID,
self.key,
self.token,
)
)
self.customfield_map = {}
for field in req.json():
self.customfield_map[field['id']] = field
self.customfield_map[field["id"]] = field

def import_card(self, card_dict):
labels = []
for label in card_dict['labels']:
labels.append(CardLabel.objects.update_or_create(
trello_id=label['id'],
defaults={
'name': label['name'],
'colour': label['color'],
}
)[0])
for label in card_dict["labels"]:
labels.append(
CardLabel.objects.update_or_create(
trello_id=label["id"],
defaults={"name": label["name"], "colour": label["color"],},
)[0]
)

card = Card.objects.update_or_create(
trello_id=card_dict['id'],
trello_id=card_dict["id"],
defaults={
'title': card_dict['name'],
'text': card_dict['desc'],
'weight': card_dict['pos'],
'url': card_dict['url'],
'comment_count': card_dict['badges']['comments']

}
"title": card_dict["name"],
"text": card_dict["desc"],
"weight": card_dict["pos"],
"url": card_dict["url"],
"comment_count": card_dict["badges"]["comments"],
},
)[0]
self.seen_ids.add(card.pk)
card.labels.add(*labels)

for custom_field_value in card_dict['customFieldItems']:
for custom_field_value in card_dict["customFieldItems"]:
for field_id, field in self.customfield_map.items():
if field['id'] == custom_field_value['idCustomField']:
if field['id'] == "5a986717d6afbd6de1d24563":
if field["id"] == custom_field_value["idCustomField"]:
if field["id"] == "5a986717d6afbd6de1d24563":
# CTA_URL
card.cta_url = custom_field_value['value']['text']
if field['id'] == "5a986717d6afbd6de1d2455c":
card.cta_url = custom_field_value["value"]["text"]
if field["id"] == "5a986717d6afbd6de1d2455c":
# Time Required
for option in field['options']:
if option["id"] == custom_field_value['idValue']:
card.time_required = option['value']['text']
for option in field["options"]:
if option["id"] == custom_field_value["idValue"]:
card.time_required = option["value"]["text"]

card.save()

Expand Down
48 changes: 33 additions & 15 deletions democracy_club/apps/backlog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,49 @@ class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='Card',
name="Card",
fields=[
('trello_id', models.CharField(blank=True, max_length=100, primary_key=True, serialize=False)),
('title', models.CharField(blank=True, max_length=800)),
('text', models.TextField(blank=True)),
('weight', models.FloatField()),
('url', models.URLField(blank=True)),
(
"trello_id",
models.CharField(
blank=True,
max_length=100,
primary_key=True,
serialize=False,
),
),
("title", models.CharField(blank=True, max_length=800)),
("text", models.TextField(blank=True)),
("weight", models.FloatField()),
("url", models.URLField(blank=True)),
],
),
migrations.CreateModel(
name='CardLabel',
name="CardLabel",
fields=[
('trello_id', models.CharField(blank=True, max_length=100, primary_key=True, serialize=False)),
('name', models.CharField(blank=True, max_length=100)),
('color', models.CharField(blank=True, max_length=100)),
(
"trello_id",
models.CharField(
blank=True,
max_length=100,
primary_key=True,
serialize=False,
),
),
("name", models.CharField(blank=True, max_length=100)),
("color", models.CharField(blank=True, max_length=100)),
],
),
migrations.AddField(
model_name='card',
name='labels',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backlog.CardLabel'),
model_name="card",
name="labels",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="backlog.CardLabel",
),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
class Migration(migrations.Migration):

dependencies = [
('backlog', '0001_initial'),
("backlog", "0001_initial"),
]

operations = [
migrations.RemoveField(
model_name='card',
name='labels',
),
migrations.RemoveField(model_name="card", name="labels",),
migrations.AddField(
model_name='card',
name='labels',
field=models.ManyToManyField(to='backlog.CardLabel'),
model_name="card",
name="labels",
field=models.ManyToManyField(to="backlog.CardLabel"),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
class Migration(migrations.Migration):

dependencies = [
('backlog', '0002_auto_20170306_2043'),
("backlog", "0002_auto_20170306_2043"),
]

operations = [
migrations.RenameField(
model_name='cardlabel',
old_name='color',
new_name='colour',
model_name="cardlabel", old_name="color", new_name="colour",
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
class Migration(migrations.Migration):

dependencies = [
('backlog', '0003_auto_20170306_2045'),
("backlog", "0003_auto_20170306_2045"),
]

operations = [
migrations.AlterModelOptions(
name='card',
options={'ordering': ('weight',)},
name="card", options={"ordering": ("weight",)},
),
migrations.AddField(
model_name='card',
name='published',
model_name="card",
name="published",
field=models.BooleanField(default=True),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
class Migration(migrations.Migration):

dependencies = [
('backlog', '0004_auto_20170307_0931'),
("backlog", "0004_auto_20170307_0931"),
]

operations = [
migrations.AddField(
model_name='card',
name='comment_count',
model_name="card",
name="comment_count",
field=models.IntegerField(blank=True, null=True),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
class Migration(migrations.Migration):

dependencies = [
('backlog', '0005_card_comment_count'),
("backlog", "0005_card_comment_count"),
]

operations = [
migrations.AddField(
model_name='card',
name='cta_url',
model_name="card",
name="cta_url",
field=models.URLField(blank=True, max_length=800),
),
migrations.AddField(
model_name='card',
name='time_required',
model_name="card",
name="time_required",
field=models.CharField(blank=True, max_length=100),
),
]
7 changes: 4 additions & 3 deletions democracy_club/apps/backlog/models.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from django.db import models


class Card(models.Model):
trello_id = models.CharField(blank=True, max_length=100, primary_key=True)
title = models.CharField(blank=True, max_length=800)
text = models.TextField(blank=True)
weight = models.FloatField()
url = models.URLField(blank=True)
labels = models.ManyToManyField('backlog.CardLabel')
labels = models.ManyToManyField("backlog.CardLabel")
published = models.BooleanField(default=True)
comment_count = models.IntegerField(blank=True, null=True)
cta_url = models.URLField(blank=True, max_length=800)
time_required = models.CharField(blank=True, max_length=100)

class Meta:
ordering = ('weight', )
ordering = ("weight",)

def __str__(self):
return self.title
Expand All @@ -23,6 +24,7 @@ def get_cta_url(self):
return self.cta_url
return self.url


class CardLabel(models.Model):
trello_id = models.CharField(blank=True, max_length=100, primary_key=True)
name = models.CharField(blank=True, max_length=100)
Expand All @@ -31,7 +33,6 @@ class CardLabel(models.Model):
def __str__(self):
return self.name


# {
# "id": "58bd63361db95c69861b68da",
# "checkItemStates": null,
Expand Down
7 changes: 2 additions & 5 deletions democracy_club/apps/backlog/tests/test_backlog_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@


class TestBacklogView(TestCase):

def setUp(self):
self.card = Card(
time_required="10 minutes",
weight=1,
title="A test task"
time_required="10 minutes", weight=1, title="A test task"
)
self.card.save()

def test_info_on_backlog_cards(self):
resp = self.client.get('/quests/')
resp = self.client.get("/quests/")
assert resp.status_code == 200
self.assertContains(resp, self.card.time_required)
self.assertContains(resp, self.card.title)
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

class TestBacklogImporter(TestCase):
@vcr.use_cassette(
'fixtures/vcr_cassettes/test_backlog_import_cards.yaml',
filter_query_parameters=['key', 'token'])
"fixtures/vcr_cassettes/test_backlog_import_cards.yaml",
filter_query_parameters=["key", "token"],
)
def test_backlog_import_cards(self):
assert Card.objects.count() == 0
call_command('backlog_import_from_trello')
call_command("backlog_import_from_trello")
assert Card.objects.count() == 4
7 changes: 1 addition & 6 deletions democracy_club/apps/backlog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
from .views import BacklogView

urlpatterns = [
url(
r'^$',
BacklogView.as_view(),
name='backlog_view'
),
url(r"^$", BacklogView.as_view(), name="backlog_view"),
# url(
# r'^(?P<pk>[^/]+)/(?P<ignored_slug>.*)$',
# PartyView.as_view(),
# name='party_view'),
]

13 changes: 7 additions & 6 deletions democracy_club/apps/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
from django.apps import apps
from django.core.checks import Error, register


@register()
def check_django_storage_version(app_configs, **kwargs):
errors = []
if (app_configs is None or apps.get_app_config('core') in app_configs):
if storages.__version__ != '1.6.5':
if app_configs is None or apps.get_app_config("core") in app_configs:
if storages.__version__ != "1.6.5":
errors.append(
Error(
'django-storages must be at version 1.6.5',
hint='See https://github.com/DemocracyClub/Website/pull/117',
obj='core',
id='core.E001'
"django-storages must be at version 1.6.5",
hint="See https://github.com/DemocracyClub/Website/pull/117",
obj="core",
id="core.E001",
)
)
return errors
3 changes: 2 additions & 1 deletion democracy_club/apps/core/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.apps import AppConfig


class CoreConfig(AppConfig):
name = 'core'
name = "core"

def ready(self):
import core.signals # noqa
Loading

0 comments on commit 90d5eae

Please sign in to comment.