当前位置: 首页>>代码示例>>Python>>正文


Python models.MetaData类代码示例

本文整理汇总了Python中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)
     name = self._add_metadata("source")
     self.assertNotEqual(MetaData.source(self.xform).data_file, None)
     self.assertEqual(MetaData.source(self.xform).data_value, desc)
开发者ID:GeoODK,项目名称:formhub,代码行数:7,代码来源:test_form_metadata.py

示例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)
开发者ID:KeithDoyle,项目名称:formhub,代码行数:8,代码来源:test_crowdforms.py

示例3: 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.assertEqual(response.status_code, 302)
     self.assertEqual(response["Location"], "%s%s" % (self.base_url, 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))
开发者ID:GeoODK,项目名称:formhub,代码行数:13,代码来源:test_form_permissions.py

示例4: edit

def edit(request, username, id_string):
    xform = XForm.objects.get(user__username=username, id_string=id_string)
    if username == request.user.username or\
            request.user.has_perm('odk_logger.change_xform', xform):
        if request.POST.get('description'):
            xform.description = request.POST['description']
        elif request.POST.get('title'):
            xform.title = request.POST['title']
        elif request.POST.get('toggle_shared'):
            if request.POST['toggle_shared'] == 'data':
                xform.shared_data = not xform.shared_data
            elif request.POST['toggle_shared'] == 'form':
                xform.shared = not xform.shared
            elif request.POST['toggle_shared'] == 'active':
                xform.downloadable = not xform.downloadable
        elif request.POST.get('form-license'):
            MetaData.form_license(xform, request.POST['form-license'])
        elif request.POST.get('data-license'):
            MetaData.data_license(xform, request.POST['data-license'])
        elif request.POST.get('source') or request.FILES.get('source'):
            MetaData.source(xform, request.POST.get('source'),
                request.FILES.get('source'))
        elif request.FILES:
            MetaData.supporting_docs(xform, request.FILES['doc'])
        xform.update()
        if request.is_ajax():
            return HttpResponse('Updated succeeded.')
        else:
            return HttpResponseRedirect(reverse(show, kwargs={
                        'username': username,
                        'id_string': id_string
                        }))
    return HttpResponseForbidden('Update failed.')
开发者ID:TomCoder,项目名称:formhub,代码行数:33,代码来源:views.py

示例5: 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
开发者ID:tremolo,项目名称:formhub,代码行数:16,代码来源:views.py

示例6: 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.assertEqual(response.status_code, 302)
     self.assertEqual(response["Location"], "%s%s" % (self.base_url, self.show_normal_url))
开发者ID:GeoODK,项目名称:formhub,代码行数:7,代码来源:test_form_permissions.py

示例7: map_view

def map_view(request, username, id_string):
    owner = get_object_or_404(User, username=username)
    xform = get_object_or_404(XForm, id_string=id_string, user=owner)
    if not has_permission(xform, owner, request):
        return HttpResponseForbidden(_(u"Not shared."))
    context = RequestContext(request)
    context.content_user = owner
    context.xform = xform
    context.profile, created = UserProfile.objects.get_or_create(user=owner)
    points = ParsedInstance.objects.values("lat", "lng", "instance").filter(
        instance__user=owner, instance__xform__id_string=id_string, lat__isnull=False, lng__isnull=False
    )
    center = {
        "lat": round_down_geopoint(average([p["lat"] for p in points])),
        "lng": round_down_geopoint(average([p["lng"] for p in points])),
    }

    def round_down_point(p):
        return {"lat": round_down_geopoint(p["lat"]), "lng": round_down_geopoint(p["lng"]), "instance": p["instance"]}

    context.center = json.dumps(center)
    context.form_view = True
    context.jsonform_url = reverse(download_jsonform, kwargs={"username": username, "id_string": id_string})
    context.mongo_api_url = reverse(main.views.api, kwargs={"username": username, "id_string": id_string})
    context.mapbox_layer = MetaData.mapbox_layer_upload(xform)
    return render_to_response("map.html", context_instance=context)
开发者ID:Nuredin,项目名称:formhub,代码行数:26,代码来源:views.py

示例8: formList

