本文整理汇总了Python中utils.log_api_action函数的典型用法代码示例。如果您正苦于以下问题:Python log_api_action函数的具体用法?Python log_api_action怎么用?Python log_api_action使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log_api_action函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self):
if self.config.read_auth_key_required and not (self.auth and self.auth.read_permission):
self.info(403, message="Missing or invalid authorization key", style="plain")
return
pfif_version = self.params.version
# Note that self.request.get can handle multiple IDs at once; we
# can consider adding support for multiple records later.
record_id = self.request.get("id")
if not record_id:
self.info(400, message="Missing id parameter", style="plain")
return
person = model.Person.get(self.repo, record_id, filter_expired=False)
if not person:
self.info(400, message="No person record with ID %s" % record_id, style="plain")
return
notes = model.Note.get_by_person_record_id(self.repo, record_id)
notes = [note for note in notes if not note.hidden]
self.response.headers["Content-Type"] = "application/xml"
records = [pfif_version.person_to_dict(person, person.is_expired)]
note_records = map(pfif_version.note_to_dict, notes)
utils.optionally_filter_sensitive_fields(records, self.auth)
utils.optionally_filter_sensitive_fields(note_records, self.auth)
pfif_version.write_file(self.response.out, records, lambda p: note_records)
utils.log_api_action(self, ApiActionLog.READ, len(records), len(notes))
示例2: get
def get(self):
if self.config.read_auth_key_required and not (
self.auth and self.auth.read_permission):
self.response.set_status(403)
self.write('Missing or invalid authorization key\n')
return
pfif_version = self.params.version
# Note that self.request.get can handle multiple IDs at once; we
# can consider adding support for multiple records later.
record_id = self.request.get('id')
if not record_id:
return self.error(400, 'Missing id parameter')
person = model.Person.get(
self.repo, record_id, filter_expired=False)
if not person:
return self.error(404, 'No person record with ID %s' % record_id)
notes = model.Note.get_by_person_record_id(self.repo, record_id)
notes = [note for note in notes if not note.hidden]
self.response.headers['Content-Type'] = 'application/xml'
records = [pfif_version.person_to_dict(person, person.is_expired)]
note_records = map(pfif_version.note_to_dict, notes)
utils.optionally_filter_sensitive_fields(records, self.auth)
utils.optionally_filter_sensitive_fields(note_records, self.auth)
pfif_version.write_file(
self.response.out, records, lambda p: note_records)
utils.log_api_action(
self, ApiActionLog.READ, len(records), len(notes))
示例3: get
def get(self):
if self.config.search_auth_key_required and not (
self.auth and self.auth.search_permission):
self.info(
403,
message='Missing or invalid authorization key',
style='plain')
return
pfif_version = self.params.version
# Retrieve parameters and do some sanity checks on them.
record_id = self.request.get('id')
query_string = self.request.get('q')
max_results = min(self.params.max_results or 100, HARD_MAX_RESULTS)
results = []
if record_id:
# Search by record ID (always returns just 1 result or nothing).
person = model.Person.get(self.repo, record_id)
if person:
results = [person]
elif query_string:
# Search by query words.
if self.config.external_search_backends:
query = TextQuery(query_string)
results = external_search.search(self.repo, query, max_results,
self.config.external_search_backends)
# External search backends are not always complete. Fall back to
# the original search when they fail or return no results.
if not results:
if config.get('enable_fulltext_search'):
results = full_text_search.search(
self.repo, query_string, max_results)
else:
results = indexing.search(
self.repo, TextQuery(query_string), max_results)
else:
self.info(
400,
message='Neither id nor q parameter specified',
style='plain')
records = [pfif_version.person_to_dict(result) for result in results]
utils.optionally_filter_sensitive_fields(records, self.auth)
# Define the function to retrieve notes for a person.
def get_notes_for_person(person):
notes = model.Note.get_by_person_record_id(
self.repo, person['person_record_id'])
notes = [note for note in notes if not note.hidden]
records = map(pfif_version.note_to_dict, notes)
utils.optionally_filter_sensitive_fields(records, self.auth)
return records
self.response.headers['Content-Type'] = 'application/xml; charset=utf-8'
pfif_version.write_file(
self.response.out, records, get_notes_for_person)
utils.log_api_action(self, ApiActionLog.SEARCH, len(records))
示例4: get
def get(self):
repos = model.Repo.list_launched()
if self.repo:
repos = [self.repo] if self.repo in repos else []
self.response.headers['Content-Type'] = 'application/xml'
atom.REPO_1_0.write_feed(
self.response.out, repos, self.request.url, self.TITLE,
get_latest_repo_updated_date(repos))
utils.log_api_action(self, model.ApiActionLog.REPO)
示例5: post
def post(self):
if not (self.auth and self.auth.subscribe_permission):
return self.error(403, "Missing or invalid authorization key")
subscription = model.Subscription.get(self.repo, self.params.id, self.params.subscribe_email)
self.response.set_status(200)
utils.log_api_action(self, ApiActionLog.UNSUBSCRIBE)
if subscription:
subscription.delete()
return self.info(200, "Successfully unsubscribed")
return self.info(200, "Not subscribed")
示例6: post
def post(self):
if not (self.auth and self.auth.domain_write_permission):
self.response.set_status(403)
# TODO(ryok): i18n
self.write('Missing or invalid authorization key.')
return
content = self.request.get('content')
if not content:
self.response.set_status(400)
self.write('You need to specify at least one CSV file.')
return
# TODO(ryok): let the user select timezone.
# TODO(ryok): accept more flexible date time format.
# TODO(ryok): support non-UTF8 encodings.
source_domain = self.auth.domain_write_permission
records = importer.utf8_decoder(
csv.DictReader(StringIO.StringIO(content)))
try:
records = [complete_record_ids(r, source_domain) for r in records]
except csv.Error:
self.response.set_status(400)
self.write('The CSV file is formatted incorrectly.')
return
is_empty = lambda x: (x or '').strip()
persons = [r for r in records if is_empty(r.get('full_name'))]
notes = [r for r in records if is_empty(r.get('note_record_id'))]
people_written, people_skipped, people_total = importer.import_records(
self.repo, source_domain, importer.create_person, persons)
notes_written, notes_skipped, notes_total = importer.import_records(
self.repo, source_domain, importer.create_note, notes)
utils.log_api_action(self, ApiActionLog.WRITE,
people_written, notes_written,
len(people_skipped), len(notes_skipped))
self.render('import.html',
stats=[
Struct(type='Person',
written=people_written,
skipped=people_skipped,
total=people_total),
Struct(type='Note',
written=notes_written,
skipped=notes_skipped,
total=notes_total)],
**get_tag_params(self))
示例7: convert_time_fields
source_domain = self.auth.domain_write_permission
records = importer.utf8_decoder(generate_note_record_ids(
convert_time_fields(csv.reader(lines))))
try:
records = [complete_record_ids(r, source_domain) for r in records]
except csv.Error, e:
self.error(400, message=
'The CSV file is formatted incorrectly. (%s)' % e)
return
notes_written, notes_skipped, notes_total = importer.import_records(
self.repo, source_domain, importer.create_note, records,
believed_dead_permission=self.auth.believed_dead_permission,
omit_duplicate_notes=True)
utils.log_api_action(self, ApiActionLog.WRITE,
0, notes_written, 0, len(notes_skipped))
self.render('import.html',
formats=get_requested_formats(self.env.path),
stats=[
Struct(type='Note',
written=notes_written,
skipped=notes_skipped,
total=notes_total)],
**get_tag_params(self))
def import_persons(self, lines):
# TODO(ryok): support non-UTF8 encodings.
source_domain = self.auth.domain_write_permission
records = importer.utf8_decoder(convert_time_fields(csv.reader(lines)))