Skip to content
Commits on Source (4)
[bumpversion]
current_version = 0.5.2
current_version = 0.6.0
commit = True
[bumpversion:file:web/opdm_service/__init__.py]
......
......@@ -5,10 +5,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Fixed
- problem in `REG` context for `posts_and_persons` import solved
### Changed
- `offset` parameter added to `import_posts_and_persons_from_op`
management task, useful in `REG` and `COM` contexts.
## [0.5.2]
### Fixed
- get_or_create_criterion while creating global organizations corrected
- `get_or_create` criterion while creating global organizations corrected
## [0.5.1]
### Fixed
......
"The Openpolis Data Manager service package (the backend)"
__version__ = '0.5.2'
__version__ = '0.6.0'
......@@ -120,6 +120,7 @@ class OpAPIImporter(object):
def fetch_locations_info(
self, location_type,
locations_limit=0,
locations_offset=0,
order_by='-inhabitants'
):
"""Fetch information on locations from openpolis api.
......@@ -178,7 +179,7 @@ class OpAPIImporter(object):
'type': extended_location_types[location_type][0],
'inhabitants': x['inhabitants'],
'prep': prep(
extended_location_types[location_type][0],
x['name'],
location_type
)
},
......@@ -193,7 +194,9 @@ class OpAPIImporter(object):
)
if locations_limit:
info = info[:locations_limit]
info = info[locations_offset:locations_offset + locations_limit]
else:
info = info[locations_offset]
return info
......@@ -233,13 +236,24 @@ class OpAPIImporter(object):
identifiers__identifier=loc_id
)
com_descr = "Comune di {0}".format(loc_name)
if loc_name == 'Roma':
com_descr = 'Roma Capitale'
if loc_type == 'Regione':
org_name = "Regione {0}".format(loc_name)
elif loc_type == 'Provincia':
org_name = "Amministrazione provinciale di {0}".format(loc_name)
elif loc_type == 'Città metropolitana':
org_name = "Citta' metropolitana di {0}".format(loc_name)
else: # Comune
org_name = "Comune di {0}".format(loc_name)
if loc_name == 'Roma':
org_name = 'Roma Capitale'
parent_org, cr = Organization.objects.get_or_create(
name__iexact=com_descr,
name__iexact=org_name,
classifications__classification__scheme='FORMA_GIURIDICA_ISTAT_BDAP',
classifications__classification__descr=loc_type
classifications__classification__descr=loc_type,
defaults={
'name': loc_name
}
)
if parent_org.area is None:
......
......@@ -12,7 +12,7 @@ class LabelsBuilder(object):
# commissione EU
@staticmethod
def build_labels_comm_eu(org, op_post):
def build_labels_comm_eu(org, op_post, **kwargs):
labels = {
'post': {
'label': '{0} della {1}'.format(
......@@ -27,7 +27,7 @@ class LabelsBuilder(object):
# parlamento EU
@staticmethod
def build_labels_parl_eu(org, op_post):
def build_labels_parl_eu(org, op_post, **kwargs):
labels = {'post': {}, 'membership': {}}
if op_post.charge_type_descr == 'Deputato':
labels['post'] = {
......@@ -45,7 +45,7 @@ class LabelsBuilder(object):
# governo
@staticmethod
def build_labels_gov(org, op_post):
def build_labels_gov(org, op_post, **kwargs):
labels = {
'post': {
'label': op_post.charge_type_descr,
......@@ -65,7 +65,7 @@ class LabelsBuilder(object):
# senato della repubblica
@staticmethod
def build_labels_sen(org, op_post):
def build_labels_sen(org, op_post, **kwargs):
labels = {
'post': {
'label': '{0} del {1}'.format(
......@@ -82,7 +82,7 @@ class LabelsBuilder(object):
# camera dei deputati
@staticmethod
def build_labels_cam(org, op_post):
def build_labels_cam(org, op_post, **kwargs):
labels = {
'post': {
'label': '{0} della {1}'.format(
......@@ -99,7 +99,7 @@ class LabelsBuilder(object):
# giunta amm. locale
@staticmethod
def build_labels_giunta(org, op_post, inst_name=None):
def build_labels_giunta(org, op_post, **kwargs):
"""
post.label: Presidente di Regione
membership.label: Presidente della Regione Lombardia
......@@ -125,6 +125,7 @@ class LabelsBuilder(object):
:param inst_name:
:return:
"""
inst_name = kwargs.pop('inst_name', None)
if 'region' in inst_name:
if 'assessore' in op_post.charge_type_descr.lower():
......@@ -188,7 +189,9 @@ class LabelsBuilder(object):
# consiglio amm. locale
@staticmethod
def build_labels_consiglio(org, op_post, inst_name=None):
def build_labels_consiglio(org, op_post, **kwargs):
inst_name = kwargs.pop('inst_name', None)
if 'region' in inst_name:
if 'consigliere' in op_post.charge_type_descr.lower():
post_location_specification = "regionale"
......@@ -243,6 +246,15 @@ class Command(BaseCommand):
help='Maximum number of locations to import (local contexts only)',
)
parser.add_argument(
'--locations-offset',
dest='locations_offset',
type=int,
default=0,
help='Offset of strting location to start import from '
'(local contexts only)',
)
def handle(self, *args, **options):
verbosity = options['verbosity']
if verbosity == 0:
......@@ -255,6 +267,7 @@ class Command(BaseCommand):
self.logger.setLevel(logging.DEBUG)
self.locations_limit = options['locations_limit']
self.locations_offset = options['locations_offset']
for ctx in options['contexts']:
if ctx not in ['eu', 'it', 'reg', 'com']:
......@@ -300,7 +313,9 @@ class Command(BaseCommand):
self.logger.info('Start REG')
locations_info = self.op_importer.fetch_locations_info(
'R', locations_limit=self.locations_limit
'R',
locations_limit=self.locations_limit,
locations_offset=self.locations_offset
)
for loc_info in locations_info:
self.op_importer.import_memberships(
......@@ -321,7 +336,9 @@ class Command(BaseCommand):
self.logger.info('Start COM')
locations_info = self.op_importer.fetch_locations_info(
'C', locations_limit=self.locations_limit
'C',
locations_limit=self.locations_limit,
locations_offset=self.locations_offset
)
for loc_info in locations_info:
self.op_importer.import_memberships(
......