def member_dict_from_request(request, actor, join_or_renew): """Creates and returns a dict of member info from the request. new_or_renew should be "join" if this is (or expected to be) for a new member, or "renew" for a member being renewed. """ logging.info('member_dict_from_request') logging.info(request.params.items()) # Make sure the user/form/request isn't trying to mess with fields that it # shouldn't be. for name, field in config.MEMBER_FIELDS._asdict().items(): if not field.form_field and request.POST.get(name) is not None: # This causes the request processing to stop webapp2.abort(400, detail='invalid field') if field.values is not None and request.POST.get(name) is not None \ and not set(request.POST.get(name).split(config.MULTIVALUE_DIVIDER)).issubset(field.values): # This causes the request processing to stop webapp2.abort(400, detail='invalid field value') member = config.validate_member(request.POST) if not member: # This causes the request processing to stop webapp2.abort(400, detail='invalid input') # We didn't validate the geoposition above, so do it now geoposition = request.POST.get('geoposition', '') # TODO: don't hardcode field name geoposition_required = config.MEMBER_FIELDS.joined_latlong.required \ if join_or_renew == 'join' else \ config.MEMBER_FIELDS.renewed_latlong.required if not utils.latlong_validator(geoposition, geoposition_required): webapp2.abort(400, detail='invalid input') geoaddress = helpers.address_from_latlong(geoposition) if join_or_renew == 'join': # Set the GUID field member[config.MEMBER_FIELDS.id.name] = str(uuid.uuid4()) # Set the timestamps member[config.MEMBER_FIELDS.joined.name] = utils.current_datetime() member[config.MEMBER_FIELDS.joined_by.name] = actor member[config.MEMBER_FIELDS.joined_latlong.name] = geoposition member[config.MEMBER_FIELDS.joined_address.name] = geoaddress # These get set regardless of mode member[config.MEMBER_FIELDS.renewed.name] = utils.current_datetime() member[config.MEMBER_FIELDS.renewed_by.name] = actor member[config.MEMBER_FIELDS.renewed_latlong.name] = geoposition member[config.MEMBER_FIELDS.renewed_address.name] = geoaddress member[config.MEMBER_FIELDS.address_latlong.name] = helpers.latlong_for_record( config.MEMBER_FIELDS, member) # We want the "MailChimp Updated" field to be cleared, regardless of mode member[config.MEMBER_FIELDS.mailchimp_updated.name] = '' return member
def member_dict_from_request(request, actor, join_or_renew): """Creates and returns a dict of member info from the request. new_or_renew should be "join" if this is (or expected to be) for a new member, or "renew" for a member being renewed. """ logging.info('member_dict_from_request') logging.info(request.params.items()) # Make sure the user/form/request isn't trying to mess with fields that it # shouldn't be. for name, field in config.MEMBER_FIELDS._asdict().items(): if not field.form_field and request.POST.get(name) is not None: # This causes the request processing to stop webapp2.abort(400, detail='invalid field') if field.values is not None and request.POST.get(name) is not None \ and not set(request.POST.get(name).split(config.MULTIVALUE_DIVIDER)).issubset(field.values): # This causes the request processing to stop webapp2.abort(400, detail='invalid field value') member = config.validate_member(request.POST) if not member: # This causes the request processing to stop webapp2.abort(400, detail='invalid input') # We didn't validate the geoposition above, so do it now geoposition = request.POST.get('geoposition', '') # TODO: don't hardcode field name geoposition_required = config.MEMBER_FIELDS.joined_latlong.required \ if join_or_renew == 'join' else \ config.MEMBER_FIELDS.renewed_latlong.required if not utils.latlong_validator(geoposition, geoposition_required): webapp2.abort(400, detail='invalid input') geoaddress = helpers.address_from_latlong(geoposition) if join_or_renew == 'join': # Set the GUID field member[config.MEMBER_FIELDS.id.name] = str(uuid.uuid4()) # Set the timestamps member[config.MEMBER_FIELDS.joined.name] = utils.current_datetime() member[config.MEMBER_FIELDS.joined_by.name] = actor member[config.MEMBER_FIELDS.joined_latlong.name] = geoposition member[config.MEMBER_FIELDS.joined_address.name] = geoaddress # These get set regardless of mode member[config.MEMBER_FIELDS.renewed.name] = utils.current_datetime() member[config.MEMBER_FIELDS.renewed_by.name] = actor member[config.MEMBER_FIELDS.renewed_latlong.name] = geoposition member[config.MEMBER_FIELDS.renewed_address.name] = geoaddress member[config.MEMBER_FIELDS.address_latlong. name] = helpers.latlong_for_record(config.MEMBER_FIELDS, member) # We want the "MailChimp Updated" field to be cleared, regardless of mode member[config.MEMBER_FIELDS.mailchimp_updated.name] = '' return member
def send_msg_to_MQ( msg_data): # Build connection -> build channel -> send message #建立连接,然后发起通道,然后再发送信息 connection = BlockingConnection( ConnectionParameters(host=HOST_NAME, port=HOST_PORT, virtual_host='/', credentials=credentials)) channel = connection.channel() result = channel.queue_declare( queue='un_judged') # 声明消息队列,消息将在这个队列传递,如不存在,则创建 """ data: msg_data; @key='TaskID' value->str # 自动生成唯一的任务ID (自动生成) @key='studentNumber' value->str # 学号 @key='code' value->str # 需要评判的代码 @key='time' value->str # 当前的时间 (自动生成) """ TID = gen_task_ID(msg_data['studentNumber']) message = json.dumps({ 'TaskID': TID, 'code': msg_data['code'], 'time': current_datetime(), 'studentNumber': msg_data['studentNumber'] }) # build msg channel.basic_publish(exchange='', routing_key='un_judged', body=message) # 向队列插入数值 routing_key是队列名 connection.close() return TID
def authorize_new_user(request, user): """Creates a new member with the data in the reqeust. """ logging.info('authorize_user') logging.info(request.params.items()) new_user = config.validate_obj_against_fields(request.POST, config.AUTHORIZED_FIELDS) if not new_user: # This causes the request processing to stop webapp2.abort(400, detail='invalid input') # Check if this user (i.e., email) is already authorized # NOTE: We're putting "" around the second %s because otherwise the query # gives an error. querystring = '%s=="%s"' % (config.AUTHORIZED_FIELDS.email.name, request.POST.get(config.AUTHORIZED_FIELDS.email.name)) existing_user = _get_single_list_entry(querystring, config.AUTHORIZED_SPREADSHEET_KEY, config.AUTHORIZED_WORKSHEET_KEY) if existing_user: # This causes the request processing to stop webapp2.abort(400, detail='user email address already authorized') # Set the GUID field new_user[config.AUTHORIZED_FIELDS.id.name] = str(uuid.uuid4()) # Set the timestamps new_user[config.AUTHORIZED_FIELDS.created.name] = utils.current_datetime() new_user[config.AUTHORIZED_FIELDS.created_by.name] = user.email() _add_new_row(new_user, config.AUTHORIZED_SPREADSHEET_KEY, config.AUTHORIZED_WORKSHEET_KEY)
def parse_form_for_post(form, post): title = form.get('title') readable_id = form.get('readable_id') text_type = form.get('text_type') created_at = form.get('created_at') if created_at is not None: created_at = dateutil.parser.parse(created_at) if created_at.tzinfo: created_at = created_at.astimezone(pytz.utc) updated_at = current_datetime() text = form.get('text', '') is_draft = any(form.getlist("draft", type=int)) old_url = full_url_of(post) was_draft = post.draft post.text = text post.text_type = text_type post.draft = is_draft post.updated_at = updated_at post.created_at = created_at post.readable_id = readable_id post.title = title if not was_draft: return old_url return None
def authorize_new_user(request, user): """Creates a new member with the data in the reqeust. """ logging.info('authorize_user') logging.info(request.params.items()) new_user = config.validate_obj_against_fields(request.POST, config.AUTHORIZED_FIELDS) if not new_user: # This causes the request processing to stop webapp2.abort(400, detail='invalid input') # Check if this user (i.e., email) is already authorized # NOTE: We're putting "" around the second %s because otherwise the query # gives an error. querystring = '%s=="%s"' % (config.AUTHORIZED_FIELDS.email.name, request.POST.get( config.AUTHORIZED_FIELDS.email.name)) existing_user = _get_single_list_entry(querystring, config.AUTHORIZED_SPREADSHEET_KEY, config.AUTHORIZED_WORKSHEET_KEY) if existing_user: # This causes the request processing to stop webapp2.abort(400, detail='user email address already authorized') # Set the GUID field new_user[config.AUTHORIZED_FIELDS.id.name] = str(uuid.uuid4()) # Set the timestamps new_user[config.AUTHORIZED_FIELDS.created.name] = utils.current_datetime() new_user[config.AUTHORIZED_FIELDS.created_by.name] = user.email() _add_new_row(new_user, config.AUTHORIZED_SPREADSHEET_KEY, config.AUTHORIZED_WORKSHEET_KEY)
def renew_member_by_email_or_paypal_id(email, paypal_payer_id, member_dict): """Looks in any email fields for the given email address and in the payer ID field for `paypal_payer_id`. Updates member entry from `member_dict`. Returns True if the member was found and renewed. """ querystring = '%s=="%s" or %s=="%s" or %s=="%s"' % ( config.MEMBER_FIELDS.paypal_payer_id.name, paypal_payer_id, config.MEMBER_FIELDS.email.name, email, config.MEMBER_FIELDS.paypal_email.name, email) list_entry = _get_single_list_entry(querystring, config.MEMBERS_SPREADSHEET_KEY, config.MEMBERS_WORKSHEET_KEY) # TODO: Refactor this duplication member_dict[config.MEMBER_FIELDS.renewed.name] = utils.current_datetime() member_dict[ config.MEMBER_FIELDS.renewed_by.name] = config.PAYPAL_ACTOR_NAME member_dict[config.MEMBER_FIELDS.renewed_latlong.name] = '' member_dict[config.MEMBER_FIELDS.renewed_address.name] = '' # HACK: In theory we should be updating the address geoposition here. But # we "know" that the address isn't changing. Make sure this is better when # we refactor this stuff. #member_dict[config.MEMBER_FIELDS.address_latlong.name] = helpers.latlong_for_record(config.MEMBER_FIELDS, member_dict) # We're not bothering to clear the "MailChimp Updated" field here, since we # know that no interesting fields are changing in the member row if list_entry: _update_record(config.MEMBER_FIELDS, list_entry, member_dict) return True return False
def authorize_new_user(request: flask.Request, current_user_email: str): """Creates a new member with the data in the request. Calls flask.abort on bad input. """ logging.info('authorize_new_user') logging.info(list(request.values.items())) new_user = config.validate_obj_against_fields(request.values, _S.authorized.fields) if not new_user: logging.warning( 'gapps.authorize_new_user: config.validate_obj_against_fields failed' ) # This causes the request processing to stop flask.abort(400, description='invalid input') # Check if this user (i.e., email) is already authorized if is_user_authorized(request.values.get(_S.authorized.fields.email.name)): # This causes the request processing to stop flask.abort(400, description='user email address already authorized') # Set the GUID field new_user[_S.authorized.fields.id.name] = str(uuid.uuid4()) # Set the timestamps new_user[_S.authorized.fields.created.name] = utils.current_datetime() new_user[_S.authorized.fields.created_by.name] = current_user_email # Don't record a demo user's email address if config.DEMO: new_user[_S.authorized.fields.created_by.name] = '*****@*****.**' sheetdata.Row(dct=new_user, sheet=_S.authorized).append()
def renew_member_by_email_or_paypal_id(email, paypal_payer_id, member_dict): """Looks in any email fields for the given email address and in the payer ID field for `paypal_payer_id`. Updates member entry from `member_dict`. Returns True if the member was found and renewed. """ querystring = '%s=="%s" or %s=="%s" or %s=="%s"' % ( config.MEMBER_FIELDS.paypal_payer_id.name, paypal_payer_id, config.MEMBER_FIELDS.email.name, email, config.MEMBER_FIELDS.paypal_email.name, email) list_entry = _get_single_list_entry(querystring, config.MEMBERS_SPREADSHEET_KEY, config.MEMBERS_WORKSHEET_KEY) # TODO: Refactor this duplication member_dict[config.MEMBER_FIELDS.renewed.name] = utils.current_datetime() member_dict[config.MEMBER_FIELDS.renewed_by.name] = config.PAYPAL_ACTOR_NAME member_dict[config.MEMBER_FIELDS.renewed_latlong.name] = '' member_dict[config.MEMBER_FIELDS.renewed_address.name] = '' # HACK: In theory we should be updating the address geoposition here. But # we "know" that the address isn't changing. Make sure this is better when # we refactor this stuff. #member_dict[config.MEMBER_FIELDS.address_latlong.name] = helpers.latlong_for_record(config.MEMBER_FIELDS, member_dict) # We're not bothering to clear the "MailChimp Updated" field here, since we # know that no interesting fields are changing in the member row if list_entry: _update_record(config.MEMBER_FIELDS, list_entry, member_dict) return True return False
def volunteer_dict_from_request(request: flask.Request, actor: str) -> dict: """Creates and returns a dict of volunteer info from the request. `actor` is the ID/email of the person or entity that is triggering this. """ logging.debug('gapps.volunteer_dict_from_request: %s', list(request.values.items())) # Make sure the user/form/request isn't trying to mess with fields that it # shouldn't be. for name, field in _S.volunteer.fields._asdict().items(): if not field.form_field and request.values.get(name) is not None: # This causes the request processing to stop flask.abort(400, description='invalid field') if field.values is not None and request.values.get(name) is not None \ and not set(request.values.get(name).split(config.MULTIVALUE_DIVIDER)).issubset(field.values): # This causes the request processing to stop flask.abort(400, description='invalid field value') volunteer = config.validate_volunteer(request.values) if not volunteer: logging.warning( 'gapps.volunteer_dict_from_request: config.validate_volunteer failed' ) # This causes the request processing to stop flask.abort(400, description='invalid input') # We didn't validate the geoposition above, so do it now geoposition = request.values.get(_GEOPOSITION_VALUE_KEY, '') geoposition_required = _S.volunteer.fields.joined_latlong.required if not utils.latlong_validator(geoposition, geoposition_required): logging.warning( 'gapps.volunteer_dict_from_request: utils.latlong_validator failed' ) flask.abort(400, description='invalid input') geoaddress = helpers.address_from_latlong(geoposition) # Set the GUID field volunteer[_S.volunteer.fields.id.name] = str(uuid.uuid4()) # Set the timestamps volunteer[_S.volunteer.fields.joined.name] = utils.current_datetime() volunteer[_S.volunteer.fields.joined_by.name] = actor volunteer[_S.volunteer.fields.joined_latlong.name] = geoposition volunteer[_S.volunteer.fields.joined_address.name] = geoaddress volunteer[_S.volunteer.fields.address_latlong.name] = \ helpers.latlong_for_record(_S.volunteer.fields, volunteer) return volunteer
def parse(self): response = requests.get(self.url).text bs = BeautifulSoup(response, "html.parser") for each in bs.find('div', class_='lft').find_all('li', onmouseover=True): rows = [i.text for i in each.find_all('span')] tmp = rows[2].split() status = add_status(tmp[1][0], tmp[0], "-") item = dict( name=INDEX_DICT[rows[0]], price=rows[1].replace(",", ""), status=status, rate=tmp[1][:-3].replace("+", ""), date=current_datetime() ) self.items.append(item)
def process_mailchimp_updates(): """Checks Members and Volunteers spreadsheets for records that need updating in MailChimp. """ # See comment in `cull_members_sheet()` for why we're using `taskqueue` # to process these records one at a time. googledata = GoogleData() for fields, spreadsheet_key, worksheet_key, mailchimp_upsert in ( (config.MEMBER_FIELDS, config.MEMBERS_SPREADSHEET_KEY, config.MEMBERS_WORKSHEET_KEY, mailchimp.upsert_member_info), (config.VOLUNTEER_FIELDS, config.VOLUNTEERS_SPREADSHEET_KEY, config.VOLUNTEERS_WORKSHEET_KEY, mailchimp.upsert_volunteer_info), ): querystring = '%s==""' % (fields.mailchimp_updated.name, ) list_entries = googledata.get_list_entries(spreadsheet_key, worksheet_key, query=querystring) for entry in list_entries: entry_dict = entry.to_dict() if not entry_dict.get(fields.id.name): logging.error('Member missing ID value: %s', entry_dict) continue if not entry_dict.get(fields.email.name): # If there's no email, we don't add to MailChimp continue # Updated MailChimp mailchimp_upsert(entry_dict) # Set the MailChimp update datetime entry.set_value(fields.mailchimp_updated.name, utils.current_datetime()) # Update the spreadsheet _update_list_entry(entry) # We've updated one record successfully. Enqueue another run and exit. taskqueue.add(url='/tasks/process-mailchimp-updates') return
def volunteer_dict_from_request(request, actor): """Creates and returns a dict of volunteer info from the request. """ logging.debug('volunteer_dict_from_request') logging.debug(request.params.items()) # Make sure the user/form/request isn't trying to mess with fields that it # shouldn't be. for name, field in config.VOLUNTEER_FIELDS._asdict().items(): if not field.form_field and request.POST.get(name) is not None: # This causes the request processing to stop webapp2.abort(400, detail='invalid field') if field.values is not None and request.POST.get(name) is not None \ and not set(request.POST.get(name).split(config.MULTIVALUE_DIVIDER)).issubset(field.values): # This causes the request processing to stop webapp2.abort(400, detail='invalid field value') volunteer = config.validate_volunteer(request.POST) if not volunteer: # This causes the request processing to stop webapp2.abort(400, detail='invalid input') # We didn't validate the geoposition above, so do it now geoposition = request.POST.get('geoposition', '') # TODO: don't hardcode field name geoposition_required = config.VOLUNTEER_FIELDS.joined_latlong.required if not utils.latlong_validator(geoposition, geoposition_required): webapp2.abort(400, detail='invalid input') geoaddress = helpers.address_from_latlong(geoposition) # Set the GUID field volunteer[config.VOLUNTEER_FIELDS.id.name] = str(uuid.uuid4()) # Set the timestamps volunteer[config.VOLUNTEER_FIELDS.joined.name] = utils.current_datetime() volunteer[config.VOLUNTEER_FIELDS.joined_by.name] = actor volunteer[config.VOLUNTEER_FIELDS.joined_latlong.name] = geoposition volunteer[config.VOLUNTEER_FIELDS.joined_address.name] = geoaddress volunteer[config.VOLUNTEER_FIELDS.address_latlong.name] = \ helpers.latlong_for_record(config.VOLUNTEER_FIELDS, volunteer) return volunteer
def process_mailchimp_updates(): """Checks Members and Volunteers spreadsheets for records that need updating in MailChimp. """ # See comment in `cull_members_sheet()` for why we're using `taskqueue` # to process these records one at a time. googledata = GoogleData() for fields, spreadsheet_key, worksheet_key, mailchimp_upsert in ( (config.MEMBER_FIELDS, config.MEMBERS_SPREADSHEET_KEY, config.MEMBERS_WORKSHEET_KEY, mailchimp.upsert_member_info), (config.VOLUNTEER_FIELDS, config.VOLUNTEERS_SPREADSHEET_KEY, config.VOLUNTEERS_WORKSHEET_KEY, mailchimp.upsert_volunteer_info), ): querystring = '%s==""' % (fields.mailchimp_updated.name,) list_entries = googledata.get_list_entries(spreadsheet_key, worksheet_key, query=querystring) for entry in list_entries: entry_dict = entry.to_dict() if not entry_dict.get(fields.id.name): logging.error('Member missing ID value: %s', entry_dict) continue if not entry_dict.get(fields.email.name): # If there's no email, we don't add to MailChimp continue # Updated MailChimp mailchimp_upsert(entry_dict) # Set the MailChimp update datetime entry.set_value(fields.mailchimp_updated.name, utils.current_datetime()) # Update the spreadsheet _update_list_entry(entry) # We've updated one record successfully. Enqueue another run and exit. taskqueue.add(url='/tasks/process-mailchimp-updates') return
def __init__(self, name, work_dir, data_dir, output_root): super(Configuration, self).__init__() # file related params self.work_dir = work_dir self.data_dir = data_dir self.vocab_path = os.path.join(self.data_dir, 'vocabulary') self.embed_path = os.path.join(self.data_dir, 'glove_embedding.npy') self.vocab_size = line_count(self.vocab_path, skip_empty=True) with setups(self): with immutables(self): self.start_time = current_datetime() self.name = name self.output_dir = os.path.join(output_root, name) self.train_path = os.path.join(self.data_dir, 'trainyiseg.csv') self.train_eval_path = os.path.join(self.data_dir, 'trainyiseg_eval.csv') self.valid_path = os.path.join(self.data_dir, 'validyiseg.csv') self.test_path = os.path.join(self.data_dir, 'testayiseg.csv') self.model_path = os.path.join(self.output_dir, 'model') self.elmo_path = os.path.join(self.data_dir, 'elmo', 'model') self.num_aspects = 20 self.visible_gpus = '0' # visible GPUs self.num_gpus = len(self.visible_gpus.split(',')) os.environ['CUDA_VISIBLE_DEVICES'] = self.visible_gpus with structures(self): self.hidden_size = 512 self.embed_size = 300 self.atn_units = 300 self.num_layers = 1 self.use_elmo = False with learning(self): # training process params self.load_embed = True self.keep_prob = 0.65 self.rnn_kernel_keep_prob = 0.8 self.max_epoch = 50 self.grad_clip_max_norm = 5.0 self.early_stop_epoch = 10 # input params self.batch_size = 64 self.eval_batch_size = 64
def renew_member_by_email_or_paypal_id(email: str, paypal_payer_id: str, member_dict: dict) -> bool: """Looks in any email fields for the given email address and in the payer ID field for `paypal_payer_id`. Updates member entry from `member_dict`. Returns True if the member was found and renewed. """ if not email and not paypal_payer_id: logging.warning( 'gapps.renew_member_by_email_or_paypal_id: email and paypal_payer_id empty' ) return False def matcher(d): if paypal_payer_id and (d[_S.member.fields.paypal_payer_id.name] == paypal_payer_id): return True if email and (d[_S.member.fields.email.name] == email) or ( d[_S.member.fields.paypal_email.name] == email): return True return False row = sheetdata.Row.find(_S.member, matcher) if not row: return False member_dict[_S.member.fields.renewed.name] = utils.current_datetime() member_dict[_S.member.fields.renewed_by.name] = config.PAYPAL_ACTOR_NAME member_dict[_S.member.fields.renewed_latlong.name] = '' member_dict[_S.member.fields.renewed_address.name] = '' # HACK: In theory we should be updating the address geoposition here. But # we "know" that the address isn't changing. Make sure this is better when # we refactor this stuff. #member_dict[_S.member.fields.address_latlong.name] = helpers.latlong_for_record(_S.member.fields, member_dict) # We're not bothering to clear the "MailChimp Updated" field here, since we # know that no interesting fields are changing in the member row row.dict.update(member_dict) row.update() return True
def process_mailchimp_updates(): """Checks Members and Volunteers spreadsheets for records that need updating in MailChimp. """ for sheet, mailchimp_upsert in ( (_S.member, mailchimp.upsert_member_info), (_S.volunteer, mailchimp.upsert_volunteer_info), ): rows = sheetdata.find_rows( sheet, lambda d: not d[sheet.fields.mailchimp_updated.name]) rows_to_update = [] for row in rows: if not row.dict.get(sheet.fields.id.name): logging.error('Member or Volunteer missing ID value: %s', row.dict) continue if not row.dict.get(sheet.fields.email.name): # If there's no email, we don't add to MailChimp continue # Set the MailChimp update datetime row.dict[sheet.fields.mailchimp_updated. name] = utils.current_datetime() # Update MailChimp. Note that this involves a network call. # TODO: Is there a bulk upsert for Mailchimp? mailchimp_upsert(row.dict) rows_to_update.append(row) sheetdata.update_rows(sheet, rows_to_update)
def member_dict_from_request(request: flask.Request, actor: str, join_or_renew: str) -> dict: """Creates and returns a dict of member info from the request. new_or_renew should be "join" if this is (or expected to be) for a new member, or "renew" for a member being renewed. `actor` is the ID/email of the person or entity that is triggering this. """ logging.info('member_dict_from_request') logging.info(list(request.values.items())) # Make sure the user/form/request isn't trying to mess with fields that it # shouldn't be. for name, field in _S.member.fields._asdict().items(): if not field.form_field and request.values.get(name) is not None: # There is a field provided in the request that isn't one that's allowed to be # set via the form. This can be achieved by an attacker by modifying the page # elements. This causes the request processing to stop. flask.abort(400, description='invalid field') if field.values is not None and request.values.get(name) is not None \ and not set(request.values.get(name).split(config.MULTIVALUE_DIVIDER)).issubset(field.values): # This field has a restricted set of allowed values, and the form has provided # one that isn't allowed. This causes the request processing to stop. flask.abort(400, description='invalid field value') member = config.validate_member(request.values) if not member: logging.warning( 'gapps.member_dict_from_request: config.validate_member failed') # This causes the request processing to stop flask.abort(400, description='invalid input') # We didn't validate the geoposition above, so do it now geoposition = request.values.get(_GEOPOSITION_VALUE_KEY, '') geoposition_required = _S.member.fields.joined_latlong.required \ if join_or_renew == 'join' else \ _S.member.fields.renewed_latlong.required if not utils.latlong_validator(geoposition, geoposition_required): logging.warning( 'gapps.member_dict_from_request: utils.latlong_validator failed') flask.abort(400, description='invalid input') geoaddress = helpers.address_from_latlong(geoposition) if join_or_renew == 'join': # Set the GUID field member[_S.member.fields.id.name] = str(uuid.uuid4()) # Set the timestamps member[_S.member.fields.joined.name] = utils.current_datetime() member[_S.member.fields.joined_by.name] = actor member[_S.member.fields.joined_latlong.name] = geoposition member[_S.member.fields.joined_address.name] = geoaddress # These get set regardless of mode member[_S.member.fields.renewed.name] = utils.current_datetime() member[_S.member.fields.renewed_by.name] = actor member[_S.member.fields.renewed_latlong.name] = geoposition member[_S.member.fields.renewed_address.name] = geoaddress member[_S.member.fields.address_latlong.name] = helpers.latlong_for_record( _S.member.fields, member) # We want the "MailChimp Updated" field to be cleared, regardless of mode member[_S.member.fields.mailchimp_updated.name] = '' # Fields clear if we're in demo mode. We don't want to record a demo user's email address. if config.DEMO: member[_S.member.fields.joined_by.name] = '*****@*****.**' member[_S.member.fields.renewed_by.name] = '*****@*****.**' member[_S.member.fields.joined_latlong.name] = '' member[_S.member.fields.joined_address.name] = 'Demo' member[_S.member.fields.renewed_latlong.name] = '' member[_S.member.fields.renewed_address.name] = 'Demo' return member