Skip to content

Commit

Permalink
Checks for deleting and editing standard SRS
Browse files Browse the repository at this point in the history
  • Loading branch information
rendrom committed Jun 19, 2019
1 parent db96057 commit 3a79881
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 28 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*.js]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ doc/*/_build/
# IDE
.idea
.vscode

XDG_CACHE_HOME
22 changes: 11 additions & 11 deletions nextgisweb/spatial_ref_sys/amd/ngw-spatial-ref-sys/SRSWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,13 @@ define([
identity: "srs_list",
title: i18n.gettext("SRS"),

postCreate: function () {
this.inherited(arguments);

if (this.operation !== 'create') {
}

if (this.operation === 'create') {
}
constructor: function (obj) {
this.wktEditDisabled = obj.value && obj.value.disabled;
// this.fromWkt = obj.value && obj.value.wkt;
},


validateWidget: function () {
var widget = this;

var result = { isValid: true, error: [] };

Expand All @@ -62,19 +57,24 @@ define([
result.isValid = false;
}
});
// if (this.wktEditDisabled && this.fromWkt !== this.wkt.get("value")) {
// result.isValid = false;
// }

return result;
},

_setValueAttr: function (value) {
this.displayName.set("value", value.display_name);
this.wkt.set("value", value.wkt);
if (this.wkt) {
this.wkt.set("value", value.wkt);
}
},

_getValueAttr: function () {
var result = {
display_name: this.displayName.get("value"),
wkt: this.wkt.get("value"),
wkt: this.wkt.get("value")
};
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div data-dojo-type="${baseClass}" data-dojo-attach-point="focusNode" class="content-box">

<div data-dojo-type="dojox/layout/TableContainer"
data-dojo-props="cols:2, labelWidth: 150">

Expand All @@ -9,11 +10,12 @@
style="width: 100%">
</input>

{{#unless wktEditDisabled}}
<textarea data-dojo-attach-point="wkt"
data-dojo-type="dijit/form/SimpleTextarea"
data-dojo-props="rows: 4, colspan: 2, required: true"
title="{{gettext 'WKT'}}"
style="width: 100%; box-sizing: border-box"></textarea>

{{/unless}}
</div>
</div>
7 changes: 5 additions & 2 deletions nextgisweb/spatial_ref_sys/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
SRID_MAX = 998999 # PostGIS maximum srid (srs.id)
SRID_LOCAL = 990001 # First local srid (srs.id)

DISABLED_SRS = [4326, 3857]
WKT_ESPG_4326 = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]'
WKT_ESPG_3857 = 'PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],AUTHORITY["EPSG","3857"]]'

Expand Down Expand Up @@ -52,11 +51,15 @@ class SRS(Base):
name='srs_id_auth_check'),
)

def delete(selef):
raise Exception()

@db.validates('wkt')
def _validate_wkt(self, key, value):
sr = osr.SpatialReference()
if sr.ImportFromWkt(value) != 0:
raise ValueError('Invalid SRS WKT definition!')

self.proj4 = sr.ExportToProj4()
return value

Expand All @@ -75,7 +78,7 @@ def __unicode__(self):

@property
def disabled(self):
return self.auth_srid in DISABLED_SRS
return bool(self.auth_srid or self.auth_name)


db.event.listen(SRS.__table__, 'after_create', db.DDL("""
Expand Down
2 changes: 1 addition & 1 deletion nextgisweb/spatial_ref_sys/template/srs_browse.mako
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<td>${obj.display_name}</td>
<td>
<a class="material-icons icon-edit" href="${request.route_url('srs.edit', id=obj.id)}"></a>
%if not obj.disabled:
<a class="material-icons icon-edit" href="${request.route_url('srs.edit', id=obj.id)}"></a>
<a class="material-icons icon-delete" href="${request.route_url('srs.delete', id=obj.id)}"></a>
%endif
</td>
Expand Down
50 changes: 39 additions & 11 deletions nextgisweb/spatial_ref_sys/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from .. import dynmenu as dm

from .models import SRS
from ..models import DBSession

from .util import _

Expand All @@ -24,10 +23,26 @@ def check_permission(request):

request.require_administrator()

class SRSDeleteWidget(DeleteWidget):


def validate(self):
result = super(SRSDeleteWidget, self).validate()
self.error = []
if self.operation == 'delete':
disabled = self.obj.disabled
if disabled:
result = False
self.error.append(dict(
message=self.request.localizer.translate(
_("Unable to delete standard coordinate system."))))
return result


class SRSWidget(ObjectWidget):

def is_applicable(self):
return self.operation in ('create', 'edit')
return self.operation in ('create', 'edit', 'delete',)

def populate_obj(self):
super(SRSWidget, self).populate_obj()
Expand All @@ -41,12 +56,19 @@ def validate(self):

if self.operation == 'create':
conflict = SRS.filter_by(
auth_srid=self.data.get("auth_srid")).first()
display_name=self.data.get("display_name")).first()
if conflict:
result = False
self.error.append(dict(
message=self.request.localizer.translate(
_("SRS is not unique."))))
_("Coordinate system name is not unique."))))
elif self.operation == 'edit':
disallowed_wkt_change = self.obj.disabled and self.obj.wkt != self.data.get("wkt")
if disallowed_wkt_change:
result = False
self.error.append(dict(
message=self.request.localizer.translate(
_("Cannot change wkt of standard coordinate system."))))

return result

Expand Down Expand Up @@ -88,6 +110,11 @@ def delete_context(self, request):
check_permission(request)
obj = SRS.filter_by(**request.matchdict).one()

# disabled = obj.disabled
# if disabled:
# raise Exception(_("Unable to delete standard coordinate system."))


return dict(
obj=obj,
template=dict(obj=obj)
Expand All @@ -101,7 +128,7 @@ def query_object(self, context):

def widget_class(self, context, operation):
if operation == 'delete':
return DeleteWidget
return SRSDeleteWidget
else:
return SRSWidget

Expand Down Expand Up @@ -143,13 +170,14 @@ def build(self, kwargs):
id=kwargs.obj.id
)
)
yield dm.Link(
self.sub('delete'), _("Delete"),
lambda kwargs: kwargs.request.route_url(
'srs.delete',
id=kwargs.obj.id
if not kwargs.obj.disabled:
yield dm.Link(
self.sub('delete'), _("Delete"),
lambda kwargs: kwargs.request.route_url(
'srs.delete',
id=kwargs.obj.id
)
)
)


SRS.__dynmenu__ = comp.env.pyramid.control_panel
Expand Down
4 changes: 2 additions & 2 deletions nextgisweb/views/model_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def delete(self, request):
widget.bind(data=request.json_body, request=request)

if widget.validate():
DBSession.delete(obj)
DBSession.flush()
# DBSession.delete(obj)
# DBSession.flush()

return render_to_response(
'json',
Expand Down

0 comments on commit 3a79881

Please sign in to comment.