def send(request): message = request.params.get('message') conn_data = { 'message': message } if request.params.get('type'): conn_data['type'] = request.params.get('type') conn = create_or_update_conn(request.user.id, request.params.get('conn_id'), request.params.get('to'), **conn_data) to = User.bid(int(request.params.get('to'))) subject_type = request.params.get('subject_type', '') if subject_type != 'mentor': count_left = check_quota(request.user) - 1 if count_left in (10, 5, 2, 0): request.user.notificate('%s messages left in quota' % count_left) message = prep_message(message) data = {'to': to, 'from': request.user, 'message': message, 'hash': conn.code} conn.sent_at = datetime.now() if subject_type == 'mentor' or subject_type == 'faculty': data['conn'] = conn request.session.flash(render_template('/messaging/mentoring/success_requestmentoring.jinja2', {}, request), 'popup') to.send_mail('mentoring_request', request, data) return HTTPFound(request.referer or '/mentors') else: data['cname'] = (' of %s' % request.user.company.name) if request.user.company else '' if request.params.get('send_copy'): data_copy = data.copy() data_copy['hash'] = 'dummy' request.user.send_mail('connect_request', request, data_copy) request.session.flash(render_template('/messaging/connect_me/success_connectme.jinja2', {}, request), 'popup') to.send_mail('connect_request', request, data) return HTTPFound(request.referer or '/connections')
def _exception(code, exception, request): return Response(render_template( 'nextgisweb:wmsserver/template/wms111exception.mako', dict(code=code, exception=exception), request=request), content_type='application/vnd.ogc.se_xml', charset='utf-8')
def send_company(request): cid = int(request.params.get('to')) data = {'company_id': cid, 'message': request.params.get('message')} conn = create_or_update_conn(request.user.id, None, None, **data) DBSession.flush() main_poc = find_poc(conn.company, request) poc_emails = [main_poc[0].email] if not request.params.get('poc_id'): poc_emails = [u.email for u in conn.company.employees if u.point_of_contact and u.email] conn.user = main_poc[0] send_mail(poc_emails, 'company_connect_request', request, {'main_poc': main_poc[0], 'conn': conn, 'hash': conn.code, 'message': prep_message(conn.message)}) request.session.flash(render_template('/messaging/company/success_requestcompany.jinja2', {}, request), 'popup') return HTTPFound(request.referer or '/alchemist_startups')
def _get_feature_info(obj, params, request): p_bbox = _validate_bbox([float(v) for v in params.get('BBOX').split(',')]) p_width = int(params.get('WIDTH')) p_height = int(params.get('HEIGHT')) p_srs = params.get('SRS', params.get('CRS')) if p_srs is None: raise ValidationError(message="CRS/SRS parameter required.") p_info_format = params.get('INFO_FORMAT', 'text/html') p_x = float(params.get('X')) p_y = float(params.get('Y')) p_query_layers = params.get('QUERY_LAYERS').split(',') p_feature_count = int(params.get('FEATURE_COUNT', GFI_FEATURE_COUNT)) bw = p_bbox[2] - p_bbox[0] bh = p_bbox[3] - p_bbox[1] qbox = dict(l=p_bbox[0] + bw * (p_x - GFI_RADIUS) / p_width, b=p_bbox[3] - bh * (p_y + GFI_RADIUS) / p_height, r=p_bbox[0] + bw * (p_x + GFI_RADIUS) / p_width, t=p_bbox[3] - bh * (p_y - GFI_RADIUS) / p_height) try: epsg, axis_xy = parse_srs(p_srs) except SRSParseError as e: raise ValidationError(str(e)) try: srs = SRS.filter_by(id=epsg).one() except NoResultFound: raise ValidationError(message="SRS (id=%d) not found." % epsg) qgeom = Geometry.from_wkt( ("POLYGON((%(l)f %(b)f, %(l)f %(t)f, " + "%(r)f %(t)f, %(r)f %(b)f, %(l)f %(b)f))") % qbox, srs.id) results = list() fcount = 0 for lname in p_query_layers: layer = layer_by_keyname(obj, lname) flayer = layer.resource.feature_layer request.resource_permission(DataScope.read, layer.resource) request.resource_permission(DataScope.read, flayer) query = flayer.feature_query() query.intersects(qgeom) # Limit number of layer features so that we # don't overshoot its total number query.limit(p_feature_count - fcount) features = list(query()) fcount += len(features) results.append( Bunch(keyname=layer.keyname, display_name=layer.display_name, feature_layer=flayer, features=features)) # Needed number of features found, stop search if fcount >= p_feature_count: break if p_info_format == 'application/json': result = [ dict( keyname=result.keyname, display_name=result.display_name, features=[{ fld.display_name: feature.fields[fld.keyname] for fld in result.feature_layer.fields } for feature in result.features], ) for result in results ] return Response(json.dumps(result, cls=geojson.Encoder), content_type='application/json', charset='utf-8') return Response(render_template( 'nextgisweb:wmsserver/template/get_feature_info_html.mako', dict(results=results, resource=obj), request=request), content_type='text/html', charset='utf-8')
def _get_feature_info(obj, request): params = dict((k.upper(), v) for k, v in request.params.items()) p_bbox = tuple(map(float, params.get('BBOX').split(','))) p_width = int(params.get('WIDTH')) p_height = int(params.get('HEIGHT')) p_srs = params.get('SRS') p_info_format = params.get('INFO_FORMAT', 'text/html') p_x = float(params.get('X')) p_y = float(params.get('Y')) p_query_layers = params.get('QUERY_LAYERS').split(',') p_feature_count = int(params.get('FEATURE_COUNT', GFI_FEATURE_COUNT)) bw = p_bbox[2] - p_bbox[0] bh = p_bbox[3] - p_bbox[1] qbox = dict(l=p_bbox[0] + bw * (p_x - GFI_RADIUS) / p_width, b=p_bbox[3] - bh * (p_y + GFI_RADIUS) / p_height, r=p_bbox[0] + bw * (p_x + GFI_RADIUS) / p_width, t=p_bbox[3] - bh * (p_y - GFI_RADIUS) / p_height) srs = SRS.filter_by(id=int(p_srs.split(':')[-1])).one() qgeom = Geometry.from_wkt( ("POLYGON((%(l)f %(b)f, %(l)f %(t)f, " + "%(r)f %(t)f, %(r)f %(b)f, %(l)f %(b)f))") % qbox, srs.id) lmap = dict((lyr.keyname, lyr) for lyr in obj.layers) results = list() fcount = 0 for lname in p_query_layers: layer = lmap[lname] flayer = layer.resource.feature_layer request.resource_permission(DataScope.read, layer.resource) request.resource_permission(DataScope.read, flayer) query = flayer.feature_query() query.intersects(qgeom) # Limit number of layer features so that we # don't overshoot its total number query.limit(p_feature_count - fcount) features = list(query()) fcount += len(features) results.append( Bunch(keyname=layer.keyname, display_name=layer.display_name, feature_layer=flayer, features=features)) # Needed number of features found, stop search if fcount >= p_feature_count: break if p_info_format == 'application/json': result = [ dict( keyname=result.keyname, display_name=result.display_name, features=[{ fld.display_name: feature.fields[fld.keyname] for fld in result.feature_layer.fields } for feature in result.features], ) for result in results ] return Response(json.dumps(result, cls=geojson.Encoder), content_type='application/json', charset='utf-8') return Response(render_template( 'nextgisweb:wmsserver/template/get_feature_info_html.mako', dict(results=results, resource=obj), request=request), content_type='text/html', charset='utf-8')