本文整理汇总了Python中website.models.DraftRegistration类的典型用法代码示例。如果您正苦于以下问题:Python DraftRegistration类的具体用法?Python DraftRegistration怎么用?Python DraftRegistration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DraftRegistration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete_draft_registration_non_admin
def test_delete_draft_registration_non_admin(self):
assert_equal(1, DraftRegistration.find().count())
url = self.node.api_url_for('delete_draft_registration', draft_id=self.draft._id)
res = self.app.delete(url, auth=self.non_admin.auth, expect_errors=True)
assert_equal(res.status_code, http.FORBIDDEN)
assert_equal(1, DraftRegistration.find().count())
示例2: test_delete_draft_registration
def test_delete_draft_registration(self):
assert_equal(1, DraftRegistration.find().count())
url = self.node.api_url_for('delete_draft_registration', draft_id=self.draft._id)
res = self.app.delete(url, auth=self.user.auth)
assert_equal(res.status_code, http.NO_CONTENT)
assert_equal(0, DraftRegistration.find().count())
示例3: test_delete_draft_registration_approved_and_registration_deleted
def test_delete_draft_registration_approved_and_registration_deleted(self, mock_register_draft):
self.draft.register(auth=self.auth, save=True)
self.draft.registered_node.is_deleted = True
self.draft.registered_node.save()
assert_equal(1, DraftRegistration.find().count())
url = self.node.api_url_for('delete_draft_registration', draft_id=self.draft._id)
res = self.app.delete(url, auth=self.user.auth)
assert_equal(res.status_code, http.NO_CONTENT)
assert_equal(0, DraftRegistration.find().count())
示例4: migrate_drafts
def migrate_drafts(dry):
PREREG_CHALLENGE_METASCHEMA = get_prereg_schema()
draft_registrations = DraftRegistration.find(
Q('registration_schema', 'eq', PREREG_CHALLENGE_METASCHEMA)
)
count = 0
for r in draft_registrations:
# NOTE: We don't query Q('approval', 'eq', None) just in case
# approval is set but the fk doesn't exist in the database
if r.approval or r.registered_node:
continue
logger.debug('Reading draft with id: {0}'.format(r._id))
data = r.registration_metadata
migrated = False
for q, ans in data.iteritems():
if isinstance(ans.get('value'), dict):
for value in ans['value'].values():
migrated = migrate_file_meta(value)
else:
migrated = migrate_file_meta(ans)
if migrated:
count += 1
logger.info('Migrated draft with id: {0}'.format(r._id))
if not dry:
r.save()
logger.info('Done with {0} drafts migrated.'.format(count))
示例5: main
def main(dry_run=False, test=False):
with TokuTransaction():
prereg_drafts = DraftRegistration.find(
Q('registration_schema', 'eq', PREREG_SCHEMA)
)
for draft in prereg_drafts:
migrate_draft_metadata(draft, test)
if dry_run:
raise RuntimeError("Dry run, rolling back transaction")
示例6: test_new_draft_registration_POST
def test_new_draft_registration_POST(self):
target = NodeFactory(creator=self.user)
payload = {
'schema_name': self.meta_schema.name,
'schema_version': self.meta_schema.schema_version
}
url = target.web_url_for('new_draft_registration')
res = self.app.post(url, payload, auth=self.user.auth)
assert_equal(res.status_code, http.FOUND)
target.reload()
draft = DraftRegistration.find_one(Q('branched_from', 'eq', target))
assert_equal(draft.registration_schema, self.meta_schema)
示例7: migrate_drafts_metadata_key
def migrate_drafts_metadata_key(schema):
"""
Finds Veer draft registrations whose registration_metadata has an undefined key and corrects.
"""
drafts = DraftRegistration.find(Q('registration_schema', 'eq', schema))
total_drafts = drafts.count()
logger.info('Examining {} drafts for improper key'.format(total_drafts))
draft_count = 0
for draft in drafts:
draft_count += 1
if draft.registration_metadata.get('recommended-methods', {}).get('value', {}).get('undefined', {}):
draft.registration_metadata['recommended-methods']['value']['procedure'] = draft.registration_metadata['recommended-methods']['value'].pop('undefined')
draft.save()
logger.info('{}/{} Migrated key for {}'.format(draft_count, total_drafts, draft._id))
else:
logger.info('{}/{} Key already correct for {}. No change.'.format(draft_count, drafts.count(), draft._id))
示例8: migrate_drafts_q5_metadata
def migrate_drafts_q5_metadata(schema):
"""
Finds Prereg Challenge draft registrations and corrects q5 response metadata
"""
drafts = DraftRegistration.find(Q('registration_schema', 'eq', schema))
total_drafts = drafts.count()
logger.info('Examining {} drafts for q5 metadata'.format(total_drafts))
draft_count = 0
for draft in drafts:
draft_count += 1
if draft.registration_metadata.get('q5', {}).get('value', {}):
draft.registration_metadata['q5']['value'] = draft.registration_metadata['q5']['value'].rstrip()
draft.save()
logger.info('{}/{} Migrated q5 response for {}'.format(draft_count, total_drafts, draft._id))
else:
logger.info('{}/{} q5 not answered. No change needed for {}.'.format(draft_count, drafts.count(), draft._id))
示例9: migrate
def migrate(dry=True):
registrations = Node.find(
Q('is_registration', 'eq', True) &
Q('registered_meta', 'ne', None)
)
regs_migrated, reg_errored = migrate_extras(registrations, dry=dry)
drafts = DraftRegistration.find(Q('registration_metadata', 'ne', {}))
drafts_migrated, drafts_errored = migrate_extras(drafts, dry=dry)
logger.info('Migrated registered_meta for {} registrations'.format(len(regs_migrated)))
if reg_errored:
logger.error('{} errored: {}'.format(len(reg_errored), reg_errored))
logger.info('Migrated registered_meta for {} draft registrations'.format(len(drafts_migrated)))
if drafts_errored:
logger.error('{} errored: {}'.format(len(drafts_errored), drafts_errored))
示例10: main
def main(dry_run=True):
if dry_run:
logger.warn('DRY RUN mode')
pending_approval_drafts = DraftRegistration.find()
need_approval_drafts = [draft for draft in pending_approval_drafts
if draft.requires_approval and draft.approval and draft.approval.state == Sanction.UNAPPROVED]
for draft in need_approval_drafts:
sanction = draft.approval
try:
if not dry_run:
sanction.state = Sanction.APPROVED
sanction._on_complete(None)
sanction.save()
logger.warn('Approved {0}'.format(draft._id))
except Exception as e:
logger.error(e)
示例11: main
def main(dry_run=False, test=False):
init_app(set_backends=True, routes=False)
prereg_schema = get_prereg_schema()
count = 0
with TokuTransaction():
prereg_drafts = DraftRegistration.find(
Q('registration_schema', 'eq', prereg_schema)
)
for draft in prereg_drafts:
# only migrate unapproved drafts
if draft.is_approved:
continue
changed = migrate_draft_metadata(draft, test)
if changed:
count += 1
logger.info('Migrated {} drafts'.format(count))
if dry_run:
raise RuntimeError('Dry run, rolling back transaction')
示例12: main
def main(dry_run=True):
if dry_run:
logger.warn('DRY RUN mode')
pending_approval_drafts = DraftRegistration.find()
need_approval_drafts = [draft for draft in pending_approval_drafts
if draft.requires_approval and draft.approval and draft.approval.state == Sanction.UNAPPROVED]
for draft in need_approval_drafts:
add_comments(draft)
sanction = draft.approval
try:
if not dry_run:
sanction.forcibly_reject()
#manually do the on_reject functionality to prevent send_mail problems
sanction.meta = {}
sanction.save()
draft.approval = None
draft.save()
logger.warn('Rejected {0}'.format(draft._id))
except Exception as e:
logger.error(e)
示例13: create
def create(self, validated_data):
node = validated_data.pop('node')
initiator = validated_data.pop('initiator')
metadata = validated_data.pop('registration_metadata', None)
schema_id = validated_data.pop('registration_schema').get('_id')
schema = get_object_or_error(MetaSchema, schema_id)
if schema.schema_version != LATEST_SCHEMA_VERSION or schema.name not in ACTIVE_META_SCHEMAS:
raise exceptions.ValidationError('Registration supplement must be an active schema.')
draft = DraftRegistration.create_from_node(node=node, user=initiator, schema=schema)
reviewer = is_prereg_admin_not_project_admin(self.context['request'], draft)
if metadata:
try:
# Required fields are only required when creating the actual registration, not updating the draft.
draft.validate_metadata(metadata=metadata, reviewer=reviewer, required_fields=False)
except ValidationValueError as e:
raise exceptions.ValidationError(e.message)
draft.update_metadata(metadata)
draft.save()
return draft
示例14: migrate_drafts
def migrate_drafts():
PREREG_CHALLENGE_METASCHEMA = get_prereg_schema()
draft_registrations = DraftRegistration.find(
Q('registration_schema', 'eq', PREREG_CHALLENGE_METASCHEMA)
)
count = 0
for draft in draft_registrations:
migrated = False
logger.debug('Reading preregistration draft with id: {0}'.format(draft._id))
for answer in draft.registration_metadata.values():
if isinstance(answer.get('value'), dict):
for value in answer['value'].values():
migrated_one = migrate_file_meta(value)
if migrated_one and not migrated:
migrated = True
else:
migrated_one = migrate_file_meta(answer)
if migrated_one and not migrated:
migrated = True
if migrated:
draft.save()
count += 1
logger.info('Migrated preregistration draft {0}'.format(draft._id))
logger.info('Done with {0} prereg drafts migrated.'.format(count))
示例15: migrate_drafts
def migrate_drafts(dry):
PREREG_CHALLENGE_METASCHEMA = get_prereg_schema()
draft_registrations = DraftRegistration.find(
Q('registration_schema', 'eq', PREREG_CHALLENGE_METASCHEMA) &
Q('approval', 'eq', None) &
Q('registered_node', 'eq', None)
)
count = 0
for r in draft_registrations:
data = r.registration_metadata
migrated = False
for q, ans in data.iteritems():
if isinstance(ans.get('value'), dict):
for value in ans['value'].values():
migrated = migrate_file_meta(value)
else:
migrated = migrate_file_meta(ans)
if migrated:
count += 1
logger.info('Migrated draft with id: {0}'.format(r._id))
if not dry:
r.save()
logger.info('Done with {0} drafts migrated.'.format(count))