Skip to content

Commit

Permalink
Better class to edit the layer
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 23, 2018
1 parent 8a5721a commit c4c183f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 1 addition & 3 deletions geoportal/c2cgeoportal_geoportal/lib/lingua_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import subprocess
import os
import yaml
import re
import traceback
import requests
Expand Down Expand Up @@ -59,7 +58,6 @@
from c2cgeoportal_geoportal.lib import add_url_params, get_url2
from c2cgeoportal_geoportal.lib.bashcolor import colorize, RED
from c2cgeoportal_geoportal.lib.caching import init_region

from c2cgeoportal_geoportal.lib.print_ import * # noqa


Expand Down Expand Up @@ -422,7 +420,7 @@ def _import_layer_wms(self, layer, messages):
if layer.geo_table is not None and layer.geo_table != "":
try:
from c2cgeoportal_geoportal.views.layers import get_layer_class
cls = get_layer_class(layer, with_exclude=True)
cls = get_layer_class(layer, with_last_update_columns=True)
for column_property in class_mapper(cls).iterate_properties:
if isinstance(column_property, ColumnProperty) and len(column_property.columns) == 1:
column = column_property.columns[0]
Expand Down
22 changes: 16 additions & 6 deletions geoportal/c2cgeoportal_geoportal/views/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def metadata(self):
if not layer.public and self.request.user is None:
raise HTTPForbidden()

return get_layer_class(layer, with_exclude=True)
return get_layer_class(layer, with_last_update_columns=True)

@view_config(route_name="layers_enumerate_attribute_values", renderer="json")
def enumerate_attribute_values(self):
Expand Down Expand Up @@ -469,10 +469,19 @@ def query_enumerate_attribute_values(dbsession, layerinfos, fieldname):
return dbsession.query(distinct(attribute)).order_by(attribute).all()


def get_layer_class(layer, with_exclude=False):
if with_exclude:
# Exclude the columns used to record the last features update
exclude = [] if layer.exclude_properties is None else layer.exclude_properties.split(",")
def get_layer_class(layer, with_last_update_columns=False):
"""
Get the SQLAlchemy class to edit a GeoMapFish layer
:param layer:
:param with_last_update_columns: False to just have a class to access to the table and be able to
modify the last_update_columns, True to have a correct class to build the UI
(without the hidden column).
:return: SQLAlchemy class
"""
# Exclude the columns used to record the last features update
exclude = [] if layer.exclude_properties is None else layer.exclude_properties.split(",")
if with_last_update_columns:
last_update_date = Layers.get_metadata(layer, "lastUpdateDateColumn")
if last_update_date is not None:
exclude.append(last_update_date)
Expand All @@ -481,6 +490,7 @@ def get_layer_class(layer, with_exclude=False):
exclude.append(last_update_user)
else:
exclude = []

m = Layers.get_metadata(layer, "editingAttributesOrder")
attributes_order = m.split(',') if m else None
m = Layers.get_metadata(layer, "readonlyAttributes")
Expand Down Expand Up @@ -516,7 +526,7 @@ def get_layer_class(layer, with_exclude=False):


def get_layer_metadatas(layer):
cls = get_layer_class(layer, with_exclude=True)
cls = get_layer_class(layer, with_last_update_columns=True)
edit_columns = []

for column_property in class_mapper(cls).iterate_properties:
Expand Down

0 comments on commit c4c183f

Please sign in to comment.