本文整理匯總了Python中website.models.MetaSchema.find_one方法的典型用法代碼示例。如果您正苦於以下問題:Python MetaSchema.find_one方法的具體用法?Python MetaSchema.find_one怎麽用?Python MetaSchema.find_one使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類website.models.MetaSchema
的用法示例。
在下文中一共展示了MetaSchema.find_one方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUp
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def setUp(self):
super(TestDraftRegistrationUpdate, self).setUp()
ensure_schemas()
self.schema = MetaSchema.find_one(
Q('name', 'eq', 'OSF-Standard Pre-Data Collection Registration') &
Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
)
self.draft_registration = DraftRegistrationFactory(
initiator=self.user,
registration_schema=self.schema,
branched_from=self.public_project
)
self.prereg_schema = MetaSchema.find_one(
Q('name', 'eq', 'Prereg Challenge') &
Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
)
self.prereg_draft_registration = DraftRegistrationFactory(
initiator=self.user,
registration_schema=self.prereg_schema,
branched_from=self.public_project
)
self.registration_metadata = self.prereg_metadata(self.prereg_draft_registration)
self.other_project = ProjectFactory(creator=self.user)
self.url = '/{}nodes/{}/draft_registrations/{}/'.format(API_BASE, self.public_project._id, self.draft_registration._id)
self.payload = {
"data": {
"id": self.draft_registration._id,
"type": "draft_registrations",
"attributes": {
"registration_metadata": {
"datacompletion": {
"value": "No, data collection has not begun"
},
"looked": {
"value": "No"
},
"comments": {
"value": "This is my first registration."
}
}
}
}
}
示例2: test_update_draft_registration
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def test_update_draft_registration(self):
metadata = {
'summary': {
'value': 'updated',
'comments': []
}
}
assert_not_equal(metadata, self.draft.registration_metadata)
payload = {
'schema_data': metadata,
'schema_name': 'OSF-Standard Pre-Data Collection Registration',
'schema_version': 1
}
url = self.node.api_url_for('update_draft_registration', draft_id=self.draft._id)
res = self.app.put_json(url, payload, auth=self.user.auth)
assert_equal(res.status_code, http.OK)
open_ended_schema = MetaSchema.find_one(
Q('name', 'eq', 'OSF-Standard Pre-Data Collection Registration') &
Q('schema_version', 'eq', 1)
)
self.draft.reload()
assert_equal(open_ended_schema, self.draft.registration_schema)
assert_equal(metadata, self.draft.registration_metadata)
示例3: test_required_third_level_questions_must_be_answered_on_draft
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def test_required_third_level_questions_must_be_answered_on_draft(self, mock_enqueue):
prereg_schema = MetaSchema.find_one(
Q('name', 'eq', 'Prereg Challenge') &
Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
)
prereg_draft_registration = DraftRegistrationFactory(
initiator=self.user,
registration_schema=prereg_schema,
branched_from=self.public_project
)
registration_metadata = self.prereg_metadata(prereg_draft_registration)
registration_metadata['q11'] = {'value': {"question": {}}}
prereg_draft_registration.registration_metadata = registration_metadata
prereg_draft_registration.save()
payload = {
"data": {
"type": "registrations",
"attributes": {
"registration_choice": "immediate",
"draft_registration": prereg_draft_registration._id,
}
}
}
res = self.app.post_json_api(self.url, payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 400)
assert_equal(res.json['errors'][0]['detail'], "'value' is a required property")
示例4: node_register_template_page
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def node_register_template_page(auth, node, metaschema_id, **kwargs):
if node.is_registration and bool(node.registered_schema):
try:
meta_schema = MetaSchema.find_one(
Q('_id', 'eq', metaschema_id)
)
except NoResultsFound:
# backwards compatability for old urls, lookup by name
try:
meta_schema = MetaSchema.find(
Q('name', 'eq', _id_to_name(metaschema_id))
).sort('-schema_version')[0]
except IndexError:
raise HTTPError(http.NOT_FOUND, data={
'message_short': 'Invalid schema name',
'message_long': 'No registration schema with that name could be found.'
})
if meta_schema not in node.registered_schema:
raise HTTPError(http.BAD_REQUEST, data={
'message_short': 'Invalid schema',
'message_long': 'This registration has no registration supplment with that name.'
})
ret = _view_project(node, auth, primary=True)
ret['node']['registered_schema'] = serialize_meta_schema(meta_schema)
return ret
else:
status.push_status_message(
'You have been redirected to the project\'s registrations page. From here you can initiate a new Draft Registration to complete the registration process',
trust=False
)
return redirect(node.web_url_for('node_registrations', view=kwargs.get('template')))
示例5: setUp
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def setUp(self):
super(TestRegistrationCreate, self).setUp()
ensure_schemas()
self.schema = MetaSchema.find_one(
Q('name', 'eq', 'Replication Recipe (Brandt et al., 2013): Post-Completion') &
Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
)
self.draft_registration = DraftRegistrationFactory(
initiator=self.user,
registration_schema=self.schema,
branched_from=self.public_project,
registration_metadata = {
'item29': {'value': 'Yes'},
'item33': {'value': 'success'}
}
)
self.url = '/{}nodes/{}/registrations/'.format(API_BASE, self.public_project._id)
self.payload = {
"data": {
"type": "registrations",
"attributes": {
"draft_registration": self.draft_registration._id,
"registration_choice": "immediate"
}
}
}
示例6: setUp
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def setUp(self):
super(PreregViewsTests, self).setUp()
ensure_schemas()
self.osf_user = factories.AuthUserFactory()
password = fake.password(),
self.user = User.objects.create(
email=fake.email(),
first_name=fake.first_name(),
last_name=fake.last_name(),
osf_id=self.osf_user._id
)
self.user.set_password(password)
self.user.save()
self.logged_in = self.client.login(username=self.user.email, password=password)
PREREG_GROUP.user_set.add(self.user)
PREREG_GROUP.save()
self.prereg_schema = MetaSchema.find_one(
Q('name', 'eq', 'Prereg Challenge') &
Q('schema_version', 'eq', 2)
)
self.other_schema = MetaSchema.find(
Q('name', 'ne', 'Prereg Challenge') &
Q('schema_version', 'eq', 2)
)[0]
示例7: test_required_metaschema_questions_not_required_on_post
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def test_required_metaschema_questions_not_required_on_post(self):
prereg_schema = MetaSchema.find_one(
Q("name", "eq", "Prereg Challenge") & Q("schema_version", "eq", LATEST_SCHEMA_VERSION)
)
prereg_draft_registration = DraftRegistrationFactory(
initiator=self.user, registration_schema=prereg_schema._id, branched_from=self.public_project
)
url = "/{}nodes/{}/draft_registrations/?embed=initiator&embed=branched_from".format(
API_BASE, self.public_project._id
)
registration_metadata = self.prereg_metadata(prereg_draft_registration)
del registration_metadata["q1"]
prereg_draft_registration.registration_metadata = registration_metadata
prereg_draft_registration.save()
payload = {
"data": {
"type": "draft_registrations",
"attributes": {
"registration_supplement": prereg_schema._id,
"registration_metadata": registration_metadata,
},
}
}
res = self.app.post_json_api(url, payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 201)
data = res.json["data"]
assert_equal(res.json["data"]["attributes"]["registration_metadata"]["q2"]["value"], "Test response")
assert_equal(data["attributes"]["registration_supplement"], prereg_schema._id)
assert_equal(data["embeds"]["branched_from"]["data"]["id"], self.public_project._id)
assert_equal(data["embeds"]["initiator"]["data"]["id"], self.user._id)
示例8: node_register_template_page
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def node_register_template_page(auth, node, **kwargs):
template_name = kwargs['template'].replace(' ', '_')
# Error to raise if template can't be found
not_found_error = HTTPError(
http.NOT_FOUND,
data=dict(
message_short='Template not found.',
message_long='The registration template you entered '
'in the URL is not valid.'
)
)
if node.is_registration and node.registered_meta:
registered = True
payload = node.registered_meta.get(to_mongo(template_name))
payload = json.loads(payload)
payload = unprocess_payload(payload)
if node.registered_schema:
meta_schema = node.registered_schema
else:
try:
meta_schema = MetaSchema.find_one(
Q('name', 'eq', template_name) &
Q('schema_version', 'eq', 1)
)
except NoResultsFound:
raise not_found_error
else:
# Anyone with view access can see this page if the current node is
# registered, but only admins can view the registration page if not
# TODO: Test me @jmcarp
if not node.has_permission(auth.user, ADMIN):
raise HTTPError(http.FORBIDDEN)
registered = False
payload = None
metaschema_query = MetaSchema.find(
Q('name', 'eq', template_name)
).sort('-schema_version')
if metaschema_query:
meta_schema = metaschema_query[0]
else:
raise not_found_error
schema = meta_schema.schema
# TODO: Notify if some components will not be registered
ret = {
'template_name': template_name,
'schema': json.dumps(schema),
'metadata_version': meta_schema.metadata_version,
'schema_version': meta_schema.schema_version,
'registered': registered,
'payload': payload,
'children_ids': node.nodes._to_primary_keys(),
}
ret.update(_view_project(node, auth, primary=True))
return ret
示例9: main
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def main(dry=True):
init_app(set_backends=True, routes=False)
if not dry:
scripts_utils.add_file_logger(logger, __file__)
prereg = MetaSchema.find_one(
Q('name', 'eq', "Prereg Challenge"))
migrate_drafts_q5_metadata(prereg)
migrate_registrations_q5_metadata(prereg)
示例10: main
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def main(dry=True):
init_app(set_backends=True, routes=False)
if not dry:
scripts_utils.add_file_logger(logger, __file__)
veer = MetaSchema.find_one(
Q('name', 'eq',
"Pre-Registration in Social Psychology (van 't Veer & Giner-Sorolla, 2016): Pre-Registration"))
migrate_drafts_metadata_key(veer)
migrate_registrations_metadata_key(veer)
示例11: get_prereg_schema
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def get_prereg_schema(campaign='prereg'):
from website.models import MetaSchema # noqa
if campaign not in PREREG_CAMPAIGNS:
raise ValueError('campaign must be one of: {}'.format(', '.join(PREREG_CAMPAIGNS.keys())))
schema_name = PREREG_CAMPAIGNS[campaign]
return MetaSchema.find_one(
Q('name', 'eq', schema_name) &
Q('schema_version', 'eq', 2)
)
示例12: setUp
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def setUp(self):
super(TestDraftRegistrationList, self).setUp()
ensure_schemas()
self.schema = MetaSchema.find_one(
Q("name", "eq", "Open-Ended Registration") & Q("schema_version", "eq", LATEST_SCHEMA_VERSION)
)
self.draft_registration = DraftRegistrationFactory(
initiator=self.user, registration_schema=self.schema, branched_from=self.public_project
)
self.url = "/{}nodes/{}/draft_registrations/".format(API_BASE, self.public_project._id)
示例13: setUp
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def setUp(self):
super(TestDraftRegistrationApprovals, self).setUp()
self.approval = DraftRegistrationApproval(initiated_by=self.user, meta={"registration_choice": "immediate"})
self.authorizer1 = AuthUserFactory()
self.authorizer2 = AuthUserFactory()
for authorizer in [self.authorizer1, self.authorizer2]:
self.approval.add_authorizer(authorizer)
self.approval.save()
self.draft.registration_schema = MetaSchema.find_one(
Q("name", "eq", "Prereg Challenge") & Q("schema_version", "eq", 2)
)
self.draft.approval = self.approval
self.draft.save()
示例14: setUp
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def setUp(self):
super(RegistrationsTestBase, self).setUp()
self.user = AuthUserFactory()
self.auth = Auth(self.user)
self.node = ProjectFactory(creator=self.user)
self.non_admin = AuthUserFactory()
self.node.add_contributor(
self.non_admin,
permissions.DEFAULT_CONTRIBUTOR_PERMISSIONS,
auth=self.auth,
save=True
)
self.non_contrib = AuthUserFactory()
MetaSchema.remove()
ensure_schemas()
self.meta_schema = MetaSchema.find_one(
Q('name', 'eq', 'Open-Ended Registration') &
Q('schema_version', 'eq', 2)
)
self.draft = DraftRegistrationFactory(
initiator=self.user,
branched_from=self.node,
registration_schema=self.meta_schema,
registration_metadata={
'summary': {'value': 'Some airy'}
}
)
current_month = dt.datetime.now().strftime("%B")
current_year = dt.datetime.now().strftime("%Y")
valid_date = dt.datetime.now() + dt.timedelta(days=180)
self.embargo_payload = {
u'embargoEndDate': unicode(valid_date.strftime('%a, %d, %B %Y %H:%M:%S')) + u' GMT',
u'registrationChoice': 'embargo'
}
self.invalid_embargo_date_payload = {
u'embargoEndDate': u"Thu, 01 {month} {year} 05:00:00 GMT".format(
month=current_month,
year=str(int(current_year) - 1)
),
u'registrationChoice': 'embargo'
}
self.immediate_payload = {
'registrationChoice': 'immediate'
}
self.invalid_payload = {
'registrationChoice': 'foobar'
}
示例15: setUp
# 需要導入模塊: from website.models import MetaSchema [as 別名]
# 或者: from website.models.MetaSchema import find_one [as 別名]
def setUp(self):
super(TestSearchSerializer, self).setUp()
self.user = AuthUserFactory()
self.project = ProjectFactory(creator=self.user, is_public=True)
self.component = NodeFactory(parent=self.project, creator=self.user, is_public=True)
self.file = utils.create_test_file(self.component, self.user)
ensure_schemas()
self.schema = MetaSchema.find_one(
Q('name', 'eq', 'Replication Recipe (Brandt et al., 2013): Post-Completion') &
Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
)
with mock_archive(self.project, autocomplete=True, autoapprove=True, schema=self.schema) as registration:
self.registration = registration