def getbbox(coord, localrange): """ >>> getbbox("Point 56.1, -3.0", 100) (55.19961041787985, -4.614338821845118, 57.00038958212015, -1.3856611781548822) """ pt_lat, pt_long = IS_GEOLOCATION.parse_geopoint(coord) # pt_lat = 56.100 # pt_long = -3.0 minlat, minlong, maxlat, maxlong = boundingBox(pt_lat, pt_long, localrange) return minlat, minlong, maxlat, maxlong
def new_location(): stdclass = "btn btn-primary btn-xs btn-group-xs" # This allows creation and editing of a locations by their owner fields = ['location_name', 'description', 'address1', 'address2', 'address3', 'address4', 'addrcode', 'continent', 'country', 'subdivision', 'coord'] buttons = [TAG.button('Submit', _type="submit"), TAG.INPUT(_TYPE='BUTTON', _id="geocode", _class=stdclass, _onclick="", _VALUE="Get Co-ordinates"), TAG.INPUT(_TYPE='BUTTON', _id="rev_geocode", _class=stdclass, _onclick="", _VALUE="Get Address")] locationid = request.args(0, default=None) if locationid is not None: record = db.locn(locationid) form = SQLFORM(db.locn, record, fields=fields) else: form = SQLFORM(db.locn, fields=fields, buttons=buttons) if form.validate(): if locationid: if form.deleted: db(db.location.id == locationid).delete() response.flash = 'Location deleted' redirect(URL('location', 'index')) else: record.update_record(**dict(form.vars)) response.flash = 'Location updated' redirect(URL('location', 'index')) else: # write values into separate fields for indexed bb queries on non spatial databases form.vars.geoy, form.vars.geox = IS_GEOLOCATION.parse_geopoint(form.vars.coord) form.vars.id = db.locn.insert(**dict(form.vars)) session.flash = 'Location Created' redirect(URL('accept_location', args=[form.vars.id])) elif form.errors: response.flash = 'form has errors' else: response.flash = 'please fill out the form' return dict(form=form)
Field('coord', 'string', label='Lat/Longitude'), Field('question_long', 'double', default=0.0, label='Latitude', writable=False, readable=False), Field('question_lat', 'double', default=0.0, label='Longitude', writable=False, readable=False), Field('perccomplete', 'integer', default=0, label='Percent Complete', requires=IS_INT_IN_RANGE(0, 101, error_message='Must be between 0 and 100')), Field('notes', 'text', label='Notes', comment='General notes about question - may also document answers from knowledge engines'), Field('execstatus', 'string', label='Execution Status', default='Proposed', requires=IS_IN_SET(['Proposed', 'Planned', 'In Progress', 'Completed']))) # , widget=range100_widget - stuck with this as won't go to zero for some reason db.question.totanswers = Field.Lazy(lambda row: sum(row.question.answercounts)) db.question.numanswers = Field.Lazy(lambda row: len(row.question.numanswers)) db.question.correctanstext = Field.Lazy(lambda row: (row.question.correctans > -1 and row.question.answers[row.question.correctans]) or '') if use_geolocation: db.question.coord.requires = IS_GEOLOCATION() db.question.coord.widget = location_widget() db.question.eventid.requires = IS_IN_DB(db(db.evt.status == 'Open'), 'evt.id', '%(evt_name)s') db.question._after_insert.append(lambda fields, id: questcount_insert(fields, id)) def questcount_insert(fields, id): """ :param fields: question fields :param id: question id :return: True This updates the questcounts table with a category record and an answer group record for each questio submitted """ groupcat = 'G'
# used to block registration if required auth.settings.actions_disabled.append('register') # configure auth policy if useappconfig: auth.settings.registration_requires_verification = myconf.take('user.verification', cast=int) auth.settings.registration_requires_approval = myconf.take('user.approval', cast=int) else: auth.settings.registration_requires_verification = False auth.settings.registration_requires_approval = False auth.settings.reset_password_requires_verification = True db.auth_user.privacypref.requires = IS_IN_SET(['Standard', 'Extreme']) if use_geolocation and (not useappconfig or myconf.take('user.address', cast=int)): db.auth_user.coord.requires = IS_GEOLOCATION() db.auth_user.coord.widget = location_widget() # recommended and supported login methods are now web2py and socialauth - other code # is left as legacy but not supported if request.env.web2py_runtime_gae and login == 'google': from gluon.contrib.login_methods.gae_google_account import GaeGoogleAccount auth.settings.login_form = GaeGoogleAccount() elif login == 'janrain': # this is limited by Janrain providers # from gluon.contrib.login_methods.rpx_account import RPXAccount from gluon.contrib.login_methods.rpx_account import use_janrain use_janrain(auth, filename='private/janrain.key') elif login == 'web2pyandjanrain': # this is now proving useless as no providers really work # Dual login sort of working but not fully tested with Janrain - doesnt work with gae # from gluon.contrib.login_methods.extended_login_form import ExtendedLoginForm
default=True, comment='Allows other users to link events'), Field('auth_userid', 'reference auth_user', writable=False, readable=False, default=auth.user_id), Field('createdate', 'datetime', default=request.utcnow, writable=False, readable=False), format='%(location_name)s') db.locn.addrurl.requires = IS_EMPTY_OR(IS_URL()) db.locn.coord.requires = IS_GEOLOCATION() db.locn.coord.widget = location_widget() INIT = db(db.initialised).select().first() PARAMS = db(db.website_parameters).select().first() if PARAMS: labeltoplevel = PARAMS.level1desc or 'DfltContinent' labelmidlevel = PARAMS.level2desc or 'DfltCountry' labellowlevel = PARAMS.level3desc or 'DfltSubdivision' if INIT is None or INIT.website_init is False: if db(db.continent.continent_name == "Unspecified").isempty(): contid = db.continent.insert(continent_name="Unspecified") if db(db.resolve.resolve_name == "Standard").isempty(): resolveid = db.resolve.insert(resolve_name="Standard")