Skip to content

Commit fa9c54b

Browse files
authored
Display row number in each task and add seed command
* Add a seed command * Add row number in templates * Correctly set docker-compose's env * No need for directory listing * Clean unused code * Use only moonsheep's production mode * Show for errors in html * Add support for row number in models and forms * Adapt tasks to moonsheep's production mode * Wait for a longer period of time * Seed all the time * Update development instructions * Remove debug leftovers
1 parent 9fd8dfa commit fa9c54b

34 files changed

+353
-251
lines changed

README.md

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Catalog politic - Declaratii de avere [![Datree](https://s3.amazonaws.com/catalog.static.datree.io/datree-badge-20px.svg)](https://datree.io/?src=badge) [![GitHub contributors](https://img.shields.io/github/contributors/code4romania/catpol-declaratii.svg)](https://github.com/code4romania/catpol-declaratii/graphs/contributors) [![GitHub last commit](https://img.shields.io/github/last-commit/code4romania/catpol-declaratii.svg)](https://github.com/code4romania/catpol-declaratii/commits/master) [![License: MPL 2.0](https://img.shields.io/badge/license-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)
1+
# Catalog politic - Declaratii de avere [![Datree](https://s3.amazonaws.com/catalog.static.datree.io/datree-badge-20px.svg)](https://datree.io/?src=badge) [![GitHub contributors](https://img.shields.io/github/contributors/code4romania/asset-declarations.svg)](https://github.com/code4romania/asset-declarations/graphs/contributors) [![GitHub last commit](https://img.shields.io/github/last-commit/code4romania/asset-declarations.svg)](https://github.com/code4romania/asset-declarations/commits/master) [![License: MPL 2.0](https://img.shields.io/badge/license-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)
22

33
<!-- Please don't remove this: Grab your social icons from https://github.com/carlsednaoui/gitsocial -->
44

@@ -23,7 +23,7 @@
2323
* MAKING PUBLIC INFORMATION TRULY PUBLIC
2424
* data from asset declarations, including a net worth estimation
2525

26-
**Important!** This project is currently out of sync with the latest version of [Moonsheep](https://github.com/themoonsheep/moonsheep), a library that it is dependent on. In order for development to continue, we must first fix [this critical issue](https://github.com/code4romania/catpol-declaratii/issues/191).
26+
**Important!** This project is currently out of sync with the latest version of [Moonsheep](https://github.com/themoonsheep/moonsheep), a library that it is dependent on. In order for development to continue, we must first fix [this critical issue](https://github.com/code4romania/asset-declarations/issues/191).
2727

2828
Currently, in Romania, public information on elected officials is spread on a multitude of media, in a multitude of formats and requires a
2929
priori knowledge of the sources where data resides, making it hard, if not impossible for a regular citizen to make sense of the data.
@@ -87,34 +87,21 @@ Political Catalogue - Asset Declaration is a web application.
8787
Installation process
8888
* Fork this repo
8989
* Clone your fork
90-
* Open the directory where you have cloned the repo (`cd catpol-declaratii`)
90+
* Open the directory where you have cloned the repo (`cd asset-declarations`)
9191
* Optionally, you can create a virtual environment named "venv": `python3 -m venv venv` and then activate it: `source venv/bin/activate`
9292
* `pip install -r requirements-dev.txt`
9393
* `export DJANGO_SETTINGS_MODULE=project_template.settings.dev`
9494
* `python manage.py migrate --run-syncdb`
95+
* `python manage.py seed`
9596
* `python manage.py runserver`
9697

97-
Using Dockerfile:
98-
* Install docker
98+
Using docker-compose:
99+
* Install docker and cdocker-compose
99100
* Fork this repo
100101
* Clone your fork
101-
* Open the directory where you have cloned the repo (`cd catpol-declaratii`)
102-
* Run the following command to create a Docker image for the project `docker build -t catpol`
103-
* Run the following command to run the Docker image `docker run -p 8000 catpol`
104-
* Show the container id running the `catpol` image `docker ps`
105-
* Inspect the container to get the host port `docker inspect <container_id>`, you should see something like:
106-
```json
107-
"Ports": {
108-
"8000/tcp": [
109-
{
110-
"HostIp": "0.0.0.0",
111-
"HostPort": "32769"
112-
}
113-
]
114-
},
115-
```
116-
* Connect to specified port on localhost and enjoy the solution
117-
102+
* Open the directory where you have cloned the repo (`cd asset-declarations`)
103+
* Run the following command to start the development server `docker-compose up`
104+
* You can interact with the container's environment using `docker-compose exec web bash`
118105

119106
## Contributing
120107

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3'
22
services:
33
web:
44
build: .
5-
command: ls -la /opt/catpol && dockerize --wait tcp://db:3306
5+
command: dockerize -wait tcp://db:5432 -timeout 90s
66
ports:
77
- "8000:8000"
88
volumes:
@@ -12,6 +12,8 @@ services:
1212
image: "postgres:12"
1313
ports:
1414
- "5432:5432"
15+
env_file:
16+
- .env
1517
volumes:
1618
- database-data:/var/lib/postgresql/data/
1719

docker-entrypoint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ PORT=${PORT:-"8000"}
55
echo "Migrating databse"
66
python3 manage.py migrate --run-syncdb
77

8+
echo "Seed"
9+
python3 manage.py seed
10+
811
echo "Start web server on $PORT"
912
python3 manage.py runserver "0.0.0.0:$PORT"

project_template/forms.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, *args, **kwargs):
7676
class Meta:
7777
model = models.OwnedLandTableEntry
7878
# Exclude the Model's table and coowner fields because they will be handled separately by the Task
79-
exclude = ["table", "coowner"]
79+
exclude = ["table", "row_number", "coowner"]
8080

8181

8282
class TranscribeOwnedBuildingsTable(forms.Form):
@@ -101,7 +101,7 @@ def __init__(self, *args, **kwargs):
101101
class Meta:
102102
model = models.OwnedBuildingsTableEntry
103103
# Exclude the Model's table and coowner fields because they will be handled separately by the Task
104-
exclude = ["table", "coowner"]
104+
exclude = ["table", "row_number", "coowner"]
105105
# TODO: The 'address' model field doesn't seem to be used by the old form. Is it an overlook?
106106
exclude += ["address"]
107107

@@ -129,6 +129,7 @@ class Meta:
129129
# Exclude the Model's table field because they will be handled separately by the Task
130130
exclude = [
131131
"table",
132+
"row_number",
132133
]
133134

134135

@@ -154,6 +155,7 @@ class Meta:
154155
# Exclude the Model's table field because they will be handled separately by the Task
155156
exclude = [
156157
"table",
158+
"row_number",
157159
]
158160

159161

@@ -182,7 +184,7 @@ def __init__(self, *args, **kwargs):
182184
class Meta:
183185
model = models.OwnedExtraValuableTableEntry
184186
# Exclude the Model's table and receiver_of_goods fields because they will be handled separately by the Task
185-
exclude = ["table", "receiver_of_goods"]
187+
exclude = ["table", "row_number", "receiver_of_goods"]
186188
# TODO: The 'address' model field doesn't seem to be used by the old form. Is it an overlook?
187189
exclude += ["address"]
188190

@@ -201,6 +203,7 @@ class Meta:
201203
model = models.OwnedBankAccountsTableEntry
202204
exclude = [
203205
"table",
206+
"row_number",
204207
]
205208

206209
def __init__(self, *args, **kwargs):
@@ -226,7 +229,7 @@ class TranscribeOwnedInvestmentsOver5KRowEntry(PartialModelForm):
226229
class Meta:
227230
model = models.OwnedInvestmentsOver5KTableEntry
228231
# Exclude the Model's table and loan_beneficiary fields because they will be handled separately by the Task
229-
exclude = ["table", "loan_beneficiary"]
232+
exclude = ["table", "row_number", "loan_beneficiary"]
230233

231234

232235
class TranscribeOwnedDebtsTable(forms.Form):
@@ -244,7 +247,7 @@ class TranscribeOwnedDebtsRowEntry(PartialModelForm):
244247
class Meta:
245248
model = models.OwnedDebtsTableEntry
246249
# Exclude the Model's table and person fields because they will be handled separately by the Task
247-
exclude = ["table", "person"]
250+
exclude = ["table", "row_number", "person"]
248251

249252
def __init__(self, *args, **kwargs):
250253
super().__init__(*args, **kwargs)
@@ -271,7 +274,7 @@ class TranscribeOwnedGoodsOrServicesRowEntry(PartialModelForm):
271274
class Meta:
272275
model = models.OwnedGoodsOrServicesTableEntry
273276
# Exclude the Model's table and person fields because they will be handled separately by the Task
274-
exclude = ["table", "person"]
277+
exclude = ["table", "row_number", "person"]
275278

276279

277280
class TranscribeOwnedIncomeFromSalariesTable(forms.Form):
@@ -288,7 +291,7 @@ class TranscribeOwnedIncomeFromSalariesRowEntry(PartialModelForm):
288291
class Meta:
289292
model = models.OwnedIncomeFromSalariesTableEntry
290293
# Exclude the Model's table and person fields because they will be handled separately by the Task
291-
exclude = ["table", "person"]
294+
exclude = ["table", "row_number", "person"]
292295

293296

294297
class TranscribeIndependentActivitiesTable(forms.Form):
@@ -307,7 +310,7 @@ class TranscribeIndependentActivitiesRowEntry(PartialModelForm):
307310
class Meta:
308311
model = models.OwnedIncomeFromIndependentActivitiesTableEntry
309312
# Exclude the Model's table and person fields because they will be handled separately by the Task
310-
exclude = ["table", "person"]
313+
exclude = ["table", "row_number", "person"]
311314

312315

313316
class TranscribeOwnedIncomeFromDeferredUseOfGoodsTable(forms.Form):
@@ -324,7 +327,7 @@ class TranscribeOwnedIncomeFromDeferredUseOfGoodsRowEntry(PartialModelForm):
324327
class Meta:
325328
model = models.OwnedIncomeFromDeferredUseOfGoodsTableEntry
326329
# Exclude the Model's table and person fields because they will be handled separately by the Task
327-
exclude = ["table", "person"]
330+
exclude = ["table", "row_number", "person"]
328331

329332

330333
class TranscribeOwnedIncomeFromInvestmentsTable(forms.Form):
@@ -343,7 +346,7 @@ class TranscribeOwnedIncomeFromInvestmentsRowEntry(PartialModelForm):
343346
class Meta:
344347
model = models.OwnedIncomeFromInvestmentsTableEntry
345348
# Exclude the Model's table and person fields because they will be handled separately by the Task
346-
exclude = ["table", "person"]
349+
exclude = ["table", "row_number", "person"]
347350

348351

349352
class TranscribeOwnedIncomeFromPensionsTable(forms.Form):
@@ -360,7 +363,7 @@ class TranscribeOwnedIncomeFromPensionsRowEntry(PartialModelForm):
360363
class Meta:
361364
model = models.OwnedIncomeFromPensionsTableEntry
362365
# Exclude the Model's table and person fields because they will be handled separately by the Task
363-
exclude = ["table", "person"]
366+
exclude = ["table", "row_number", "person"]
364367

365368

366369
class TranscribeOwnedIncomeFromAgriculturalActivitiesTable(forms.Form):
@@ -377,7 +380,7 @@ class TranscribeOwnedIncomeFromAgriculturalActivitiesRowEntry(PartialModelForm):
377380
class Meta:
378381
model = models.OwnedIncomeFromAgriculturalActivitiesTableEntry
379382
# Exclude the Model's table and person fields because they will be handled separately by the Task
380-
exclude = ["table", "person"]
383+
exclude = ["table", "row_number", "person"]
381384

382385

383386
class TranscribeOwnedIncomeFromGamblingTable(forms.Form):
@@ -394,7 +397,7 @@ class TranscribeOwnedIncomeFromGamblingRowEntry(PartialModelForm):
394397
class Meta:
395398
model = models.OwnedIncomeFromGamblingTableEntry
396399
# Exclude the Model's table and person fields because they will be handled separately by the Task
397-
exclude = ["table", "person"]
400+
exclude = ["table", "row_number", "person"]
398401

399402

400403
class TranscribeOwnedIncomeFromOtherSourcesTable(forms.Form):
@@ -411,4 +414,4 @@ class TranscribeOwnedIncomeFromOtherSourcesRowEntry(PartialModelForm):
411414
class Meta:
412415
model = models.OwnedIncomeFromOtherSourcesTableEntry
413416
# Exclude the Model's table and person fields because they will be handled separately by the Task
414-
exclude = ["table", "person"]
417+
exclude = ["table", "row_number", "person"]

project_template/management/__init__.py

Whitespace-only changes.

project_template/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from django.core.management.base import BaseCommand
2+
3+
from moonsheep.models import Task
4+
from moonsheep.settings import MOONSHEEP
5+
6+
from project_template.models import Declaration
7+
8+
9+
class Command(BaseCommand):
10+
def handle(self, *args, **kwargs):
11+
for url in [
12+
"http://cdep.ro/declaratii/deputati/2016/avere/002a.pdf",
13+
"http://cdep.ro/declaratii/deputati/2016/avere/003c.pdf",
14+
"http://cdep.ro/declaratii/deputati/2016/avere/004e.pdf",
15+
"http://cdep.ro/declaratii/deputati/2016/avere/005c.pdf",
16+
"http://cdep.ro/declaratii/deputati/2016/avere/006d.pdf",
17+
]:
18+
declaration, _ = Declaration.objects.get_or_create(url=url)
19+
20+
for task_type in MOONSHEEP["DOCUMENT_INITIAL_TASKS"]:
21+
Task.objects.get_or_create(type=task_type, doc_id=declaration.id, params={"url": url,})

0 commit comments

Comments
 (0)