本文整理汇总了Python中anaf.core.models.Object类的典型用法代码示例。如果您正苦于以下问题:Python Object类的具体用法?Python Object怎么用?Python Object使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Object类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index_by_status
def index_by_status(request, status_id, response_format='html'):
"""Sort tasks by status"""
status = get_object_or_404(TaskStatus, pk=status_id)
if not request.user.profile.has_permission(status):
return user_denied(request, message="You don't have access to this Task Status")
query = Q(parent__isnull=True, status=status)
if request.GET:
query = query & _get_filter_query(request.GET)
tasks = Object.filter_by_request(request, Task.objects.filter(query))
milestones = Object.filter_by_request(
request, Milestone.objects.filter(task__status=status).distinct())
filters = FilterForm(request.user.profile, 'status', request.GET)
context = _get_default_context(request)
context.update({'milestones': milestones,
'tasks': tasks,
'status': status,
'filters': filters})
return render_to_response('projects/index_by_status', context,
context_instance=RequestContext(request), response_format=response_format)
示例2: index_in_progress
def index_in_progress(request, response_format='html'):
"""A page with a list of tasks in progress"""
query = Q(parent__isnull=True)
if request.GET:
query = query & Q(
status__hidden=False) & _get_filter_query(request.GET)
else:
query = query & Q(status__hidden=False)
tasks = Object.filter_by_request(request, Task.objects.filter(query))
milestones = Object.filter_by_request(
request, Milestone.objects.filter(status__hidden=False))
filters = FilterForm(request.user.profile, 'status', request.GET)
time_slots = Object.filter_by_request(
request, TaskTimeSlot.objects.filter(time_from__isnull=False, time_to__isnull=True))
context = _get_default_context(request)
context.update({'milestones': milestones,
'tasks': tasks,
'filters': filters,
'time_slots': time_slots})
return render_to_response('projects/index_in_progress', context,
context_instance=RequestContext(request), response_format=response_format)
示例3: index_assigned
def index_assigned(request, response_format='html'):
"""Tasks assigned to current user"""
query = Q(parent__isnull=True, assigned=request.user.profile)
if request.GET:
if 'status' in request.GET and request.GET['status']:
query = query & _get_filter_query(request.GET)
else:
query = query & Q(
status__hidden=False) & _get_filter_query(request.GET)
else:
query = query & Q(status__hidden=False)
tasks = Object.filter_by_request(request, Task.objects.filter(query))
milestones = Object.filter_by_request(
request, Milestone.objects.filter(status__hidden=False))
filters = FilterForm(request.user.profile, 'assigned', request.GET)
context = _get_default_context(request)
context.update({'milestones': milestones,
'tasks': tasks,
'filters': filters})
return render_to_response('projects/index_assigned', context,
context_instance=RequestContext(request), response_format=response_format)
示例4: __init__
def __init__(self, user, skip=None, *args, **kwargs):
if skip is None:
skip = []
super(OrderFilterForm, self).__init__(*args, **kwargs)
if 'status' in skip:
del self.fields['status']
else:
self.fields['status'].queryset = Object.filter_permitted(user,
SaleStatus.objects.filter(use_sales=True))
self.fields['status'].required = False
self.fields['status'].label = _("Status")
self.fields['paid'].label = _("Payment Status")
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'].required = False
self.fields['client'].label = _("Client")
self.fields['source'].queryset = Object.filter_permitted(
user, SaleSource.objects.filter(active=True))
self.fields['source'].required = False
self.fields['source'].label = _("Source")
self.fields['assigned'].label = _("Assigned")
self.fields['assigned'].widget.attrs.update({'class': 'multicomplete',
'callback': reverse('identities_ajax_user_lookup')})
if 'assigned' in skip:
del self.fields['assigned']
else:
self.fields['assigned'].help_text = ""
示例5: get_events
def get_events(request):
"""Return a list of EventRenderers from available Tasks and Milestones"""
events = []
query = (Q(start_date__isnull=False) | Q(end_date__isnull=False)) & Q(
status__hidden=False)
tasks = Object.filter_by_request(
request, manager=Task.objects.filter(query))
for task in tasks:
if task.end_date:
event = EventRenderer(
task.name, task.start_date, task.end_date, task.get_absolute_url())
else:
event = EventRenderer(
task.name, None, task.start_date, task.get_absolute_url())
event.css_class += " projects-calendar-task"
events.append(event)
query = (Q(start_date__isnull=False) | Q(end_date__isnull=False)) & Q(
status__hidden=False)
milestones = Object.filter_by_request(
request, manager=Milestone.objects.filter(query))
for milestone in milestones:
name = " " + milestone.name
if milestone.end_date:
event = EventRenderer(name, milestone.start_date, milestone.end_date,
milestone.get_absolute_url())
else:
event = EventRenderer(
name, None, milestone.start_date, milestone.get_absolute_url())
event.css_class += " projects-calendar-milestone"
events.append(event)
return events
示例6: task_time_slot_add
def task_time_slot_add(request, task_id, response_format='html'):
"""Time slot add to preselected task"""
task = get_object_or_404(Task, pk=task_id)
if not request.user.profile.has_permission(task, mode='x'):
return user_denied(request, message="You don't have access to this Task")
if request.POST:
task_time_slot = TaskTimeSlot(
task=task, time_to=datetime.now(), user=request.user.profile)
form = TaskTimeSlotForm(
request.user.profile, task_id, request.POST, instance=task_time_slot)
if 'cancel' in request.POST:
return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
elif form.is_valid():
task_time_slot = form.save()
task_time_slot.set_user_from_request(request)
return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
else:
form = TaskTimeSlotForm(request.user.profile, task_id)
subtasks = Object.filter_by_request(
request, Task.objects.filter(parent=task))
time_slots = Object.filter_by_request(
request, TaskTimeSlot.objects.filter(task=task))
context = _get_default_context(request)
context.update({'form': form,
'task': task,
'subtasks': subtasks,
'time_slots': time_slots})
return render_to_response('projects/task_time_add', context,
context_instance=RequestContext(request), response_format=response_format)
示例7: task_delete
def task_delete(request, task_id, response_format='html'):
"""Task delete"""
task = get_object_or_404(Task, pk=task_id)
if not request.user.profile.has_permission(task, mode='w'):
return user_denied(request, message="You don't have access to this Task")
if request.POST:
if 'delete' in request.POST:
if 'trash' in request.POST:
task.trash = True
task.save()
else:
task.delete()
return HttpResponseRedirect(reverse('projects_index'))
elif 'cancel' in request.POST:
return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
subtasks = Object.filter_by_request(
request, Task.objects.filter(parent=task))
time_slots = Object.filter_by_request(
request, TaskTimeSlot.objects.filter(task=task))
context = _get_default_context(request)
context.update({'task': task,
'subtasks': subtasks,
'time_slots': time_slots})
return render_to_response('projects/task_delete', context,
context_instance=RequestContext(request), response_format=response_format)
示例8: contact_view
def contact_view(request, contact_id, attribute='', response_format='html'):
"Contact view"
contact = get_object_or_404(Contact, pk=contact_id)
if not request.user.profile.has_permission(contact):
return user_denied(request, message="You don't have access to this Contact")
types = Object.filter_by_request(
request, ContactType.objects.order_by('name'))
subcontacts = Object.filter_by_request(request, contact.child_set)
contact_values = contact.contactvalue_set.order_by('field__name')
objects = get_contact_objects(
request.user.profile, contact, preformat=True)
module = None
for key in objects:
if not attribute and objects[key]['count']:
# attribute = objects[key]['objects'].keys()[0]
module = objects[key]['module']
elif attribute in objects[key]['objects'].keys():
module = objects[key]['module']
break
return render_to_response('identities/contact_view',
{'contact': contact,
'subcontacts': subcontacts,
'objects': objects,
'current_module': module,
'attribute': attribute,
'types': types,
'contact_values': contact_values},
context_instance=RequestContext(request), response_format=response_format)
示例9: queue_delete
def queue_delete(request, queue_id, response_format='html'):
"Queue delete"
queue = get_object_or_404(TicketQueue, pk=queue_id)
if not request.user.profile.has_permission(queue, mode='w'):
return user_denied(request, message="You don't have access to this Queue")
if request.POST:
if 'delete' in request.POST:
if 'trash' in request.POST:
queue.trash = True
queue.save()
else:
queue.delete()
return HttpResponseRedirect(reverse('services_settings_view'))
elif 'cancel' in request.POST:
return HttpResponseRedirect(reverse('services_queue_view', args=[queue.id]))
query = Q(queue=queue) & Q(status__hidden=False)
tickets = Object.filter_by_request(request, Ticket.objects.filter(query))
subqueues = Object.filter_by_request(
request, TicketQueue.objects.filter(parent=queue))
context = _get_default_context(request)
context.update({'queue': queue,
'subqueues': subqueues,
'tickets': tickets})
return render_to_response('services/queue_delete', context,
context_instance=RequestContext(request), response_format=response_format)
示例10: queue_view
def queue_view(request, queue_id, response_format='html'):
"Queue view"
queue = get_object_or_404(TicketQueue, pk=queue_id)
if not request.user.profile.has_permission(queue):
return user_denied(request, message="You don't have access to this Queue")
query = Q(queue=queue)
if request.GET:
if 'status' in request.GET and request.GET['status']:
query = query & _get_filter_query(request.GET)
else:
query = query & Q(
status__hidden=False) & _get_filter_query(request.GET)
else:
query = query & Q(status__hidden=False)
tickets = Object.filter_by_request(request, Ticket.objects.filter(query))
filters = FilterForm(request.user.profile, 'queue', request.GET)
subqueues = Object.filter_by_request(
request, TicketQueue.objects.filter(parent=queue))
context = _get_default_context(request)
context.update({'queue': queue,
'subqueues': subqueues,
'filters': filters,
'tickets': tickets})
return render_to_response('services/queue_view', context,
context_instance=RequestContext(request), response_format=response_format)
示例11: _find_duplicates
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
示例12: _get_default_context
def _get_default_context(request):
"Returns default context as a dict()"
projects = Object.filter_by_request(request, Project.objects)
statuses = Object.filter_by_request(request, TaskStatus.objects)
massform = MassActionForm(request.user.profile)
context = {'projects': projects,
'statuses': statuses,
'massform': massform}
return context
示例13: contact_edit
def contact_edit(request, contact_id, response_format='html'):
"Contact edit"
contact = get_object_or_404(Contact, pk=contact_id)
if not request.user.profile.has_permission(contact, mode='w'):
return user_denied(request, message="You don't have write access to this Contact")
if request.POST:
if 'cancel' not in request.POST:
form = ContactForm(request.user.profile, contact.contact_type, request.POST,
files=request.FILES, instance=contact)
if form.is_valid():
contact = form.save(request)
return HttpResponseRedirect(reverse('identities_contact_view', args=[contact.id]))
else:
return HttpResponseRedirect(reverse('identities_contact_view', args=[contact.id]))
else:
form = ContactForm(
request.user.profile, contact.contact_type, instance=contact)
types = Object.filter_by_request(
request, ContactType.objects.order_by('name'))
return render_to_response('identities/contact_edit',
{'contact': contact,
'types': types,
'form': form},
context_instance=RequestContext(request), response_format=response_format)
示例14: settings_view
def settings_view(request, response_format='html'):
"Settings"
if not request.user.profile.is_admin('anaf.identities'):
return user_denied(request, message="You are not an Administrator of the Identities module",
response_format=response_format)
contact_types = ContactType.objects.all().filter(trash=False)
contact_fields = ContactField.objects.all().filter(trash=False)
contacts = Object.filter_by_request(
request, Contact.objects.order_by('name'))
context = _get_default_context(request)
context.update({'contact_types': contact_types,
'contact_fields': contact_fields,
'contacts': contacts})
if request.POST and 'file' in request.FILES:
csv_file = request.FILES['file']
# TODO: check file extension
content = csv_file.read()
import_c = ProcessContacts()
import_c.import_contacts(content)
return HttpResponseRedirect(reverse('identities_index'))
return render_to_response('identities/settings_view', context,
context_instance=RequestContext(request), response_format=response_format)
示例15: messaging_unread
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))