Skip to content

Commit

Permalink
Added auto generated column
Browse files Browse the repository at this point in the history
  • Loading branch information
wondie committed Feb 10, 2017
1 parent 0653acd commit 0c7d19d
Show file tree
Hide file tree
Showing 23 changed files with 1,526 additions and 215 deletions.
33 changes: 32 additions & 1 deletion data/configuration/columns.py
Expand Up @@ -586,6 +586,7 @@ class GeometryColumn(BaseColumn):
POINT, LINE, POLYGON, MULTIPOINT, MULTILINE, MULTIPOLYGON = range(0, 6)

def __init__(self, *args, **kwargs):

if len(args) < 3:
raise Exception('Constructor requires name, entity and geometry '
'type arguments.')
Expand Down Expand Up @@ -672,7 +673,7 @@ def __init__(self, *args, **kwargs):
self.entity_relation.child_column = self.name
self.entity_relation.child = self.entity

#If the entity relation is valid then add it right away to the profile
# If the entity relation is valid then add it right away to the profile
if self.entity_relation.valid()[0]:
self.profile.add_entity_relation(self.entity_relation)

Expand Down Expand Up @@ -787,6 +788,36 @@ def display_name(cls):

AdministrativeSpatialUnitColumn.register()


class AutoGeneratedColumn(VarCharColumn):
"""
Enables the attachment of a unique identifier code to the entity.
.. versionadded:: 1.5
"""
TYPE_INFO = 'AUTO_GENERATED'
SQL_MAX = 4000
SQL_MIN = 0
sql_updater = varchar_updater

def __init__(self, *args, **kwargs):

self.prefix_source = kwargs.pop('prefix_source', '')
self.leading_zero = kwargs.pop('leading_zero', '')
self.separator = kwargs.pop('separator', '')

VarCharColumn.__init__(self, *args, **kwargs)

def can_create_check_constraints(self):
# No need to create constraints since the extents are set while
# creating the column.
return False

@classmethod
def display_name(cls):
return tr('Auto Generated Code')

AutoGeneratedColumn.register()

class VirtualColumn(BaseColumn):
"""
Virtual columns are not created in the database, only the references are
Expand Down
2 changes: 1 addition & 1 deletion data/database.py
Expand Up @@ -352,7 +352,7 @@ def __init__(self,name="",code="",parent=None):
self.Code = code
self.Parent = parent

def hierarchyCode(self,separator = "/"):
def hierarchyCode(self, separator = "/"):
'''
Returns a string constituted of codes aggregated from the class instance, prior to which
there are codes of the parent administrative units in the hierarchy.
Expand Down
Binary file added images/icons/clear.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icons/code.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 2 additions & 11 deletions plugin.py
Expand Up @@ -110,11 +110,6 @@

from stdm.ui.social_tenure.str_editor import STREditor



from stdm.settings.database_backup import *
from stdm.settings.database_updaters import DatabaseUpdater

LOGGER = logging.getLogger('stdm')


Expand Down Expand Up @@ -617,13 +612,9 @@ def load_configuration_from_file(self, parent, manual=False):
:rtype: bool
"""
self.progress = STDMProgressDialog(parent)
self.progress.overall_progress(
'Upgrading STDM Configuration...',
)
self.progress.overall_progress('Upgrading STDM Configuration...')

home = QDesktopServices.storageLocation(
QDesktopServices.HomeLocation
)
home = QDesktopServices.storageLocation(QDesktopServices.HomeLocation)

config_path = '{}/.stdm/configuration.stc'.format(home)

Expand Down
2 changes: 2 additions & 0 deletions resources.qrc
Expand Up @@ -99,5 +99,7 @@
<file>images/icons/period.png</file>
<file>images/icons/down_arrow.png</file>
<file>images/icons/period_blue.png</file>
<file>images/icons/code.jpg</file>
<file>images/icons/clear.png</file>
</qresource>
</RCC>
327 changes: 230 additions & 97 deletions resources_rc.py

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions settings/config_serializer.py
Expand Up @@ -1974,6 +1974,66 @@ def _obj_args(cls, args, kwargs, element, assoc_elements,
AdminSpatialUnitColumnSerializer.register()


class AutoGeneratedColumnSerializer(ColumnSerializerCollection):
"""
(De)serializes administrative spatial unit column type.
"""
COLUMN_TYPE_INFO = 'AUTO_GENERATED'
CODE = 'Code'
PREFIX_SOURCE = 'prefix_source'
LEADING_ZERO = 'leading_zero'
SEPARATOR = 'separator'

@classmethod
def _convert_bounds_type(cls, value):
return int(value)


@classmethod
def _obj_args(cls, args, kwargs, element, assoc_elements,
entity_relation_elements):
#Include the prefix_code in the arguments.
code_ele = element.firstChildElement(
AutoGeneratedColumnSerializer.CODE
)
if not code_ele.isNull():

prefix_source = code_ele.attribute(
AutoGeneratedColumnSerializer.PREFIX_SOURCE,
''
)
leading_zero = code_ele.attribute(
AutoGeneratedColumnSerializer.LEADING_ZERO,
''
)
separator = code_ele.attribute(
AutoGeneratedColumnSerializer.SEPARATOR,
''
)

# Append prefix_source
kwargs['prefix_source'] = prefix_source
kwargs['leading_zero'] = leading_zero
kwargs['separator'] = separator

return args, kwargs

@classmethod
def _write_xml(cls, column, column_element, document):
# Append code prefix source
dt_element = document.createElement(
AutoGeneratedColumnSerializer.CODE
)

dt_element.setAttribute('prefix_source', column.prefix_source)
dt_element.setAttribute('leading_zero', column.leading_zero)
dt_element.setAttribute('separator', column.separator)

column_element.appendChild(dt_element)

AutoGeneratedColumnSerializer.register()


class MultipleSelectColumnSerializer(ColumnSerializerCollection):
"""
(De)serializes multiple select column type information.
Expand Down
19 changes: 0 additions & 19 deletions ui/admin_unit_selector.py
Expand Up @@ -101,22 +101,3 @@ def onRejectDialog(self):
'''
self.reject()




















0 comments on commit 0c7d19d

Please sign in to comment.