示例#1
0
文件: views.py 项目: jmfield2/treeio
def report_view(request, response_format="html", report_id=None):
    "Display the report"

    report = get_object_or_404(Report, pk=report_id)
    report_context = _get_report_content(report, request)
    context = _get_default_context(request)
    context.update(report_context)

    if response_format == "csv":
        return render_to_response(
            "reports/gen", context, context_instance=RequestContext(request), response_format="csv"
        )

    report_content = str(
        render_to_response("reports/gen", context, context_instance=RequestContext(request), response_format="html")
    ).replace("Content-Type: text/html", "")

    charts = report.chart_set.filter(trash=False)

    # Now take the rendered report and embed it in the report view page.
    context = _get_default_context(request)
    context.update({"report": report, "charts": charts, "report_content": report_content})

    return render_to_response(
        "reports/report_view", context, context_instance=RequestContext(request), response_format=response_format
    )
示例#2
0
def authorize_request_token(request, form_class=AuthorizeRequestTokenForm, template_name='core/api/auth/authorize', verification_template_name='core/api/auth/authorize_verification_code'):
    if 'oauth_token' not in request.REQUEST:
        return HttpResponseBadRequest('No request token specified.')

    oauth_request = get_oauth_request(request)

    try:
        request_token = store.fetch_request_token(request, oauth_request, request.REQUEST['oauth_token'])
    except InvalidTokenError:
        return HttpResponseBadRequest('Invalid request token.')

    consumer = store.get_consumer_for_request_token(request, oauth_request, request_token)

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid() and form.cleaned_data['authorize_access']:
            request_token = store.authorize_request_token(request, oauth_request, request_token)
            if request_token.callback is not None and request_token.callback != 'oob':
                domain = RequestSite(request).domain
                return HttpResponseRedirect('%s&%s' % (request_token.get_callback_url(), urlencode({'oauth_token': request_token.key, 'domain': domain})))
            else:
                return render_to_response(verification_template_name,
                                          {'consumer': consumer, 'verification_code': request_token.verifier},
                                          context_instance=RequestContext(request), response_format='html')
    else:
        form = form_class(initial={'oauth_token': request_token.key})

    return render_to_response(template_name, {'consumer': consumer, 'form': form},
                              context_instance=RequestContext(request), response_format='html')
示例#3
0
文件: views.py 项目: 5n1p/treeio
def report_view(request, response_format='html', report_id=None):
    "Display the report"

    report = get_object_or_404(Report, pk=report_id)
    report_context = _get_report_content(report, request)
    context = _get_default_context(request)
    context.update(report_context)

    if response_format == "csv":
        return render_to_response('reports/gen', context,
                                  context_instance=RequestContext(request),
                                  response_format='csv')

    report_content = str(render_to_response('reports/gen', context,
                                            context_instance=RequestContext(
                                                request),
                                            response_format='html')).replace('Content-Type: text/html', '')

    charts = report.chart_set.filter(trash=False)

    # Now take the rendered report and embed it in the report view page.
    context = _get_default_context(request)
    context.update({'report': report,
                    'charts': charts,
                    'report_content': report_content})

    return render_to_response('reports/report_view', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#4
0
def widget_contact_me(request, response_format='html'):
    "My Contact card"
    
    contact = request.user.get_profile().get_contact()
    if not request.user.get_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'))
    if contact:
        return render_to_response('identities/widgets/contact_me',
                                  {'contact': contact, 'types': types},
                                  context_instance=RequestContext(request), response_format=response_format)
    else:
        return render_to_response('identities/widgets/contact_me_missing', {'types': types},
                                  context_instance=RequestContext(request), response_format=response_format)
示例#5
0
文件: views.py 项目: 5n1p/treeio
def item_add(request, response_format='html'):
    "New item form"

    context = _get_default_context(request)

    return render_to_response('infrastructure/item_add', context,
                              context_instance=RequestContext(request), response_format=response_format)
示例#6
0
def invitation_retrieve(request, response_format='html'):
    "Retrieve invitation and create account"
    
    if request.user.username:
        return HttpResponseRedirect('/')
    
    email = request.REQUEST.get('email', None)
    key = request.REQUEST.get('key', None)
    if email and key:
        try:
            invitation = Invitation.objects.get(email=email, key=key)
        except:
            raise Http404
    else:
        raise Http404
    
    if request.POST:
        form = InvitationForm(invitation, request.POST)
        if form.is_valid():
            profile = form.save()
            username = profile.user.username
            password = form.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user:
                invitation.delete()
                login(request, user)
                return HttpResponseRedirect('/')
    else:
        form = InvitationForm(invitation)

    return render_to_response('core/invitation_retrieve',
                              {'invitation': invitation,
                               'form': form},
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#7
0
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)
示例#8
0
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)
示例#9
0
def user_denied(request, message='', response_format='html'):
    "User denied page"
    response = render_to_response('core/user_denied',
                                 {'message': message},
                                 context_instance=RequestContext(request), response_format=response_format)
    #response.status_code = 403
    return response
