Skip to content

Commit

Permalink
data migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ppeczek committed Apr 20, 2018
1 parent 5d9014b commit 72429fa
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 24 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ node_modules/
.env
build/
staticfiles/
shared/

requirements-local.txt
requirements-local.txt
dbdata.json
3 changes: 1 addition & 2 deletions project_template/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.urls import path
from .models import *

# Register your models here.

# TODO move this to project_template
class MyAdminSite(admin.AdminSite):
Expand Down Expand Up @@ -53,7 +52,7 @@ def import_declarations_from_parldata(self, request):

@admin.register(Politician, site=site)
class PoliticianAdmin(admin.ModelAdmin):
pass
list_display = ['name', 'party', 'parliamentary_id', 'created_at', 'updated_at']


site.register(Relative)
Expand Down
28 changes: 16 additions & 12 deletions project_template/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,28 @@ def __str__(self):
return self.name


class Politician(models.Model):
name = models.CharField(_('Full name'), max_length=128)
class Politician(models.Model): # crowdataapp_politician.json
name = models.CharField(_('Full name'), max_length=128) # crowdataapp_politician.json [name]
"""
Used in most of the urls of parliamentary website
"""
parliamentary_id = models.CharField(_('Parliamentary website ID'), max_length=24)
image_url = models.URLField(_('Image URL'), max_length=256)
parliamentary_id = models.CharField(_('Parliamentary website ID'), max_length=24) # crowdataapp_politician.json [parliamentary_id]
image_url = models.URLField(_('Image URL'), max_length=256) # crowdataapp_politician.json [image_url]
party = models.ForeignKey(
"Party", related_name='members', verbose_name='Current MPs party', on_delete=models.PROTECT,
null=True, blank=True
)
parldata_id = models.CharField(_('External ParlData API ID'), max_length=64)
) # crowdataapp_politician.json [party_id]
parldata_id = models.CharField(_('External ParlData API ID'), max_length=64) # crowdataapp_politician.json [parldata_id]

# Audit timestamps
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
created_at = models.DateTimeField(auto_now_add=True) # crowdataapp_politician.json [created_at]
updated_at = models.DateTimeField(auto_now=True) # crowdataapp_politician.json [updated_at]

objects = MyManager()

def __str__(self):
return self.name

def create_asset_declaration_url(self, year):
template = 'http://www.parlament.hu/internet/cplsql/ogy_vagyonpub.vagyon_kiir_egys' \
+ '?P_FNEV=/{year}/{id}_j0{date}k.pdf&p_cont=application/pdf'
Expand All @@ -57,7 +60,7 @@ class Meta:
verbose_name_plural = _('Politicians')


class Party(models.Model):
class Party(models.Model): # crowdataapp_party.json
name = models.CharField(_('Full name'), max_length=128)
short_name = models.CharField(_('Short name'), max_length=128)
parldata_id = models.CharField(_('External ParlData API ID'), max_length=64)
Expand All @@ -76,12 +79,13 @@ class Meta:
verbose_name_plural = _('Political Parties')


class Declaration(models.Model):
url = models.URLField(max_length=500)
class Declaration(models.Model): # crowdataapp_document.json
url = models.URLField(max_length=500) # crowdataapp_document.json [url]

# crowdataapp_document.json [name] [politician_id]
politician = models.ForeignKey("Politician", related_name='declarations', on_delete=models.PROTECT)

for_year = models.IntegerField()
for_year = models.IntegerField() # crowdataapp_document.json [name]

# Personal Data
# spouse and children foreign link exists in Relative class
Expand Down
8 changes: 8 additions & 0 deletions project_template/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,11 @@
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'

# moonsheep settings
# MOONSHEEP_TASK_SOURCE = 'pybossa' # 'random' / 'pybossa' -> default 'random'

# if pybossa is selected
PYBOSSA_URL = 'http://localhost:5000/'
PYBOSSA_PROJECT_ID = 1
PYBOSSA_API_KEY = os.environ.get('PYBOSSA_API_KEY')
2 changes: 2 additions & 0 deletions project_template/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