def formList(request, username):
    render_formlist = False
    formlist_user = get_object_or_404(User, username=username)
    profile, created = UserProfile.objects.get_or_create(user=formlist_user)
    if profile.require_auth:
        # source, http://djangosnippets.org/snippets/243/
        if 'HTTP_AUTHORIZATION' in request.META:
            auth = request.META['HTTP_AUTHORIZATION'].split()
            # NOTE: We are only support BASIC authentication for now.
            if len(auth) == 2 and auth[0].lower() == "basic":
                uname, passwd = base64.b64decode(auth[1]).split(':')
                # ensure listing this user's forms
                if formlist_user.username == uname:
                    user = authenticate(username=uname, password=passwd)
                    if user is not None and user.is_active:
                        render_formlist = True
    else:
        render_formlist = True
    if render_formlist:
        """This is where ODK Collect gets its download list."""
        xforms = XForm.objects.filter(downloadable=True, user__username=username)
        urls = [
            {'url': request.build_absolute_uri(xform.url()), 'text': xform.title
            , 'media': {'m': MetaData.media_upload(xform), 'user': xform.user, 
            'id': xform.id_string}}
            for xform in xforms
        ]
        return render_to_response("formList.xml", {'urls': urls, 'host': 
                        'http://%s' % request.get_host()}, mimetype="text/xml")
    return HttpResponseNotAuthorized('Must be logged in')
开发者ID:asseym,项目名称:formhub,代码行数:30,代码来源:views.py

示例9: 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)
开发者ID:vernondcole,项目名称:formhub,代码行数:57,代码来源:views.py

示例10: 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.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'],
             '%s%s' % (self.base_url, 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))
开发者ID:larryweya,项目名称:formhub,代码行数:17,代码来源:test_form_permissions.py

示例11: 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)
     md.data_file.storage.delete(md.data_file.name)
     md = MetaData.objects.get(xform=self.xform,
                               data_value='screenshot.png')
     self.assertEqual(len(md.hash), 0)
开发者ID:geoffreymuchai,项目名称:onadata,代码行数:17,代码来源:test_process.py

示例12: set_perm

def set_perm(request, username, id_string):
    xform = get_object_or_404(XForm,
                              user__username=username, id_string=id_string)
    try:
        perm_type = request.POST['perm_type']
        for_user = request.POST['for_user']
    except KeyError:
        return HttpResponseBadRequest()
    if perm_type in ['edit', 'view', 'remove']:
        user = User.objects.get(username=for_user)
        if perm_type == 'edit':
            assign('change_xform', user, xform)
        elif perm_type == 'view':
            assign('view_xform', user, xform)
        elif perm_type == 'remove':
            remove_perm('change_xform', user, xform)
            remove_perm('view_xform', user, xform)
    elif perm_type == 'link':
        if for_user == 'all':
            MetaData.public_link(xform, True)
        elif for_user == 'none':
            MetaData.public_link(xform, False)
        elif for_user == 'toggle':
            current = MetaData.public_link(xform)
            MetaData.public_link(xform, not current)
    return HttpResponseRedirect(reverse(show, kwargs={
        'username': username,
        'id_string': id_string
    }))
开发者ID:Nuredin,项目名称:formhub,代码行数:29,代码来源:views.py

示例13: set_perm

def set_perm(request, username, id_string):
    xform = get_object_or_404(XForm, user__username=username, id_string=id_string)
    try:
        perm_type = request.POST["perm_type"]
        for_user = request.POST["for_user"]
    except KeyError:
        return HttpResponseBadRequest()
    if perm_type in ["edit", "view", "remove"]:
        user = User.objects.get(username=for_user)
        if perm_type == "edit":
            assign("change_xform", user, xform)
        elif perm_type == "view":
            assign("view_xform", user, xform)
        elif perm_type == "remove":
            remove_perm("change_xform", user, xform)
            remove_perm("view_xform", user, xform)
    elif perm_type == "link":
        if for_user == "all":
            MetaData.public_link(xform, True)
        elif for_user == "none":
            MetaData.public_link(xform, False)
        elif for_user == "toggle":
            current = MetaData.public_link(xform)
            MetaData.public_link(xform, not current)
    return HttpResponseRedirect(reverse(show, kwargs={"username": username, "id_string": id_string}))
开发者ID:asseym,项目名称:formhub,代码行数:25,代码来源:views.py

示例14: 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.assertEqual(response.status_code, 302)
     self.assertEqual(response['Location'],
             '%s%s' % (self.base_url, self.show_normal_url))
开发者ID:larryweya,项目名称:formhub,代码行数:9,代码来源:test_form_permissions.py

示例15: 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': '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.assertEqual(response.status_code, 302)
     response = self.anon.get(self.url)
     self.assertEqual(response.status_code, 302)
开发者ID:TomCoder,项目名称:formhub,代码行数:9,代码来源:test_form_enter_data.py


注:本文中的main.models.MetaData类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。