本文整理汇总了Python中onadata.apps.main.models.MetaData类的典型用法代码示例。如果您正苦于以下问题:Python MetaData类的具体用法?Python MetaData怎么用?Python MetaData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MetaData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_upload_source_file_keep_name
def test_upload_source_file_keep_name(self):
desc = 'Snooky'
response = self.client.post(self.edit_url, {'source': desc},
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(response.status_code, 200)
self._add_metadata('source')
self.assertNotEqual(MetaData.source(self.xform).data_file, None)
self.assertEqual(MetaData.source(self.xform).data_value, desc)
示例2: test_user_add_crowdform_duplicate_entry
def test_user_add_crowdform_duplicate_entry(self):
self._add_crowdform()
self.assertEqual(self.response.status_code, 302)
meta = MetaData.crowdform_users(self.xform)
self.assertEqual(len(meta), 1)
self._add_crowdform()
meta = MetaData.crowdform_users(self.xform)
self.assertEqual(len(meta), 1)
示例3: test_metadata_file_hash
def test_metadata_file_hash(self):
self._publish_transportation_form()
src = os.path.join(self.this_directory, "fixtures",
"transportation", "screenshot.png")
uf = UploadedFile(file=open(src), content_type='image/png')
count = MetaData.objects.count()
MetaData.media_upload(self.xform, uf)
# assert successful insert of new metadata record
self.assertEqual(MetaData.objects.count(), count + 1)
md = MetaData.objects.get(xform=self.xform,
data_value='screenshot.png')
# assert checksum string has been generated, hash length > 1
self.assertTrue(len(md.hash) > 16)
示例4: handle
def handle(self, *args, **kwargs):
cursor = connection.cursor()
cursor.execute(
'SELECT uid FROM kpi_asset WHERE asset_type=%s', ['survey'])
rs = cursor.cursor.fetchall()
uids = [a[0] for a in rs]
xforms = XForm.objects.filter(id_string__in=uids)
for x in xforms:
MetaData.published_by_formbuilder(x, 'True')
self.stdout.write(
"Done creating published_by_formbuilder metadata!!!"
)
示例5: test_retrieve_xform_manifest_linked_form
def test_retrieve_xform_manifest_linked_form(self):
# for linked forms check if manifest media download url for csv
# has a group_delimiter param
data_type = 'media'
data_value = 'xform {} transportation'.format(self.xform.pk)
media = self._add_form_metadata(self.xform, data_type, data_value)
self.view = XFormListViewSet.as_view(
{
"get": "manifest",
"head": "manifest"
}
)
# sign in bob
request = self.factory.head('/')
auth_response = self.view(request, pk=self.xform.pk)
auth = DigestAuth('bob', 'bobbob')
# set up bob's request
request = self.factory.get('/xformsManifest')
request.META.update(auth(request.META, auth_response))
# make request
response = self.view(request, pk=self.xform.pk, format='csv')
# test
manifest_media_url = '{}{}'.format(
media.data['media_url'],
'?group_delimiter=.&repeat_index_tags=_,_')
download_url = response.data[0]['downloadUrl']
self.assertEqual(manifest_media_url, download_url)
url = '/bob/xformsMedia/{}/{}.csv?group_delimiter=.'\
.format(self.xform.pk, self.metadata.pk)
username = 'bob'
password = 'bob'
client = DigestClient()
client.set_authorization(username, password, 'Digest')
req = client.get(url)
self.assertEqual(req.status_code, 200)
# enable meta perms
data_value = "editor-minor|dataentry"
MetaData.xform_meta_permission(self.xform, data_value=data_value)
req = client.get(url)
self.assertEqual(req.status_code, 401)
示例6: test_private_set_link_to_share_toggle_off
def test_private_set_link_to_share_toggle_off(self):
response = self.client.post(self.perm_url, {'for_user': 'toggle',
'perm_type': 'link'})
self.assertEqual(MetaData.public_link(self.xform), True)
response = self.anon.get(self.show_url)
self.assertRedirects(response, self.show_normal_url)
response = self.client.post(self.perm_url, {'for_user': 'none',
'perm_type': 'link'})
self.assertEqual(MetaData.public_link(self.xform), False)
response = self.anon.get(self.show_url)
# follow redirect
response = self.anon.get(response['Location'])
self.assertEqual(response.status_code, 302)
self.assertNotEqual(response['Location'],
'%s%s' % (self.base_url, self.show_normal_url))
示例7: test_public_with_link_to_share_toggle_on
def test_public_with_link_to_share_toggle_on(self):
# sharing behavior as of 09/13/2012:
# it requires both data_share and form_share both turned on
# in order to grant anon access to form uploading
# TODO: findout 'for_user': 'all' and what it means
response = self.client.post(
self.perm_url, {"for_user": "all", "perm_type": "link"}
)
self.assertEqual(response.status_code, 302)
self.assertEqual(MetaData.public_link(self.xform), True)
# toggle shared on
self.xform.shared = True
self.xform.shared_data = True
self.xform.save()
response = self.anon.get(self.show_url)
self.assertEqual(response.status_code, 302)
if not self._running_enketo():
raise SkipTest
with HTTMock(enketo_mock):
factory = RequestFactory()
request = factory.get("/")
request.user = AnonymousUser()
response = enter_data(
request, self.user.username, self.xform.id_string
)
self.assertEqual(response.status_code, 302)
示例8: xformsManifest
def xformsManifest(request, username, id_string): # pylint: disable=C0103
"""
XFormManifest view, part of OpenRosa Form Discovery API 1.0.
"""
xform_kwargs = {
'id_string__iexact': id_string,
'user__username__iexact': username
}
xform = get_form(xform_kwargs)
formlist_user = xform.user
profile, __ = UserProfile.objects.get_or_create(user=formlist_user)
if profile.require_auth:
authenticator = HttpDigestAuthenticator()
if not authenticator.authenticate(request):
return authenticator.build_challenge_response()
response = render(
request,
"xformsManifest.xml", {
'host':
request.build_absolute_uri().replace(request.get_full_path(), ''),
'media_files':
MetaData.media_upload(xform, download=True)
},
content_type="text/xml; charset=utf-8")
response['X-OpenRosa-Version'] = '1.0'
response['Date'] = datetime.now(pytz.timezone(settings.TIME_ZONE))\
.strftime('%a, %d %b %Y %H:%M:%S %Z')
return response
示例9: test_public_with_link_to_share
def test_public_with_link_to_share(self):
response = self.client.post(self.perm_url, {
'for_user': 'all', 'perm_type': 'link'})
self.assertEqual(response.status_code, 302)
self.assertEqual(MetaData.public_link(self.xform), True)
response = self.anon.get(self.show_url)
self.assertRedirects(response, self.show_normal_url)
示例10: xformsManifest
def xformsManifest(request, username, id_string):
xform = get_object_or_404(XForm, id_string__exact=id_string, user__username__iexact=username)
formlist_user = xform.user
profile, created = UserProfile.objects.get_or_create(user=formlist_user)
if profile.require_auth:
authenticator = HttpDigestAuthenticator()
if not authenticator.authenticate(request):
return authenticator.build_challenge_response()
response = render(
request,
"xformsManifest.xml",
{
"host": request.build_absolute_uri().replace(request.get_full_path(), ""),
"media_files": MetaData.media_upload(xform, download=True),
},
content_type="text/xml; charset=utf-8",
)
response["X-OpenRosa-Version"] = "1.0"
tz = pytz.timezone(settings.TIME_ZONE)
dt = datetime.now(tz).strftime("%a, %d %b %Y %H:%M:%S %Z")
response["Date"] = dt
return response
示例11: show
def show(request, username=None, id_string=None, uuid=None):
if uuid:
xform = get_object_or_404(XForm, uuid=uuid)
request.session["public_link"] = xform.uuid if MetaData.public_link(xform) else False
return HttpResponseRedirect(
reverse(show, kwargs={"username": xform.user.username, "id_string": xform.id_string})
)
xform, is_owner, can_edit, can_view = get_xform_and_perms(username, id_string, request)
# no access
if not (xform.shared or can_view or request.session.get("public_link")):
return HttpResponseRedirect(reverse(home))
context = RequestContext(request)
context.cloned = (
len(XForm.objects.filter(user__username=request.user.username, id_string=id_string + XForm.CLONED_SUFFIX)) > 0
)
context.public_link = MetaData.public_link(xform)
context.is_owner = is_owner
context.can_edit = can_edit
context.can_view = can_view or request.session.get("public_link")
context.xform = xform
context.content_user = xform.user
context.base_url = "https://%s" % request.get_host()
context.source = MetaData.source(xform)
context.form_license = MetaData.form_license(xform).data_value
context.data_license = MetaData.data_license(xform).data_value
context.supporting_docs = MetaData.supporting_docs(xform)
context.media_upload = MetaData.media_upload(xform)
context.mapbox_layer = MetaData.mapbox_layer_upload(xform)
if is_owner:
context.sms_support_form = ActivateSMSSupportFom(
initial={"enable_sms_support": xform.allows_sms, "sms_id_string": xform.sms_id_string}
)
if not xform.allows_sms:
context.sms_compatible = check_form_sms_compatibility(None, json_survey=json.loads(xform.json))
else:
url_root = request.build_absolute_uri("/")[:-1]
context.sms_providers_doc = providers_doc(url_root=url_root, username=username, id_string=id_string)
context.url_root = url_root
context.form_license_form = FormLicenseForm(initial={"value": context.form_license})
context.data_license_form = DataLicenseForm(initial={"value": context.data_license})
context.doc_form = SupportDocForm()
context.source_form = SourceForm()
context.media_form = MediaForm()
context.mapbox_layer_form = MapboxLayerForm()
users_with_perms = []
for perm in get_users_with_perms(xform, attach_perms=True).items():
has_perm = []
if "change_xform" in perm[1]:
has_perm.append(_(u"Can Edit"))
if "view_xform" in perm[1]:
has_perm.append(_(u"Can View"))
users_with_perms.append((perm[0], u" | ".join(has_perm)))
context.users_with_perms = users_with_perms
context.permission_form = PermissionForm(username)
if xform.allows_sms:
context.sms_support_doc = get_autodoc_for(xform)
return render_to_response("show.html", context_instance=context)
示例12: test_windows_csv_file_upload
def test_windows_csv_file_upload(self):
count = MetaData.objects.filter(data_type='media').count()
media_file = os.path.join(
self.this_directory, 'fixtures', 'transportation',
'transportation.csv')
f = InMemoryUploadedFile(open(media_file),
'media',
'transportation.csv',
'application/octet-stream',
2625,
None)
MetaData.media_upload(self.xform, f)
media_list = MetaData.objects.filter(data_type='media')
new_count = media_list.count()
self.assertEqual(count + 1, new_count)
media = media_list.get(data_value='transportation.csv')
self.assertEqual(media.data_file_type, 'text/csv')
示例13: redirect_to_public_link
def redirect_to_public_link(request, uuid):
xform = get_object_or_404(XForm, uuid=uuid)
request.session['public_link'] = \
xform.uuid if MetaData.public_link(xform) else False
return HttpResponseRedirect(reverse(show, kwargs={
'username': xform.user.username,
'id_string': xform.id_string
}))
示例14: test_public_with_link_to_share_toggle_on
def test_public_with_link_to_share_toggle_on(self):
response = self.client.post(self.perm_url, {'for_user': 'toggle',
'perm_type': 'link'})
self.assertEqual(response.status_code, 302)
self.assertEqual(MetaData.public_link(self.xform), True)
response = self.anon.get(self.show_url)
self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'],
'%s%s' % (self.base_url, self.show_normal_url))
response = self.anon.get(self.show_normal_url)
self.assertEqual(response.status_code, 200)
示例15: auto_add_crowd_form_to_registered_user
def auto_add_crowd_form_to_registered_user(sender, **kwargs):
new_user = kwargs.get("user")
if (
hasattr(settings, "AUTO_ADD_CROWDFORM")
and settings.AUTO_ADD_CROWDFORM
and hasattr(settings, "DEFAULT_CROWDFORM")
):
try:
default_crowdform = settings.DEFAULT_CROWDFORM
if (
isinstance(default_crowdform, dict)
and "xform_username" in default_crowdform
and "xform_id_string" in default_crowdform
):
xform = XForm.objects.get(
id_string=default_crowdform["xform_id_string"], user__username=default_crowdform["xform_username"]
)
MetaData.crowdform_users(xform, new_user.username)
except XForm.DoesNotExist:
pass