AUTH_PASSWORD_VALIDATORS = []

ALLOWED_HOSTS = '*'

# Add debug toolbar
if DEBUG:
INSTALLED_APPS += ['debug_toolbar', 'django_extensions']
Expand Down
2 changes: 1 addition & 1 deletion project_template/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

assert 'SECRET_KEY' in os.environ, 'Set SECRET_KEY variable in your environment file!'
SECRET_KEY = os.environ['SECRET_KEY']
SECRET_KEY = os.environ.get('SECRET_KEY')

# To be double sure
DEBUG = TEMPLATE_DEBUG = False
Expand Down
26 changes: 22 additions & 4 deletions project_template/tasks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import datetime

from moonsheep.models import ModelMapper
from moonsheep.register import base_task, initial_task
from moonsheep.tasks import AbstractTask
from moonsheep.verifiers import *

from .forms import *
from .models import *


Expand All @@ -23,11 +20,14 @@ def create_mocked_task(self, base):
return base


@base_task.register
@initial_task.register
class S1PersonalData(AbstractTask):
"""
Személyes információk
"""
template_name = 'tasks/personal_data.html'
verbose_name = 'personal data'

create_mocked_task = create_mocked_task

Expand All @@ -42,11 +42,14 @@ def save_verified_data(self, vd: dict):
Relative.objects.get_or_create(child_of=d, name=child.strip())


@initial_task.register
@base_task.register
class S2Properties(AbstractTask):
"""
Ingatlanok
"""
template_name = 'tasks/properties.html'
verbose_name = 'properties'

create_mocked_task = create_mocked_task

Expand Down Expand Up @@ -109,11 +112,14 @@ def save_verified_data(self, vd: dict):
# TODO feedback 'something_wrong': ['']}


@initial_task.register
@base_task.register
class S3Movables(AbstractTask):
"""
Nagy értékű ingóságok
"""
template_name = 'tasks/movables.html'
verbose_name = 'movables'

create_mocked_task = create_mocked_task

Expand Down Expand Up @@ -171,6 +177,8 @@ def save_verified_data(self, vd: dict):
m.create(declaration=d).save()


@initial_task.register
@base_task.register
class S4FinancialAndOther(AbstractTask):
"""
tartozások ?
Expand All @@ -180,6 +188,7 @@ class S4FinancialAndOther(AbstractTask):
egyéb közlendők (other)
"""
template_name = 'tasks/financial.html'
verbose_name = 'financial and other'

create_mocked_task = create_mocked_task

Expand Down Expand Up @@ -242,11 +251,14 @@ def save_verified_data(self, vd: dict):
d.financial_other = vd['financial_other'].strip()


@initial_task.register
@base_task.register
class S5Income(AbstractTask):
"""
Jövedelemnyilatkozat
"""
template_name = 'tasks/income.html'
verbose_name = 'income'

create_mocked_task = create_mocked_task

Expand All @@ -270,11 +282,14 @@ def save_verified_data(self, vd: dict):
m.create(declaration=d).save()


@initial_task.register
@base_task.register
class S6EconomicInterest(AbstractTask):
"""
érdekeltségi
"""
template_name = 'tasks/economic_interest.html'
verbose_name = 'economic interest'

create_mocked_task = create_mocked_task

Expand Down Expand Up @@ -308,12 +323,15 @@ def save_verified_data(self, vd: dict):
m.create(declaration=d).save()


@initial_task.register
@base_task.register
class S7Benefits(AbstractTask):
"""
juttatásról, ajándékról, támogatásról
benefits, gifts, or subsidies
"""
template_name = 'tasks/benefits.html'
verbose_name = 'benefits'

create_mocked_task = create_mocked_task

Expand Down
2 changes: 1 addition & 1 deletion project_template/templates/task.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.html" %}
{% extends "base.html" %}
{% load static %}

{% block extra_scripts %}
Expand Down
Loading

0 comments on commit 72429fa

Please sign in to comment.