示例#10
0
文件: views.py 项目: AlexLX2/treeio
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)
示例#11
0
文件: views.py 项目: 5n1p/treeio
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)
示例#12
0
文件: views.py 项目: AlexLX2/treeio
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)
示例#13
0
文件: views.py 项目: 5n1p/treeio
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)
示例#14
0
文件: views.py 项目: 5n1p/treeio
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)
示例#15
0
文件: views.py 项目: AlexLX2/treeio
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)
示例#16
0
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)
示例#17
0
文件: views.py 项目: AlexLX2/treeio
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)
示例#18
0
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)
示例#19
0
def item_add(request, response_format='html'):
    "Add new knowledge item"
    items = Object.filter_permitted(manager=KnowledgeItem.objects, user=request.user.get_profile(), mode='r')
    
    if request.POST:
        if not 'cancel' in request.POST:
            item = KnowledgeItem()
            form = KnowledgeItemForm(request.user.get_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.get_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)
示例#20
0
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.get_profile(), mode='r')
    
    try:
        folder = KnowledgeFolder.by_path(folderPath)
        knowledgeType_id = folder.id
    except KnowledgeFolder.DoesNotExist:
        raise Http404    
            
    if request.POST:
        if not 'cancel' in request.POST:
            item = KnowledgeItem()
            form = KnowledgeItemForm(request.user.get_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.get_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)
