本文整理汇总了Python中onadata.apps.main.models.MetaData.crowdform_users方法的典型用法代码示例。如果您正苦于以下问题:Python MetaData.crowdform_users方法的具体用法?Python MetaData.crowdform_users怎么用?Python MetaData.crowdform_users使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类onadata.apps.main.models.MetaData
的用法示例。
在下文中一共展示了MetaData.crowdform_users方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_user_add_crowdform_duplicate_entry
# 需要导入模块: from onadata.apps.main.models import MetaData [as 别名]
# 或者: from onadata.apps.main.models.MetaData import crowdform_users [as 别名]
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)
示例2: auto_add_crowd_form_to_registered_user
# 需要导入模块: from onadata.apps.main.models import MetaData [as 别名]
# 或者: from onadata.apps.main.models.MetaData import crowdform_users [as 别名]
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
示例3: test_crowdform_for_new_user
# 需要导入模块: from onadata.apps.main.models import MetaData [as 别名]
# 或者: from onadata.apps.main.models.MetaData import crowdform_users [as 别名]
def test_crowdform_for_new_user(self):
# initial
meta = MetaData.crowdform_users(self.xform)
self.assertEqual(len(meta), 0)
#save settings to be restored later
old_auto_add_cf = settings.AUTO_ADD_CROWDFORM
old_default_cf = settings.DEFAULT_CROWDFORM
# enable auto add crowdform
settings.AUTO_ADD_CROWDFORM = True
settings.DEFAULT_CROWDFORM = {
'xform_username': self.user.username,
'xform_id_string': self.xform.id_string}
# register new user
post_data = {
'username': self.alice,
'email': '[email protected]',
'password1': 'bobbob',
'password2': 'bobbob',
'name': 'Alice',
'city': 'Ecila',
'country': 'US',
'organization': 'Alic Inc.',
'home_page': 'alice.com',
'twitter': 'alicerama'
}
url = '/accounts/register/'
self.response = self.client.post(url, post_data)
# check to ensure that crowd form was added
meta = MetaData.crowdform_users(self.xform)
self.assertEqual(len(meta), 1)
self.assertEqual(meta[0].data_value, self.alice)
# restore old settings
settings.AUTO_ADD_CROWDFORM = old_auto_add_cf
settings.DEFAULT_CROWDFORM = old_default_cf
示例4: edit
# 需要导入模块: from onadata.apps.main.models import MetaData [as 别名]
# 或者: from onadata.apps.main.models.MetaData import crowdform_users [as 别名]
def edit(request, username, id_string):
xform = XForm.objects.get(user__username=username, id_string=id_string)
owner = xform.user
if request.GET.get("crowdform"):
crowdform_action = request.GET["crowdform"]
request_username = request.user.username
# ensure is crowdform
if xform.is_crowd_form:
if crowdform_action == "delete":
MetaData.objects.get(
xform__id_string=id_string, data_value=request_username, data_type=MetaData.CROWDFORM_USERS
).delete()
elif crowdform_action == "add":
MetaData.crowdform_users(xform, request_username)
return HttpResponseRedirect(reverse(profile, kwargs={"username": request_username}))
if username == request.user.username or request.user.has_perm("logger.change_xform", xform):
if request.POST.get("description"):
audit = {"xform": xform.id_string}
audit_log(
Actions.FORM_UPDATED,
request.user,
owner,
_("Description for '%(id_string)s' updated from " "'%(old_description)s' to '%(new_description)s'.")
% {
"id_string": xform.id_string,
"old_description": xform.description,
"new_description": request.POST["description"],
},
audit,
request,
)
xform.description = request.POST["description"]
elif request.POST.get("title"):
audit = {"xform": xform.id_string}
audit_log(
Actions.FORM_UPDATED,
request.user,
owner,
_("Title for '%(id_string)s' updated from " "'%(old_title)s' to '%(new_title)s'.")
% {"id_string": xform.id_string, "old_title": xform.title, "new_title": request.POST.get("title")},
audit,
request,
)
xform.title = request.POST["title"]
elif request.POST.get("toggle_shared"):
if request.POST["toggle_shared"] == "data":
audit = {"xform": xform.id_string}
audit_log(
Actions.FORM_UPDATED,
request.user,
owner,
_("Data sharing updated for '%(id_string)s' from " "'%(old_shared)s' to '%(new_shared)s'.")
% {
"id_string": xform.id_string,
"old_shared": _("shared") if xform.shared_data else _("not shared"),
"new_shared": _("shared") if not xform.shared_data else _("not shared"),
},
audit,
request,
)
xform.shared_data = not xform.shared_data
elif request.POST["toggle_shared"] == "form":
audit = {"xform": xform.id_string}
audit_log(
Actions.FORM_UPDATED,
request.user,
owner,
_("Form sharing for '%(id_string)s' updated " "from '%(old_shared)s' to '%(new_shared)s'.")
% {
"id_string": xform.id_string,
"old_shared": _("shared") if xform.shared else _("not shared"),
"new_shared": _("shared") if not xform.shared else _("not shared"),
},
audit,
request,
)
xform.shared = not xform.shared
elif request.POST["toggle_shared"] == "active":
audit = {"xform": xform.id_string}
audit_log(
Actions.FORM_UPDATED,
request.user,
owner,
_("Active status for '%(id_string)s' updated from " "'%(old_shared)s' to '%(new_shared)s'.")
% {
"id_string": xform.id_string,
"old_shared": _("shared") if xform.downloadable else _("not shared"),
"new_shared": _("shared") if not xform.downloadable else _("not shared"),
},
audit,
request,
)
xform.downloadable = not xform.downloadable
elif request.POST["toggle_shared"] == "crowd":
audit = {"xform": xform.id_string}
audit_log(
#.........这里部分代码省略.........
示例5: test_user_delete_crowdform
# 需要导入模块: from onadata.apps.main.models import MetaData [as 别名]
# 或者: from onadata.apps.main.models.MetaData import crowdform_users [as 别名]
def test_user_delete_crowdform(self):
self._add_crowdform()
self.response = self.client.get(self.edit_url, {'crowdform': 'delete'})
meta = MetaData.crowdform_users(self.xform)
self.assertEqual(len(meta), 0)
self.assertEqual(self.response.status_code, 302)
示例6: test_user_add_crowdform
# 需要导入模块: from onadata.apps.main.models import MetaData [as 别名]
# 或者: from onadata.apps.main.models.MetaData import crowdform_users [as 别名]
def test_user_add_crowdform(self):
self._add_crowdform()
self.assertEqual(self.response.status_code, 302)
meta = MetaData.crowdform_users(self.xform)
self.assertEqual(len(meta), 1)
self.assertEqual(meta[0].data_value, self.alice)
示例7: _add_crowdform
# 需要导入模块: from onadata.apps.main.models import MetaData [as 别名]
# 或者: from onadata.apps.main.models.MetaData import crowdform_users [as 别名]
def _add_crowdform(self):
self._create_user_and_login(self.alice, self.alice)
self.assertEqual(len(MetaData.crowdform_users(self.xform)),
self.crowdform_count)
self.response = self.client.get(self.edit_url, {'crowdform': 'add'})
self.crowdform_count += 1