def mlist_view(request, mlist_id, response_format='html'): "Mailing List view page" user = request.user.get_profile() mlist = get_object_or_404(MailingList, pk=mlist_id) if not request.user.get_profile().has_permission(mlist): return user_denied( request, message="You don't have access to this Mailing List", response_format=response_format) if request.user.get_profile().has_permission(mlist, mode='x'): if request.POST: message = Message() message.author = request.user.get_profile().get_contact() if not message.author: return user_denied( request, message= "You can't send message without a Contact Card assigned to you.", response_format=response_format) form = MessageForm(request.user.get_profile(), mlist_id, None, request.POST, instance=message) if form.is_valid(): message = form.save() message.set_user_from_request(request) message.read_by.add(user) return HttpResponseRedirect( reverse('messaging_mlist_view', args=[mlist.id])) else: form = MessageForm(request.user.get_profile(), mlist_id) else: form = None messages = Object.filter_by_request( request, Message.objects.filter(reply_to__isnull=True, mlist=mlist).order_by('-date_created')) context = _get_default_context(request) context.update({'messages': messages, 'form': form, 'mlist': mlist}) return render_to_response('messaging/mlist_view', context, context_instance=RequestContext(request), response_format=response_format)
def ticket_set_status(request, ticket_id, status_id, response_format='html'): "Ticket quick set: Status" ticket = get_object_or_404(Ticket, pk=ticket_id) if not request.user.get_profile().has_permission(ticket, mode='w'): return user_denied(request, message="You don't have access to this Ticket") status = get_object_or_404(TicketStatus, pk=status_id) if not request.user.get_profile().has_permission(status): return user_denied(request, message="You don't have access to this Ticket Status") if not ticket.status == status: ticket.status = status ticket.save() return ticket_view(request, ticket_id, response_format)
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.get_profile(), mode='r') if not request.user.get_profile().has_permission(item, mode="w"): return user_denied(request, message="You don't have access to this Knowledge Item") if request.POST: if not 'cancel' in request.POST: form = KnowledgeItemForm(request.user.get_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.get_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)
def sla_edit(request, sla_id, response_format='html'): "ServiceLevelAgreement edit" sla = get_object_or_404(ServiceLevelAgreement, pk=sla_id) if not request.user.get_profile().has_permission(sla, mode='w'): return user_denied(request, message="You don't have access to this Service Level Agreement") if request.POST: if not 'cancel' in request.POST: form = ServiceLevelAgreementForm( request.user.get_profile(), request.POST, instance=sla) if form.is_valid(): sla = form.save() return HttpResponseRedirect(reverse('services_sla_view', args=[sla.id])) else: return HttpResponseRedirect(reverse('services_sla_view', args=[sla.id])) else: form = ServiceLevelAgreementForm( request.user.get_profile(), instance=sla) context = _get_default_context(request) context.update({'sla': sla, 'form': form}) return render_to_response('services/sla_edit', context, context_instance=RequestContext(request), response_format=response_format)
def queue_delete(request, queue_id, response_format='html'): "Queue delete" queue = get_object_or_404(TicketQueue, pk=queue_id) if not request.user.get_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)
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.get_profile(), mode='r') if not request.user.get_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)
def folder_view(request, folderPath, response_format='html'): "Single knowledge folder view page" folder = KnowledgeFolder.by_path(folderPath) if not folder: raise Http404 if not request.user.get_profile().has_permission(folder): return user_denied( request, message="You don't have access to this Knowledge Type") items = Object.filter_by_request( request, manager=KnowledgeItem.objects.filter(folder=folder)) subfolders = KnowledgeFolder.objects.filter(parent=folder) context = _get_default_context(request) context.update({ 'items': items, 'folder': folder, 'subfolders': subfolders }) return render_to_response('knowledge/folder_view', context, context_instance=RequestContext(request), response_format=response_format)
def location_edit(request, location_id, response_format='html'): "Location edit page" location = get_object_or_404(Location, pk=location_id) if not request.user.get_profile().has_permission(location, mode="w"): return user_denied(request, message="You don't have write access to this Location", response_format=response_format) if request.POST: if not 'cancel' in request.POST: form = LocationForm( request.user.get_profile(), None, request.POST, instance=location) if form.is_valid(): location = form.save(request) return HttpResponseRedirect(reverse('infrastructure_location_view', args=[location.id])) else: return HttpResponseRedirect(reverse('infrastructure_location_view', args=[location.id])) else: form = LocationForm( request.user.get_profile(), None, instance=location) context = _get_default_context(request) context.update({'location': location, 'form': form}) return render_to_response('infrastructure/location_edit', context, context_instance=RequestContext(request), response_format=response_format)
def sla_add(request, response_format='html'): "ServiceLevelAgreement add" if not request.user.get_profile().is_admin('treeio.services'): return user_denied( request, message= "You don't have administrator access to the Service Support module" ) if request.POST: if not 'cancel' in request.POST: sla = ServiceLevelAgreement() form = ServiceLevelAgreementForm(request.user.get_profile(), request.POST, instance=sla) if form.is_valid(): sla = form.save() sla.set_user_from_request(request) return HttpResponseRedirect( reverse('services_sla_view', args=[sla.id])) else: return HttpResponseRedirect(reverse('services')) else: form = ServiceLevelAgreementForm(request.user.get_profile()) context = _get_default_context(request) context.update({'form': form}) return render_to_response('services/sla_add', context, context_instance=RequestContext(request), response_format=response_format)
def sla_delete(request, sla_id, response_format='html'): "ServiceLevelAgreement delete" sla = get_object_or_404(ServiceLevelAgreement, pk=sla_id) if not request.user.get_profile().has_permission(sla, mode='w'): return user_denied( request, message="You don't have access to this Service Level Agreement") if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: sla.trash = True sla.save() else: sla.delete() return HttpResponseRedirect(reverse('services_sla_index')) elif 'cancel' in request.POST: return HttpResponseRedirect( reverse('services_sla_view', args=[sla.id])) context = _get_default_context(request) context.update({'sla': sla}) return render_to_response('services/sla_delete', context, context_instance=RequestContext(request), response_format=response_format)
def sla_edit(request, sla_id, response_format='html'): "ServiceLevelAgreement edit" sla = get_object_or_404(ServiceLevelAgreement, pk=sla_id) if not request.user.get_profile().has_permission(sla, mode='w'): return user_denied( request, message="You don't have access to this Service Level Agreement") if request.POST: if not 'cancel' in request.POST: form = ServiceLevelAgreementForm(request.user.get_profile(), request.POST, instance=sla) if form.is_valid(): sla = form.save() return HttpResponseRedirect( reverse('services_sla_view', args=[sla.id])) else: return HttpResponseRedirect( reverse('services_sla_view', args=[sla.id])) else: form = ServiceLevelAgreementForm(request.user.get_profile(), instance=sla) context = _get_default_context(request) context.update({'sla': sla, 'form': form}) return render_to_response('services/sla_edit', context, context_instance=RequestContext(request), response_format=response_format)
def service_delete(request, service_id, response_format='html'): "Service delete" service = get_object_or_404(Service, pk=service_id) if not request.user.get_profile().has_permission(service, mode='w') \ and not request.user.get_profile().is_admin('treeio_services'): return user_denied(request, message="You don't have access to this Service") if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: service.trash = True service.save() else: service.delete() return HttpResponseRedirect(reverse('services_service_catalogue')) elif 'cancel' in request.POST: return HttpResponseRedirect( reverse('services_service_view', args=[service.id])) context = _get_default_context(request) context.update({'service': service}) return render_to_response('services/service_delete', context, context_instance=RequestContext(request), response_format=response_format)
def service_edit(request, service_id, response_format='html'): "Service edit" service = get_object_or_404(Service, pk=service_id) if not request.user.get_profile().has_permission(service, mode='w') \ and not request.user.get_profile().is_admin('treeio_services'): return user_denied(request, message="You don't have access to this Service") if request.POST: if not 'cancel' in request.POST: form = ServiceForm(request.user.get_profile(), request.POST, instance=service) if form.is_valid(): service = form.save() return HttpResponseRedirect( reverse('services_service_view', args=[service.id])) else: return HttpResponseRedirect( reverse('services_service_view', args=[service.id])) else: form = ServiceForm(request.user.get_profile(), instance=service) context = _get_default_context(request) context.update({'form': form, 'service': service}) return render_to_response('services/service_edit', context, context_instance=RequestContext(request), response_format=response_format)
def ticket_delete(request, ticket_id, response_format='html'): "Ticket delete" ticket = get_object_or_404(Ticket, pk=ticket_id) if not request.user.get_profile().has_permission(ticket, mode='w'): return user_denied(request, message="You don't have access to this Ticket") if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: ticket.trash = True ticket.save() else: ticket.delete() return HttpResponseRedirect(reverse('services_index')) elif 'cancel' in request.POST: return HttpResponseRedirect( reverse('services_ticket_view', args=[ticket.id])) context = _get_default_context(request) context.update({'ticket': ticket}) return render_to_response('services/ticket_delete', context, context_instance=RequestContext(request), response_format=response_format)
def queue_add(request, response_format='html'): "Queue add" if not request.user.get_profile().is_admin('treeio.services'): return user_denied( request, message= "You don't have administrator access to the Service Support module" ) if request.POST: if not 'cancel' in request.POST: queue = TicketQueue() form = QueueForm(request.user.get_profile(), request.POST, instance=queue) if form.is_valid(): queue = form.save() queue.set_user_from_request(request) return HttpResponseRedirect( reverse('services_queue_view', args=[queue.id])) else: return HttpResponseRedirect(reverse('services_settings_view')) else: form = QueueForm(request.user.get_profile()) context = _get_default_context(request) context.update({'form': form}) return render_to_response('services/queue_add', context, context_instance=RequestContext(request), response_format=response_format)
def status_edit(request, status_id, response_format='html'): "ItemStatus edit" item_status = get_object_or_404(ItemStatus, pk=status_id) if not request.user.get_profile().has_permission(item_status, mode='w'): return user_denied(request, message="You don't have access to this Item Status", response_format=response_format) if request.POST: if not 'cancel' in request.POST: form = ItemStatusForm(request.POST, instance=item_status) if form.is_valid(): item_status = form.save(request) return HttpResponseRedirect(reverse('infrastructure_status_view', args=[item_status.id])) else: return HttpResponseRedirect(reverse('infrastructure_status_view', args=[item_status.id])) else: form = ItemStatusForm(instance=item_status) context = _get_default_context(request) context.update({'item_status': item_status, 'form': form}) return render_to_response('infrastructure/item_status_edit', context, context_instance=RequestContext(request), response_format=response_format)
def item_add_typed(request, type_id, response_format='html'): "Item add with preselected type" item_type = get_object_or_404(ItemType, pk=type_id) if not request.user.get_profile().has_permission(item_type, mode='x'): return user_denied(request, message="You don't have access to create " + unicode(item_type), response_format=response_format) if request.POST: if not 'cancel' in request.POST: form = ItemForm( request.user.get_profile(), item_type, request.POST, files=request.FILES) if form.is_valid(): item = form.save(request) return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id])) else: return HttpResponseRedirect(reverse('infrastructure_index')) else: form = ItemForm(request.user.get_profile(), item_type) context = _get_default_context(request) context.update({'item_type': item_type, 'form': form}) return render_to_response('infrastructure/item_add_typed', context, context_instance=RequestContext(request), response_format=response_format)
def event_edit(request, event_id, response_format='html'): "Event edit" event = get_object_or_404(Event, pk=event_id) if not request.user.get_profile().has_permission(event, mode='w'): return user_denied(request, message="You don't have access to this Event") if request.POST: if not 'cancel' in request.POST: form = EventForm(request.user.get_profile(), None, None, request.POST, instance=event) if form.is_valid(): event = form.save() return HttpResponseRedirect( reverse('events_event_view', args=[event.id])) else: return HttpResponseRedirect(reverse('events')) else: form = EventForm(request.user.get_profile(), instance=event) return render_to_response('events/event_edit', { 'event': event, 'form': form }, context_instance=RequestContext(request), response_format=response_format)
def service_record_add(request, response_format='html'): "New service_record form" if not request.user.get_profile().is_admin('treeio.infrastructure'): return user_denied(request, message="You don't have administrator access to the Infrastructure module") service_record = ItemServicing() if request.POST: if not 'cancel' in request.POST: form = ServiceRecordForm( request.user.get_profile(), service_record, request.POST) if form.is_valid(): record = form.save(request) return HttpResponseRedirect(reverse('infrastructure_service_record_view', args=[record.id])) else: return HttpResponseRedirect(reverse('infrastructure_service_record_index')) else: form = ServiceRecordForm(request.user.get_profile(), service_record) context = _get_default_context(request) context.update({'service_record': service_record, 'form': form}) return render_to_response('infrastructure/service_record_add', context, context_instance=RequestContext(request), response_format=response_format)
def status_view(request, status_id, response_format='html'): "Status view" status = get_object_or_404(ChangeSetStatus, pk=status_id) if not request.user.get_profile().has_permission(status) \ and not request.user.get_profile().is_admin('treeio.changes'): return user_denied(request, "You don't have access to this Change Set Status.", response_format=response_format) query = Q( object__in=Object.filter_by_request(request, Object.objects)) & Q( status=status) if request.GET: query = query & _get_filter_query(request.GET) filters = FilterForm(request.user.get_profile(), 'status', request.GET) else: filters = FilterForm(request.user.get_profile(), 'status') changesets = ChangeSet.objects.filter(query) context = _get_default_context(request) context.update({ 'status': status, 'changesets': changesets, 'filters': filters }) return render_to_response('changes/status_view', context, context_instance=RequestContext(request), response_format=response_format)
def item_view(request, folderPath, itemPath, response_format='html'): "Single knowledge item view page" try: item = KnowledgeItem.by_path(folderPath, itemPath) except KnowledgeItem.DoesNotExist: raise Http404 if not item: raise Http404 items = Object.filter_permitted(manager=KnowledgeItem.objects, user=request.user.get_profile(), mode='r') if not request.user.get_profile().has_permission(item): return user_denied( request, message="You don't have access to this Knowledge Item") context = _get_default_context(request) context.update({'items': items, 'item': item}) return render_to_response('knowledge/item_view', context, context_instance=RequestContext(request), response_format=response_format)
def set_edit(request, set_id, response_format='html'): "ChangeSet edit" changeset = get_object_or_404(ChangeSet, pk=set_id) if not request.user.get_profile().has_permission(changeset.object, mode='w') \ and not request.user.get_profile().is_admin('treeio.changes'): return user_denied(request, "You don't have access to this Change Set.", response_format=response_format) if request.POST: form = ChangeSetForm(request.user.get_profile(), request.POST, instance=changeset) if form.is_valid(): changeset = form.save() return HttpResponseRedirect( reverse('changes_set_view', args=[changeset.id])) else: form = ChangeSetForm(request.user.get_profile(), instance=changeset) context = _get_default_context(request) context.update({'changeset': changeset, 'form': form}) return render_to_response('changes/set_edit', context, context_instance=RequestContext(request), response_format=response_format)
def status_edit(request, status_id, response_format='html'): "TicketStatus edit" status = get_object_or_404(TicketStatus, pk=status_id) if not request.user.get_profile().has_permission(status, mode='w') \ and not request.user.get_profile().is_admin('treeio_services'): return user_denied(request, "You don't have access to this Ticket Status", response_format) if request.POST: if not 'cancel' in request.POST: form = TicketStatusForm( request.user.get_profile(), request.POST, instance=status) if form.is_valid(): status = form.save() return HttpResponseRedirect(reverse('services_status_view', args=[status.id])) else: return HttpResponseRedirect(reverse('services_status_view', args=[status.id])) else: form = TicketStatusForm(request.user.get_profile(), instance=status) context = _get_default_context(request) context.update({'form': form, 'status': status}) return render_to_response('services/status_edit', context, context_instance=RequestContext(request), response_format=response_format)
def set_delete(request, set_id, response_format='html'): "ChangeSet delete" changeset = get_object_or_404(ChangeSet, pk=set_id) if not request.user.get_profile().has_permission(changeset.object, mode='w') \ and not request.user.get_profile().is_admin('treeio.changes'): return user_denied(request, "You don't have access to this Change Set.", response_format=response_format) if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: changeset.trash = True changeset.save() else: changeset.delete() return HttpResponseRedirect(reverse('changes_index')) elif 'cancel' in request.POST: return HttpResponseRedirect( reverse('changes_set_view', args=[changeset.id])) context = _get_default_context(request) context.update({'changeset': changeset}) return render_to_response('changes/set_delete', context, context_instance=RequestContext(request), response_format=response_format)
def ticket_edit(request, ticket_id, response_format='html'): "Ticket edit" context = _get_default_context(request) agent = context['agent'] ticket = get_object_or_404(Ticket, pk=ticket_id) if not request.user.get_profile().has_permission(ticket, mode='w'): return user_denied(request, message="You don't have access to this Ticket") if request.POST: if not 'cancel' in request.POST: form = TicketForm( request.user.get_profile(), None, agent, request.POST, instance=ticket) if form.is_valid(): ticket = form.save() return HttpResponseRedirect(reverse('services_ticket_view', args=[ticket.id])) else: return HttpResponseRedirect(reverse('services_ticket_view', args=[ticket.id])) else: form = TicketForm( request.user.get_profile(), None, agent, instance=ticket) context.update({'form': form, 'ticket': ticket}) return render_to_response('services/ticket_edit', context, context_instance=RequestContext(request), response_format=response_format)
def folder_edit(request, knowledgeType_id, response_format='html'): "Knowledge folder edit page" folder = get_object_or_404(KnowledgeFolder, pk=knowledgeType_id) items = Object.filter_by_request( request, manager=KnowledgeItem.objects.filter(folder=folder)) if not request.user.get_profile().has_permission(folder, mode="w"): return user_denied(request, message="You don't have access to this Knowledge Type") if request.POST: if not 'cancel' in request.POST: form = KnowledgeFolderForm( request.user.get_profile(), None, request.POST, instance=folder) if form.is_valid(): folder = form.save() return HttpResponseRedirect(reverse('knowledge_folder_view', args=[folder.treepath])) else: return HttpResponseRedirect(reverse('knowledge_folder_view', args=[folder.treepath])) else: form = KnowledgeFolderForm( request.user.get_profile(), None, instance=folder) context = _get_default_context(request) context.update({'items': items, 'folder': folder, 'form': form}) return render_to_response('knowledge/folder_edit', context, context_instance=RequestContext(request), response_format=response_format)
def folder_edit(request, knowledgeType_id, response_format='html'): "Knowledge folder edit page" folder = get_object_or_404(KnowledgeFolder, pk=knowledgeType_id) items = Object.filter_by_request(request, manager=KnowledgeItem.objects.filter(folder=folder)) if not request.user.get_profile().has_permission(folder, mode="w"): return user_denied(request, message="You don't have access to this Knowledge Type") if request.POST: if not 'cancel' in request.POST: form = KnowledgeFolderForm(request.user.get_profile(), None, request.POST, instance=folder) if form.is_valid(): folder = form.save() return HttpResponseRedirect(reverse('knowledge_folder_view', args=[folder.treepath])) else: return HttpResponseRedirect(reverse('knowledge_folder_view', args=[folder.treepath])) else: form = KnowledgeFolderForm(request.user.get_profile(), None, instance=folder) context = _get_default_context(request) context.update({'items': items, 'folder': folder, 'form': form}) return render_to_response('knowledge/folder_edit', context, context_instance=RequestContext(request), response_format=response_format)
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.get_profile(), mode='r') if not request.user.get_profile().has_permission(item, mode="w"): return user_denied(request, message="You don't have access to this Knowledge Item") if request.POST: if not 'cancel' in request.POST: form = KnowledgeItemForm( request.user.get_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.get_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)
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.get_profile(), mode='r') if not request.user.get_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)
def chart_delete(request, chart_id, response_format='html'): "Chart delete" chart = get_object_or_404(Chart, pk=chart_id) report = chart.report if not request.user.get_profile().has_permission(chart, mode='w'): return user_denied(request, message="You don't have access to this Event") if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: chart.trash = True chart.save() else: chart.delete() return HttpResponseRedirect( reverse('reports_report_view', args=[report.id])) elif 'cancel' in request.POST: return HttpResponseRedirect( reverse('reports_report_view', args=[report.id])) return render_to_response('reports/chart_delete', {'chart': chart}, context_instance=RequestContext(request), response_format=response_format)
def field_add(request, response_format='html'): "ItemField add" if not request.user.get_profile().is_admin('treeio.infrastructure'): return user_denied(request, message="You don't have administrator access to the Infrastructure module", response_format=response_format) if request.POST: if not 'cancel' in request.POST: field = ItemField() form = ItemFieldForm(request.POST, instance=field) if form.is_valid(): field = form.save(request) field.set_user_from_request(request) return HttpResponseRedirect(reverse('infrastructure_field_view', args=[field.id])) else: return HttpResponseRedirect(reverse('infrastructure_settings_view')) else: form = ItemFieldForm() context = _get_default_context(request) context.update({'form': form}) return render_to_response('infrastructure/field_add', context, context_instance=RequestContext(request), response_format=response_format)
def report_filter(request, report_id, field_name, response_format='html'): "View to Filter over a given field for a Report" report = get_object_or_404(Report, pk=report_id) if not request.user.get_profile().has_permission(report, mode='w'): return user_denied(request, message="You don't have access to this Report") if request.POST: FilterForm(request.user.get_profile(), request.POST, report=report, field_name=field_name).save() return HttpResponseRedirect( reverse('reports_report_edit', args=[report.id])) else: form = FilterForm(request.user.get_profile(), report=report, field_name=field_name) return render_to_response('reports/report_filter', { 'form': form, 'field_name': field_name }, context_instance=RequestContext(request), response_format=response_format)
def status_add(request, response_format='html'): "ItemStatus edit" if not request.user.get_profile().is_admin('treeio.infrastructure'): return user_denied(request, message="You are not an Administrator of the Infrastructure module", response_format=response_format) if request.POST: if not 'cancel' in request.POST: item_status = ItemStatus() form = ItemStatusForm(request.POST, instance=item_status) if form.is_valid(): item_status = form.save(request) item_status.set_user_from_request(request) return HttpResponseRedirect(reverse('infrastructure_status_view', args=[item_status.id])) else: return HttpResponseRedirect(reverse('infrastructure_settings_view')) else: form = ItemStatusForm() context = _get_default_context(request) context.update({'form': form}) return render_to_response('infrastructure/item_status_add', context, context_instance=RequestContext(request), response_format=response_format)
def report_group(request, report_id, field_name, response_format='html'): "View to Group by a given field in a report" t = get_object_or_404(Report, pk=report_id) if not request.user.get_profile().has_permission(t, mode='w'): return user_denied(request, message="You don't have access to this Report") model = loads(t.model) # Check if this field is already grouped, if so then remove grouping thisfield = model.get_field(field_name) if thisfield.groupby == 1: thisfield.groupby = 0 else: # Other wise reset grouping and set selected field as groupfield for field in model.fields: field.groupby = 0 field = model.get_field(field_name) field.groupby = 1 t.model = dumps(model) t.save() return report_edit(request, report_id=report_id, response_format=response_format)
def item_edit(request, item_id, response_format='html'): "Item edit page" item = get_object_or_404(Item, pk=item_id) if not request.user.get_profile().has_permission(item, mode="w"): return user_denied(request, message="You don't have write access to this Item", response_format=response_format) if request.POST: if not 'cancel' in request.POST: form = ItemForm(request.user.get_profile(), item.item_type, request.POST, files=request.FILES, instance=item) if form.is_valid(): item = form.save(request) return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id])) else: return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id])) else: form = ItemForm( request.user.get_profile(), item.item_type, instance=item) context = _get_default_context(request) context.update({'item': item, 'form': form}) return render_to_response('infrastructure/item_edit', context, context_instance=RequestContext(request), response_format=response_format)
def type_delete(request, type_id, response_format='html'): "ContactType delete page" type = get_object_or_404(ContactType, pk=type_id) if not request.user.get_profile().has_permission(type, mode="w"): return user_denied( request, message="You don't have write access to this ContactType") if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: type.trash = True type.save() else: type.delete() return HttpResponseRedirect(reverse('identities_index')) elif 'cancel' in request.POST: return HttpResponseRedirect( reverse('identities_type_view', args=[type.id])) context = _get_default_context(request) context.update({'type': type}) return render_to_response('identities/contact_type_delete', context, context_instance=RequestContext(request), response_format=response_format)
def settings_view(request, response_format='html'): "Settings" if not request.user.get_profile().is_admin('treeio.infrastructure'): return user_denied(request, message="You are not an Administrator of the Infrastructure module", response_format=response_format) item_types = ItemType.objects.all().filter(trash=False) item_statuses = ItemStatus.objects.all().filter(trash=False) item_fields = ItemField.objects.all().filter(trash=False) default_item_status = None try: conf = ModuleSetting.get_for_module( 'treeio.infrastructure', 'default_item_status')[0] default_item_status = ItemStatus.objects.get( pk=long(conf.value), trash=False) except Exception: pass context = _get_default_context(request) context.update({'item_types': item_types, 'item_fields': item_fields, 'item_statuses': item_statuses, 'default_item_status': default_item_status}) return render_to_response('infrastructure/settings_view', context, context_instance=RequestContext(request), response_format=response_format)
def field_edit(request, field_id, response_format='html'): "ContactField edit" field = get_object_or_404(ContactField, pk=field_id) if not request.user.get_profile().has_permission(field, mode='w'): return user_denied(request, message="You don't have access to this Field Type", response_format=response_format) if request.POST: if not 'cancel' in request.POST: form = ContactFieldForm(request.POST, instance=field) if form.is_valid(): field = form.save(request) return HttpResponseRedirect( reverse('identities_field_view', args=[field.id])) else: return HttpResponseRedirect( reverse('identities_field_view', args=[field.id])) else: form = ContactFieldForm(instance=field) context = _get_default_context(request) context.update({'form': form, 'field': field}) return render_to_response('identities/field_edit', context, context_instance=RequestContext(request), response_format=response_format)
def service_record_edit(request, service_record_id, response_format='html'): "ServiceRecord edit page" service_record = get_object_or_404(ItemServicing, pk=service_record_id) if not request.user.get_profile().has_permission(service_record, mode="w"): return user_denied(request, message="You don't have write access to this ServiceRecord", response_format=response_format) if request.POST: if not 'cancel' in request.POST: form = ServiceRecordForm( request.user.get_profile(), None, request.POST, instance=service_record) if form.is_valid(): service_record = form.save(request) return HttpResponseRedirect(reverse('infrastructure_service_record_view', args=[service_record.id])) else: return HttpResponseRedirect(reverse('infrastructure_service_record_view', args=[service_record.id])) else: form = ServiceRecordForm( request.user.get_profile(), None, instance=service_record) context = _get_default_context(request) context.update({'service_record': service_record, 'form': form}) return render_to_response('infrastructure/service_record_edit', context, context_instance=RequestContext(request), response_format=response_format)
def field_add(request, response_format='html'): "ContactField add" if not request.user.get_profile().is_admin('treeio.identities'): return user_denied( request, message= "You don't have administrator access to the Infrastructure module", response_format=response_format) if request.POST: if not 'cancel' in request.POST: field = ContactField() form = ContactFieldForm(request.POST, instance=field) if form.is_valid(): field = form.save(request) field.set_user_from_request(request) return HttpResponseRedirect( reverse('identities_field_view', args=[field.id])) else: return HttpResponseRedirect(reverse('identities_settings_view')) else: form = ContactFieldForm() context = _get_default_context(request) context.update({'form': form}) return render_to_response('identities/field_add', context, context_instance=RequestContext(request), response_format=response_format)
def folder_delete(request, knowledgeType_id, response_format='html'): "Type delete" folder = get_object_or_404(KnowledgeFolder, pk=knowledgeType_id) items = Object.filter_by_request( request, manager=KnowledgeItem.objects.filter(folder=folder)) if not request.user.get_profile().has_permission(folder, mode='w'): return user_denied( request, message="You don't have access to this Knowledge Type") if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: folder.trash = True folder.save() else: folder.delete() return HttpResponseRedirect(reverse('knowledge_index')) elif 'cancel' in request.POST: return HttpResponseRedirect( reverse('knowledge_folder_view', args=[folder.treepath])) context = _get_default_context(request) context.update({'items': items, 'folder': folder}) return render_to_response('knowledge/folder_delete', context, context_instance=RequestContext(request), response_format=response_format)
def field_delete(request, field_id, response_format='html'): "ContactField delete page" field = get_object_or_404(ContactField, pk=field_id) if not request.user.get_profile().has_permission(field, mode="w"): return user_denied( request, message="You don't have write access to this ContactField") if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: field.trash = True field.save() else: field.delete() return HttpResponseRedirect(reverse('identities_index')) elif 'cancel' in request.POST: return HttpResponseRedirect( reverse('identities_field_view', args=[field.id])) context = _get_default_context(request) context.update({'field': field}) return render_to_response('identities/field_delete', context, context_instance=RequestContext(request), response_format=response_format)
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.get_profile(), mode='r') if not request.user.get_profile().has_permission(category, mode="w"): return user_denied( request, message="You don't have access to this Knowledge Category") if request.POST: if not 'cancel' 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)
def contact_add_typed(request, type_id, response_format='html'): "Contact add with preselected type" contact_type = get_object_or_404(ContactType, pk=type_id) if not request.user.get_profile().has_permission(contact_type, mode='x'): return user_denied(request, message="You don't have access to create " + unicode(contact_type)) if request.POST: if not 'cancel' in request.POST: form = ContactForm(request.user.get_profile(), contact_type, request.POST, files=request.FILES) if form.is_valid(): contact = form.save(request, contact_type) contact.set_user_from_request(request) return HttpResponseRedirect( reverse('identities_contact_view', args=[contact.id])) else: return HttpResponseRedirect(reverse('identities_index')) else: form = ContactForm(request.user.get_profile(), contact_type) types = Object.filter_by_request(request, ContactType.objects.order_by('name')) return render_to_response('identities/contact_add_typed', { 'type': contact_type, 'types': types, 'form': form }, context_instance=RequestContext(request), response_format=response_format)
def index_assigned(request, response_format='html'): "Tickets assigned to current user" context = _get_default_context(request) agent = context['agent'] if agent: query = Q(assigned=agent) 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)) else: return user_denied(request, "You are not a Service Support Agent.", response_format=response_format) filters = FilterForm(request.user.get_profile(), 'assigned', request.GET) context.update({'tickets': tickets, 'filters': filters}) return render_to_response('services/index_assigned', context, context_instance=RequestContext(request), response_format=response_format)
def contact_delete(request, contact_id, response_format='html'): "Contact delete" contact = get_object_or_404(Contact, pk=contact_id) if not request.user.get_profile().has_permission(contact, mode='w'): return user_denied(request, message="You don't have access to this Contact") if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: contact.trash = True contact.save() else: contact.delete() return HttpResponseRedirect(reverse('identities_index')) elif 'cancel' in request.POST: return HttpResponseRedirect( reverse('identities_contact_view', args=[contact.id])) types = Object.filter_by_request(request, ContactType.objects.order_by('name')) return render_to_response('identities/contact_delete', { 'contact': contact, 'types': types }, context_instance=RequestContext(request), response_format=response_format)
def queue_view(request, queue_id, response_format='html'): "Queue view" queue = get_object_or_404(TicketQueue, pk=queue_id) if not request.user.get_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.get_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)
def location_edit(request, location_id, response_format='html'): "Location edit page" location = get_object_or_404(Location, pk=location_id) if not request.user.get_profile().has_permission(location, mode="w"): return user_denied( request, message="You don't have write access to this Location", response_format=response_format) if request.POST: if not 'cancel' in request.POST: form = LocationForm(request.user.get_profile(), None, request.POST, instance=location) if form.is_valid(): location = form.save(request) return HttpResponseRedirect( reverse('identities_location_view', args=[location.id])) else: return HttpResponseRedirect( reverse('identities_location_view', args=[location.id])) else: form = LocationForm(request.user.get_profile(), None, instance=location) context = _get_default_context(request) context.update({'location': location, 'form': form}) return render_to_response('identities/location_edit', context, context_instance=RequestContext(request), response_format=response_format)
def queue_add(request, response_format='html'): "Queue add" if not request.user.get_profile().is_admin('treeio.services'): return user_denied(request, message="You don't have administrator access to the Service Support module") if request.POST: if not 'cancel' in request.POST: queue = TicketQueue() form = QueueForm( request.user.get_profile(), request.POST, instance=queue) if form.is_valid(): queue = form.save() queue.set_user_from_request(request) return HttpResponseRedirect(reverse('services_queue_view', args=[queue.id])) else: return HttpResponseRedirect(reverse('services_settings_view')) else: form = QueueForm(request.user.get_profile()) context = _get_default_context(request) context.update({'form': form}) return render_to_response('services/queue_add', context, context_instance=RequestContext(request), response_format=response_format)
def location_delete(request, location_id, response_format='html'): "Location delete page" location = get_object_or_404(Location, pk=location_id) if not request.user.get_profile().has_permission(location, mode="w"): return user_denied( request, message="You don't have write access to this Location") if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: location.trash = True location.save() else: location.delete() return HttpResponseRedirect(reverse('identities_index')) elif 'cancel' in request.POST: return HttpResponseRedirect( reverse('identities_location_view', args=[location.id])) context = _get_default_context(request) context.update({'location': location}) return render_to_response('identities/location_delete', context, context_instance=RequestContext(request), response_format=response_format)
def service_edit(request, service_id, response_format='html'): "Service edit" service = get_object_or_404(Service, pk=service_id) if not request.user.get_profile().has_permission(service, mode='w') \ and not request.user.get_profile().is_admin('treeio_services'): return user_denied(request, message="You don't have access to this Service") if request.POST: if not 'cancel' in request.POST: form = ServiceForm( request.user.get_profile(), request.POST, instance=service) if form.is_valid(): service = form.save() return HttpResponseRedirect(reverse('services_service_view', args=[service.id])) else: return HttpResponseRedirect(reverse('services_service_view', args=[service.id])) else: form = ServiceForm(request.user.get_profile(), instance=service) context = _get_default_context(request) context.update({'form': form, 'service': service}) return render_to_response('services/service_edit', context, context_instance=RequestContext(request), response_format=response_format)
def stream_edit(request, stream_id, response_format='html'): "Stream edit page" user = request.user.get_profile() stream = get_object_or_404(MessageStream, pk=stream_id) if not request.user.get_profile().has_permission(stream, mode="w"): return user_denied(request, message="You don't have access to this Stream", response_format=response_format) if request.POST: if not 'cancel' in request.POST: form = MessageStreamForm(user, request.POST, instance=stream) if form.is_valid(): stream = form.save() return HttpResponseRedirect(reverse('messaging_stream_view', args=[stream.id])) else: return HttpResponseRedirect(reverse('messaging_stream_view', args=[stream.id])) else: form = MessageStreamForm(user, instance=stream) context = _get_default_context(request) context.update({'form': form, 'stream':stream}) return render_to_response('messaging/stream_edit', context, context_instance=RequestContext(request), response_format=response_format)
def sla_add(request, response_format='html'): "ServiceLevelAgreement add" if not request.user.get_profile().is_admin('treeio.services'): return user_denied(request, message="You don't have administrator access to the Service Support module") if request.POST: if not 'cancel' in request.POST: sla = ServiceLevelAgreement() form = ServiceLevelAgreementForm( request.user.get_profile(), request.POST, instance=sla) if form.is_valid(): sla = form.save() sla.set_user_from_request(request) return HttpResponseRedirect(reverse('services_sla_view', args=[sla.id])) else: return HttpResponseRedirect(reverse('services')) else: form = ServiceLevelAgreementForm(request.user.get_profile()) context = _get_default_context(request) context.update({'form': form}) return render_to_response('services/sla_add', context, context_instance=RequestContext(request), response_format=response_format)
def stream_delete(request, stream_id, response_format='html'): "Delete stream page" stream = get_object_or_404(MessageStream, pk=stream_id) if not request.user.get_profile().has_permission(stream, mode="w"): return user_denied(request, message="You don't have access to this Stream", response_format=response_format) if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: stream.trash = True stream.save() else: stream.delete() return HttpResponseRedirect('/messaging/') elif 'cancel' in request.POST: return HttpResponseRedirect(reverse('messaging_stream_view', args=[stream.id])) context = _get_default_context(request) context.update({'stream':stream}) return render_to_response('messaging/stream_delete', context, context_instance=RequestContext(request), response_format=response_format)
def folder_delete(request, knowledgeType_id, response_format='html'): "Type delete" folder = get_object_or_404(KnowledgeFolder, pk=knowledgeType_id) items = Object.filter_by_request(request, manager=KnowledgeItem.objects.filter(folder=folder)) if not request.user.get_profile().has_permission(folder, mode='w'): return user_denied(request, message="You don't have access to this Knowledge Type") if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: folder.trash = True folder.save() else: folder.delete() return HttpResponseRedirect(reverse('knowledge_index')) elif 'cancel' in request.POST: return HttpResponseRedirect(reverse('knowledge_folder_view', args=[folder.treepath])) context = _get_default_context(request) context.update({'items': items, 'folder':folder}) return render_to_response('knowledge/folder_delete', context, context_instance=RequestContext(request), response_format=response_format)
def mlist_delete(request, mlist_id, response_format='html'): "Delete mlist page" mlist = get_object_or_404(MailingList, pk=mlist_id) if not request.user.get_profile().has_permission(mlist, mode="w"): return user_denied(request, message="You don't have access to this Mailing List", response_format=response_format) if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: mlist.trash = True mlist.save() else: mlist.delete() return HttpResponseRedirect('/messaging/') elif 'cancel' in request.POST: return HttpResponseRedirect(reverse('messaging_mlist_view', args=[mlist.id])) context = _get_default_context(request) context.update({'mlist':mlist}) return render_to_response('messaging/mlist_delete', context, context_instance=RequestContext(request), response_format=response_format)
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.get_profile(), mode='r') if not request.user.get_profile().has_permission(category, mode="w"): return user_denied(request, message="You don't have access to this Knowledge Category") if request.POST: if not 'cancel' 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)
def type_edit(request, type_id, response_format='html'): "ItemType edit" item_type = get_object_or_404(ItemType, pk=type_id) if not request.user.get_profile().has_permission(item_type, mode='w'): return user_denied(request, message="You don't have access to this Item Type", response_format=response_format) infrastructure = Object.filter_by_request(request, Item.objects.filter(item_type=item_type).order_by('name')) if request.POST: if not 'cancel' in request.POST: form = ItemTypeForm( request.user.get_profile(), request.POST, instance=item_type) if form.is_valid(): item_type = form.save(request) return HttpResponseRedirect(reverse('infrastructure_type_view', args=[item_type.id])) else: return HttpResponseRedirect(reverse('infrastructure_type_view', args=[item_type.id])) else: form = ItemTypeForm(request.user.get_profile(), instance=item_type) context = _get_default_context(request) context.update({'infrastructure': infrastructure, 'form': form, 'item_type': item_type}) return render_to_response('infrastructure/item_type_edit', context, context_instance=RequestContext(request), response_format=response_format)
def field_edit(request, field_id, response_format='html'): "ItemField edit" field = get_object_or_404(ItemField, pk=field_id) if not request.user.get_profile().has_permission(field, mode='w'): return user_denied(request, message="You don't have access to this Field Type", response_format=response_format) if request.POST: if not 'cancel' in request.POST: form = ItemFieldForm(request.POST, instance=field) if form.is_valid(): item = form.save(request) return HttpResponseRedirect(reverse('infrastructure_field_view', args=[item.id])) else: return HttpResponseRedirect(reverse('infrastructure_field_view', args=[item.id])) else: form = ItemFieldForm(instance=field) context = _get_default_context(request) context.update({'form': form, 'field': field}) return render_to_response('infrastructure/field_edit', context, context_instance=RequestContext(request), response_format=response_format)