示例#21
0
文件: views.py 项目: AlexLX2/treeio
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)
示例#22
0
文件: views.py 项目: 5n1p/treeio
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)
示例#23
0
文件: views.py 项目: AlexLX2/treeio
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)
示例#24
0
文件: views.py 项目: 5n1p/treeio
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)
示例#25
0
文件: views.py 项目: 5n1p/treeio
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)
示例#26
0
文件: views.py 项目: 5n1p/treeio
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)
示例#27
0
文件: views.py 项目: AlexLX2/treeio
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)
示例#28
0
文件: views.py 项目: AlexLX2/treeio
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)
示例#29
0
文件: views.py 项目: AlexLX2/treeio
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)
示例#30
0
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)
示例#31
0
def agent_view(request, agent_id, response_format='html'):
    "Agent view"

    view_agent = get_object_or_404(ServiceAgent, pk=agent_id)
    if not request.user.get_profile().has_permission(view_agent):
        return user_denied(
            request, message="You don't have access to this Service Agent")

    context = _get_default_context(request)
    context.update({'view_agent': view_agent})

    return render_to_response('services/agent_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#32
0
def widget_my_watchlist(request, response_format='html'):
    "Displays news about all objects a User is subscribed to"

    profile = request.user.get_profile()
    query = _get_filter_query(profile, do_recipients=False) & Q(
        about__in=profile.subscriptions.all()) & ~Q(author=profile)
    updates = UpdateRecord.objects.filter(query).distinct()

    context = _get_default_context(request)
    context.update({'updates': updates, 'profile': profile})

    return render_to_response('news/widgets/my_watchlist',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#33
0
def item_view(request, item_id, response_format='html'):
    "Item view"
    item = get_object_or_404(Item, pk=item_id)
    if not request.user.get_profile().has_permission(item):
        return user_denied(request,
                           message="You don't have access to this Item",
                           response_format=response_format)

    context = _get_default_context(request)
    context.update({'item': item})

    return render_to_response('infrastructure/item_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#34
0
def account_view(request, response_format='html'):
    "Account view"

    profile = request.user.get_profile()
    try:
        contacts = profile.contact_set.exclude(trash=True)
    except:
        contacts = []

    return render_to_response('account/account_view', {
        'profile': profile,
        'contacts': contacts
    },
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#35
0
def database_setup(request, response_format='html'):
    if not User.objects.all().count():
        if request.POST:
            sql_form = SqlSettingsForm(data=request.POST)
            if sql_form.is_valid():
                sql_form.create_database()
                if sql_form.is_valid():
                    return HttpResponseRedirect('/')
        else:
            sql_form = SqlSettingsForm()
        return render_to_response('core/database_setup',
                                  {'sql_form': sql_form},
                                  context_instance=RequestContext(request),
                                  response_format=response_format)
    return HttpResponseRedirect('/')
示例#36
0
文件: views.py 项目: vingodu/treeio
def service_catalogue(request, response_format='html'):
    "All available Services"

    services = Object.filter_by_request(
        request, Service.objects.filter(parent__isnull=True))

    filters = FilterForm(request.user.get_profile(), '', request.GET)

    context = _get_default_context(request)
    context.update({'services': services, 'filters': filters})

    return render_to_response('services/service_catalogue',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#37
0
def location_index(request, location_id, response_format='html'):
    "Location index"

    locations = Object.filter_permitted(request.user.get_profile(),
                                        Location.objects)

    context = _get_default_context(request)
    context.update({
        'locations': locations,
    })

    return render_to_response('identities/location_index',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#38
0
文件: views.py 项目: vovkd/treeio
def day_view(request, response_format='html'):
    "Day view - each slot represents an hour"

    events = Object.filter_by_request(request, Event.objects)

    date_current = now = datetime.now()
    istoday = True

    gotoform = GoToDateForm(now, request.GET)
    if request.GET:
        if 'date_year' in request.GET and 'date_month' in request.GET and 'date_day' in request.GET:
            try:
                day = int(request.GET['date_day'])
                year = int(request.GET['date_year'])
                month = int(request.GET['date_month'])
                if year >= 1900 and month >= 1 and month <= 12 and day >= 1 and day <= 31:
                    date_current = datetime(year, month, day)
                    istoday = date_current == now
            except Exception:
                pass
        if gotoform.is_valid() and gotoform.cleaned_data['goto']:
            date_current = gotoform.cleaned_data['goto']
            istoday = date_current == now
            date_current = now = datetime(date_current.year,
                                          date_current.month, date_current.day)

    day = date_current.date()
    date_previous = date_current - relativedelta(days=+1)
    date_next = date_current + relativedelta(days=+1)

    wrapped_events = EventCollection(events, START_HOUR, END_HOUR)
    wrapped_events.collect_events(request)

    hours = range(START_HOUR, END_HOUR + 1)

    return render_to_response('events/day_view', {
        'events': wrapped_events,
        'day': day,
        'hours': hours,
        'date_previous': date_previous,
        'date_next': date_next,
        'date_current': date_current,
        'gotoform': gotoform.as_ul(),
        'istoday': istoday,
        'now': now
    },
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#39
0
def field_view(request, field_id, response_format='html'):
    "ContactField view"

    field = get_object_or_404(ContactField, pk=field_id)
    if not request.user.get_profile().has_permission(field):
        return user_denied(request,
                           message="You don't have access to this Field Type",
                           response_format=response_format)

    context = _get_default_context(request)
    context.update({'field': field})

    return render_to_response('identities/field_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#40
0
文件: views.py 项目: vingodu/treeio
def account_edit(request, response_format='html'):
    "Account edit"

    profile = request.user.get_profile()
    if request.POST:
        form = AccountForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('account_view'))
    else:
        form = AccountForm(instance=profile)

    return render_to_response('account/account_edit',
                              {'profile': profile,
                                  'form': Markup(form.as_ul())},
                              context_instance=RequestContext(request), response_format=response_format)
示例#41
0
def pagefolder_add(request, response_format='html'):
    "Folder for Static Pages add"

    if request.POST:
        form = PageFolderForm(request.POST)
        if form.is_valid():
            folder = form.save()
            return HttpResponseRedirect(
                reverse('core_admin_pagefolder_view', args=[folder.id]))
    else:
        form = PageFolderForm()

    return render_to_response('core/administration/pagefolder_add',
                              {'form': form},
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#42
0
def page_delete(request, page_id, response_format='html'):
    "Static Page delete"

    page = get_object_or_404(Page, pk=page_id)
    if request.POST:
        if 'delete' in request.POST:
            page.delete()
            return HttpResponseRedirect(reverse('core_admin_index_pages'))
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(
                reverse('core_admin_page_view', args=[page.id]))

    return render_to_response('core/administration/page_delete',
                              {'page': page},
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#43
0
文件: views.py 项目: vingodu/treeio
def dashboard_widget_add(request, module_name=None, widget_name=None, response_format='html'):
    "Add a Widget to the Dashboard"
    trash = Object.filter_by_request(request, manager=Object.objects.filter(trash=True),
                                     mode='r', filter_trash=False).count()

    if module_name and widget_name:
        widget = _create_widget_object(request, module_name, widget_name)
        if widget:
            return HttpResponseRedirect(reverse('core_dashboard_index'))

    widgets = _get_all_widgets(request)

    return render_to_response('core/dashboard/widget_add',
                              {'trash': trash,
                               'widgets': widgets},
                              context_instance=RequestContext(request), response_format=response_format)
示例#44
0
def service_record_view(request, service_record_id, response_format='html'):
    "ServiceRecord view"
    service_record = get_object_or_404(ItemServicing, pk=service_record_id)
    if not request.user.get_profile().has_permission(service_record):
        return user_denied(
            request,
            message="You don't have access to this ServiceRecord",
            response_format=response_format)

    context = _get_default_context(request)
    context.update({'service_record': service_record})

    return render_to_response('infrastructure/service_record_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#45
0
文件: views.py 项目: vovkd/treeio
def service_view(request, service_id, response_format='html'):
    "Service view"

    service = get_object_or_404(Service, pk=service_id)
    if not request.user.get_profile().has_permission(service) \
        and not request.user.get_profile().is_admin('treeio_services'):
        return user_denied(request,
                           message="You don't have access to this Service")

    context = _get_default_context(request)
    context.update({'service': service})

    return render_to_response('services/service_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#46
0
文件: views.py 项目: vovkd/treeio
def widget_welcome(request, response_format='html'):
    "Quick start widget, which users see when they first log in"

    trial = False
    if getattr(settings, 'HARDTREE_SUBSCRIPTION_USER_LIMIT') == 3:
        trial = True

    customization = getattr(settings, 'HARDTREE_SUBSCRIPTION_CUSTOMIZATION',
                            True)

    return render_to_response('core/widgets/welcome', {
        'trial': trial,
        'customization': customization
    },
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#47
0
文件: views.py 项目: vovkd/treeio
def sla_view(request, sla_id, response_format='html'):
    "ServiceLevelAgreement view"

    sla = get_object_or_404(ServiceLevelAgreement, pk=sla_id)
    if not request.user.get_profile().has_permission(sla):
        return user_denied(
            request,
            message="You don't have access to this Service Level Agreement")

    context = _get_default_context(request)
    context.update({'sla': sla})

    return render_to_response('services/sla_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#48
0
文件: views.py 项目: vovkd/treeio
def upcoming(request, response_format='html'):
    "Upcoming Events"

    now = datetime.now()
    query = Q(start__gte=now) | Q(end__gte=now)
    events = Object.filter_by_request(
        request,
        Event.objects.filter(query).order_by('-end'))

    context = _get_default_context(request)
    context.update({'events': events})

    return render_to_response('events/upcoming',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#49
0
def weblink_view(request, weblink_id, response_format='html'):
    "Weblink page"

    link = get_object_or_404(WebLink, pk=weblink_id)

    if not request.user.get_profile().has_permission(link):
        return user_denied(request,
                           message="You don't have access to this Web Link")

    context = _get_default_context(request)
    context.update({'link': link})

    return render_to_response('documents/weblink_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#50
0
文件: views.py 项目: vingodu/treeio
def status_add(request, response_format='html'):
    "Status add"

    if request.POST:
        form = ChangeSetStatusForm(request.user.get_profile(), request.POST)
        if form.is_valid():
            status = form.save()
            return HttpResponseRedirect(reverse('changes_status_view', args=[status.id]))
    else:
        form = ChangeSetStatusForm(request.user.get_profile())

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('changes/status_add', context,
                              context_instance=RequestContext(request), response_format=response_format)
示例#51
0
文件: views.py 项目: vingodu/treeio
def settings_edit(request, response_format='html'):
    "Settings"

    if request.POST:
        form = SettingsForm(request.user.get_profile(), request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('changes_settings_view'))
    else:
        form = SettingsForm(request.user.get_profile())

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('changes/settings_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
示例#52
0
def document_view(request, document_id, response_format='html'):
    "Single document view page"

    document = get_object_or_404(Document, pk=document_id)

    if not request.user.get_profile().has_permission(document):
        return user_denied(request,
                           message="You don't have access to this Document")

    context = _get_default_context(request)
    context.update({'document': document})

    return render_to_response('documents/document_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#53
0
def index_by_module(request, module_name, response_format='html'):
    "Default index page"

    profile = request.user.get_profile()
    try:
        module = profile.get_perspective().get_modules().filter(
            name__icontains=module_name)[0]
    except:
        raise Http404('No such module in your Perspective')
    query = _get_filter_query(profile, filters=request.GET) & Q(
        about__object_type__icontains=module_name) & (~Q(author=profile)
                                                      | Q(score__gt=0))
    updates = UpdateRecord.objects.filter(query).distinct()

    if request.POST:
        record = UpdateRecord()
        record.record_type = 'share'
        form = UpdateRecordForm(request.POST, user=profile, instance=record)
        if form.is_valid():
            record = form.save()
            record.body = record.body.replace('\n', ' <br />')
            record.save()
            record.set_user_from_request(request)
            return HttpResponseRedirect(
                reverse('news_index_by_module', filters=[module_name]))
    else:
        form = UpdateRecordForm(user=profile)

    if response_format == 'rss':
        return ObjectFeed(title=(_(module.title) + ' ' + _('Activity')),
                          link=request.path,
                          description=_('Updates on activity in your Tree.io'),
                          objects=updates)(request)

    context = _get_default_context(request)
    context.update({
        'form': form,
        'active_module': module,
        'updates': updates,
        'profile': profile,
        'module_name': module_name
    })

    return render_to_response('news/index_by_module',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#54
0
def settings_view(request, response_format='html'):
    "Settings admin view"

    # default content type
    try:
        conf = ModuleSetting.get_for_module('treeio.messaging',
                                            'default_contact_type',
                                            user=request.user.get_profile())[0]
        default_contact_type = ContactType.objects.get(pk=long(conf.value))
    except:
        default_contact_type = None

    # default imap folder
    try:
        conf = ModuleSetting.get_for_module('treeio.messaging',
                                            'default_imap_folder')[0]
        default_imap_folder = conf.value
    except:
        default_imap_folder = getattr(
            settings, 'HARDTREE_MESSAGING_IMAP_DEFAULT_FOLDER_NAME', 'UNSEEN')

    # signature
    try:
        conf = ModuleSetting.get_for_module('treeio.messaging',
                                            'signature',
                                            user=request.user.get_profile(),
                                            strict=True)[0]
        signature = conf.value
    except:
        signature = ''

    types = Object.filter_by_request(request,
                                     ContactType.objects.order_by('name'))

    context = _get_default_context(request)
    context.update({
        'types': types,
        'signature': signature,
        'default_contact_type': default_contact_type,
        'default_imap_folder': default_imap_folder
    })

    return render_to_response('messaging/settings_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#55
0
文件: views.py 项目: vovkd/treeio
def integration_index(request, response_format='html'):
    "Integration index page"

    user = request.user.get_profile()
    active_resources = ModuleSetting.get_for_module('treeio.identities',
                                                    'integration_resource',
                                                    user=user,
                                                    strict=True)

    conf = ModuleSetting.get('nuvius_profile', user=user, strict=True)
    try:
        profile = conf[0].loads()
    except IndexError:
        profile = None

    available_resources = []
    response = None
    if profile:
        connector = Connector(request, profile_id=profile['id'])
        response = connector.collect('/service/contact-book/contact/',
                                     no_cache=True)

        resources = getattr(response.data.info, 'applications', [])
        for resource in resources:
            active = [int(res.loads().resource_id) for res in active_resources]
            if not resource.id.raw in active:
                available_resources.append(resource)

    message = None
    if 'message' in request.session:
        message = request.session.get('message')
        del request.session['message']

    context = _get_default_context(request)
    context.update({
        'active_resources': active_resources,
        'available_resources': available_resources,
        'message': message,
        'response': response,
        'profile': profile
    })

    return render_to_response('identities/integration_index',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#56
0
文件: views.py 项目: vingodu/treeio
def settings_edit(request, response_format='html'):
    "Settings edit"

    if request.POST:
        if not 'cancel' in request.POST:
            form = SettingsForm(request.user.get_profile(), request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse('account_settings_view'))
        else:
            return HttpResponseRedirect(reverse('account_settings_view'))
    else:
        form = SettingsForm(request.user.get_profile())

    return render_to_response('account/settings_edit',
                              {'form': Markup(form.as_ul())},
                              context_instance=RequestContext(request), response_format=response_format)
示例#57
0
def service_record_index(request, response_format='html'):
    "Index page: displays all Items"
    query = Q()
    if request.GET:
        query = query & _get_filter_query(request.GET)
    service_records = Object.filter_by_request(
        request, ItemServicing.objects.filter(query))

    filters = FilterForm(request.user.get_profile(), '', request.GET)

    context = _get_default_context(request)
    context.update({'service_records': service_records, 'filters': filters})

    return render_to_response('infrastructure/service_record_index',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#58
0
def type_view(request, type_id, response_format='html'):
    "Contacts by type"

    contact_type = get_object_or_404(ContactType, pk=type_id)
    if not request.user.get_profile().has_permission(contact_type):
        return user_denied(
            request, message="You don't have access to this Contact Type")
    contacts = Object.filter_by_request(
        request, Contact.objects.filter(contact_type=contact_type))

    context = _get_default_context(request)
    context.update({'contacts': contacts, 'type': contact_type})

    return render_to_response('identities/contact_type_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#59
0
def location_view(request, location_id, response_format='html'):
    "Location view"
    location = get_object_or_404(Location, pk=location_id)
    if not request.user.get_profile().has_permission(location):
        return user_denied(request,
                           message="You don't have access to this Location",
                           response_format=response_format)

    context = _get_default_context(request)
    context.update({
        'location': location,
    })

    return render_to_response('identities/location_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#60
0
文件: views.py 项目: vovkd/treeio
def month_view(request, response_format='html'):
    "Month view - each cell represents a day"

    events = Object.filter_by_request(request, Event.objects)

    date_current = now = datetime.now()
    istoday = True

    gotoform = GoToDateForm(now, request.GET)
    if request.GET:
        if 'date_year' in request.GET and 'date_month' in request.GET:
            try:
                year = int(request.GET['date_year'])
                month = int(request.GET['date_month'])
                if year >= 1900 and month >= 1 and month <= 12:
                    date_current = datetime(year, month, 1)
                    istoday = date_current == now
            except Exception:
                pass
        if gotoform.is_valid() and gotoform.cleaned_data['goto']:
            date_current = gotoform.cleaned_data['goto']
            istoday = date_current == now
            now = datetime(date_current.year, date_current.month,
                           date_current.day)

    dates = calendar.Calendar().monthdatescalendar(date_current.year,
                                                   date_current.month)
    date_previous = date_current - relativedelta(months=+1)
    date_next = date_current + relativedelta(months=+1)

    wrapped_events = EventCollection(events)
    wrapped_events.collect_events(request)

    return render_to_response('events/month_view', {
        'events': wrapped_events,
        'dates': dates,
        'date_previous': date_previous,
        'date_next': date_next,
        'date_current': date_current,
        'gotoform': gotoform.as_ul(),
        'istoday': istoday,
        'now': now
    },
                              context_instance=RequestContext(request),
                              response_format=response_format)