本文整理汇总了Python中anaf.core.models.Object.filter_permitted方法的典型用法代码示例。如果您正苦于以下问题:Python Object.filter_permitted方法的具体用法?Python Object.filter_permitted怎么用?Python Object.filter_permitted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anaf.core.models.Object
的用法示例。
在下文中一共展示了Object.filter_permitted方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from anaf.core.models import Object [as 别名]
# 或者: from anaf.core.models.Object import filter_permitted [as 别名]
def __init__(self, user, *args, **kwargs):
super(SubscriptionForm, self).__init__(*args, **kwargs)
del self.fields['cycle_end']
self.fields['product'].queryset = Object.filter_permitted(
user, Product.objects)
self.fields['product'].label = _("Product")
self.fields['client'].queryset = Object.filter_permitted(
user, Contact.objects)
self.fields['client'].widget.attrs.update({'class': 'autocomplete',
'callback': reverse('identities_ajax_contact_lookup')})
self.fields['client'].widget.attrs.update(
{'popuplink': reverse('identities_contact_add')})
self.fields['client'].label = _("Client")
self.fields['start'].widget.attrs.update({'class': 'datepicker'})
self.fields['start'].label = _("Start")
self.fields['expiry'].widget.attrs.update({'class': 'datepicker'})
self.fields['expiry'].label = _("Expiry")
if 'instance' in kwargs:
self.instance = kwargs['instance']
self.fields['start'].widget.attrs['readonly'] = True
del kwargs['instance']
self.fields['active'].initial = True
self.fields['active'].label = _("Active")
self.fields['cycle_period'].label = _("Cycle period")
self.fields['details'].label = _("Details")
示例2: _find_duplicates
# 需要导入模块: from anaf.core.models import Object [as 别名]
# 或者: from anaf.core.models.Object import filter_permitted [as 别名]
def _find_duplicates(resource_id, item, user):
"Finds matching items"
dups = []
item_id = None
if 'id' in item.raw:
item_id = item.id.raw
# Finding previously syncd items
if item_id:
key = '#' + unicode(resource_id) + '.' + unicode(item_id) + '#'
dups = Object.filter_permitted(user, Contact.objects).filter(
nuvius_resource__contains=key)
if dups:
return dups
# Finding equivalent items
# If name and (email or phone) are the same - it's same person
if item.name:
candidates = Object.filter_permitted(
user, Contact.objects).filter(name=item.name.raw).distinct()
dups = []
if candidates and (item.email or item.phone):
for candidate in candidates:
matching_emails = []
emails = candidate.contactvalue_set.filter(
field__field_type='email')
if item.email.raw and emails:
matching_emails = emails.filter(value__in=item.email.raw)
phones = candidate.contactvalue_set.filter(
field__field_type='phone')
matching_phones = []
if item.phone.raw and phones:
matching_phones = phones.filter(value__in=item.phone.raw)
# If anything matches or if we have no emails or no phones at
# all - add to duplicates
if matching_emails or matching_phones or (not emails and not phones):
dups.append(candidate)
elif not candidates and (item.email or item.phone):
query = Q()
if item.email:
query = query & Q(contactvalue__value__in=item.email.raw)
if item.phone:
query = query | Q(contactvalue__value__in=item.phone.raw)
dups = Object.filter_permitted(
user, Contact.objects).filter(query).distinct()
else:
dups = candidates
elif item.email or item.phone:
query = Q()
if item.email:
query = query & Q(contactvalue__value__in=item.email.raw)
if item.phone:
query = query & Q(contactvalue__value__in=item.phone.raw)
dups = Object.filter_permitted(user, Contact.objects).filter(query)
return dups
示例3: category_delete
# 需要导入模块: from anaf.core.models import Object [as 别名]
# 或者: from anaf.core.models.Object import filter_permitted [as 别名]
def category_delete(request, knowledgeCategory_id, response_format='html'):
"Knowledge Category delete"
category = get_object_or_404(KnowledgeCategory, pk=knowledgeCategory_id)
items = Object.filter_permitted(
manager=KnowledgeItem.objects, user=request.user.profile, mode='r')
if not request.user.profile.has_permission(category, mode="w"):
return user_denied(request, message="You don't have access to this Knowledge Category")
if request.POST:
if 'delete' in request.POST:
if 'trash' in request.POST:
category.trash = True
category.save()
else:
category.delete()
return HttpResponseRedirect(reverse('knowledge_index'))
elif 'cancel' in request.POST:
return HttpResponseRedirect(reverse('knowledge_category_view', args=[category.treepath]))
context = _get_default_context(request)
context.update({'category': category,
'items': items})
return render_to_response('knowledge/category_delete', context,
context_instance=RequestContext(request),
response_format=response_format)
示例4: item_add_folder
# 需要导入模块: from anaf.core.models import Object [as 别名]
# 或者: from anaf.core.models.Object import filter_permitted [as 别名]
def item_add_folder(request, folderPath, response_format='html'):
"Add new knowledge item to preselected folder"
items = Object.filter_permitted(
manager=KnowledgeItem.objects, user=request.user.profile, mode='r')
try:
folder = KnowledgeFolder.by_path(folderPath)
knowledgeType_id = folder.id
except KnowledgeFolder.DoesNotExist:
raise Http404
if request.POST:
if 'cancel' not in request.POST:
item = KnowledgeItem()
form = KnowledgeItemForm(
request.user.profile, knowledgeType_id, request.POST, instance=item)
if form.is_valid():
item = form.save()
item.set_user_from_request(request)
return HttpResponseRedirect(reverse('knowledge_item_view',
args=[item.folder.treepath, item.treepath]))
else:
return HttpResponseRedirect(reverse('knowledge'))
else:
form = KnowledgeItemForm(request.user.profile, knowledgeType_id)
context = _get_default_context(request)
context.update({'items': items,
'form': form,
'folder': folder})
return render_to_response('knowledge/item_add_folder', context,
context_instance=RequestContext(request),
response_format=response_format)
示例5: category_edit
# 需要导入模块: from anaf.core.models import Object [as 别名]
# 或者: from anaf.core.models.Object import filter_permitted [as 别名]
def category_edit(request, knowledgeCategory_id, response_format='html'):
"Knowledge category edit page"
category = get_object_or_404(KnowledgeCategory, pk=knowledgeCategory_id)
items = Object.filter_permitted(
manager=KnowledgeItem.objects, user=request.user.profile, mode='r')
if not request.user.profile.has_permission(category, mode="w"):
return user_denied(request, message="You don't have access to this Knowledge Category")
if request.POST:
if 'cancel' not in request.POST:
form = KnowledgeCategoryForm(request.POST, instance=category)
if form.is_valid():
category = form.save()
return HttpResponseRedirect(reverse('knowledge_category_view', args=[category.treepath]))
else:
return HttpResponseRedirect(reverse('knowledge_category_view', args=[category.treepath]))
else:
form = KnowledgeCategoryForm(instance=category)
context = _get_default_context(request)
context.update({'form': form,
'category': category,
'items': items})
return render_to_response('knowledge/category_edit', context,
context_instance=RequestContext(request),
response_format=response_format)
示例6: save
# 需要导入模块: from anaf.core.models import Object [as 别名]
# 或者: from anaf.core.models.Object import filter_permitted [as 别名]
def save(self, *args, **kwargs):
"Save override to omit empty fields"
if self.instance and self.is_valid():
if self.cleaned_data['stream']:
self.instance.stream = self.cleaned_data['stream']
if self.user and self.cleaned_data['mark']:
if self.cleaned_data['mark'] == 'read':
try:
self.instance.read_by.add(self.user)
except Exception:
pass
if self.cleaned_data['mark'] == 'unread':
try:
self.instance.read_by.remove(self.user)
except Exception:
pass
self.instance.save()
if self.user and self.cleaned_data['mark']:
if self.cleaned_data['mark'] == 'delete':
self.instance.delete()
if self.cleaned_data['mark'] == 'trash':
self.instance.trash = True
self.instance.save()
elif self.user and self.cleaned_data['markall']:
query = Q(reply_to__isnull=True) & ~Q(read_by=self.user)
for message in Object.filter_permitted(self.user, Message.objects.filter(query), mode='x'):
try:
message.read_by.add(self.user)
except Exception:
pass
示例7: item_edit
# 需要导入模块: from anaf.core.models import Object [as 别名]
# 或者: from anaf.core.models.Object import filter_permitted [as 别名]
def item_edit(request, knowledgeItem_id, response_format='html'):
"Knowledge item edit page"
item = get_object_or_404(KnowledgeItem, pk=knowledgeItem_id)
items = Object.filter_permitted(
manager=KnowledgeItem.objects, user=request.user.profile, mode='r')
if not request.user.profile.has_permission(item, mode="w"):
return user_denied(request, message="You don't have access to this Knowledge Item")
if request.POST:
if 'cancel' not in request.POST:
form = KnowledgeItemForm(
request.user.profile, None, request.POST, instance=item)
if form.is_valid():
item = form.save()
return HttpResponseRedirect(reverse('knowledge_item_view',
args=[item.folder.treepath, item.treepath]))
else:
return HttpResponseRedirect(reverse('knowledge_item_view',
args=[item.folder.treepath, item.treepath]))
else:
form = KnowledgeItemForm(
request.user.profile, None, instance=item)
context = _get_default_context(request)
context.update({'form': form,
'item': item,
'items': items})
return render_to_response('knowledge/item_edit', context,
context_instance=RequestContext(request),
response_format=response_format)
示例8: messaging_unread
# 需要导入模块: from anaf.core.models import Object [as 别名]
# 或者: from anaf.core.models.Object import filter_permitted [as 别名]
def messaging_unread(context):
"Print a number of unread messages"
request = context['request']
user = None
if request.user.username:
try:
user = request.user.profile
except Exception:
pass
unread = 0
messaging = None
if user:
modules = user.get_perspective().get_modules()
messaging = modules.filter(name='anaf.messaging')
if messaging:
unread = Object.filter_permitted(user,
Message.objects.filter(reply_to__isnull=True).exclude(read_by=user)).count()
response_format = 'html'
if 'response_format' in context:
response_format = context['response_format']
return Markup(render_to_string('messaging/tags/unread',
{'messaging': messaging, 'unread': unread},
context_instance=RequestContext(request),
response_format=response_format))
示例9: item_add
# 需要导入模块: from anaf.core.models import Object [as 别名]
# 或者: from anaf.core.models.Object import filter_permitted [as 别名]
def item_add(request, response_format='html'):
"Add new knowledge item"
items = Object.filter_permitted(
manager=KnowledgeItem.objects, user=request.user.profile, mode='r')
if request.POST:
if 'cancel' not in request.POST:
item = KnowledgeItem()
form = KnowledgeItemForm(
request.user.profile, None, request.POST, instance=item)
if form.is_valid():
item = form.save()
item.set_user_from_request(request)
return HttpResponseRedirect(reverse('knowledge_item_view',
args=[item.folder.treepath, item.treepath]))
else:
return HttpResponseRedirect(reverse('knowledge'))
else:
form = KnowledgeItemForm(request.user.profile, None)
context = _get_default_context(request)
context.update({'items': items,
'form': form})
return render_to_response('knowledge/item_add', context,
context_instance=RequestContext(request),
response_format=response_format)