Exemplo n.º 1
0
def attachment_delete(request, attachment_id):

    try:
        a = Attachment.objects.get(pk=attachment_id)
    except Attachment.DoesNotExist:
        return

    profile = request.user.profile

    if a.attached_object:
        object_id = a.attached_object.id
        obj = Object.objects.get(pk=object_id)
    else:
        object_id = None

    update_id = None
    if a.attached_record:
        update_id = a.attached_record.id
        update = UpdateRecord.objects.get(pk=update_id)
        if not update.author == profile:
            return user_denied(
                request,
                message="Only the author of this Update can delete attachments."
            )

    elif not profile.has_permission(obj, mode='w'):
        return user_denied(request,
                           message="You don't have full access to this Object")

    a.delete()

    return attachment(request, object_id, update_id)
Exemplo n.º 2
0
Arquivo: ajax.py Projeto: tovmeod/anaf
def attachment_delete(request, attachment_id):

    try:
        a = Attachment.objects.get(pk=attachment_id)
    except Attachment.DoesNotExist:
        return

    profile = request.user.profile

    if a.attached_object:
        object_id = a.attached_object.id
        obj = Object.objects.get(pk=object_id)
    else:
        object_id = None

    update_id = None
    if a.attached_record:
        update_id = a.attached_record.id
        update = UpdateRecord.objects.get(pk=update_id)
        if not update.author == profile:
            return user_denied(request, message="Only the author of this Update can delete attachments.")

    elif not profile.has_permission(obj, mode='w'):
        return user_denied(request, message="You don't have full access to this Object")

    a.delete()

    return attachment(request, object_id, update_id)
Exemplo n.º 3
0
def mlist_view(request, mlist_id, response_format='html'):
    "Mailing List view page"

    user = request.user.profile

    mlist = get_object_or_404(MailingList, pk=mlist_id)
    if not request.user.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.profile.has_permission(mlist, mode='x'):
        if request.POST:
            message = Message()
            message.author = request.user.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.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.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)
Exemplo n.º 4
0
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.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.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)
Exemplo n.º 5
0
def document_edit(request, document_id, response_format='html'):
    "Document edit page"

    document = get_object_or_404(Document, pk=document_id)

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

    if request.POST:
        if 'cancel' not in request.POST:
            form = DocumentForm(
                request.user.profile, None, request.POST, instance=document)
            if form.is_valid():
                document = form.save()
                return HttpResponseRedirect(reverse('documents_document_view', args=[document.id]))
        else:
            return HttpResponseRedirect(reverse('documents_document_view', args=[document.id]))
    else:
        form = DocumentForm(
            request.user.profile, None, instance=document)

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

    return render_to_response('documents/document_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemplo n.º 6
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.profile,
                                    mode='r')

    if not request.user.profile.has_permission(category, mode="w"):
        return user_denied(
            request,
            message="You don't have access to this Knowledge Category")

    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                category.trash = True
                category.save()
            else:
                category.delete()
            return HttpResponseRedirect(reverse('knowledge_index'))
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(
                reverse('knowledge_category_view', args=[category.treepath]))

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

    return render_to_response('knowledge/category_delete',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemplo n.º 7
0
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.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)
Exemplo n.º 8
0
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.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)
Exemplo n.º 9
0
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.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)
Exemplo n.º 10
0
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.profile.has_permission(ticket, mode='w'):
        return user_denied(request, message="You don't have access to this Ticket")

    if request.POST:
        if 'cancel' not in request.POST:
            form = TicketForm(
                request.user.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.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)
Exemplo n.º 11
0
def queue_add(request, response_format='html'):
    "Queue add"

    if not request.user.profile.is_admin('anaf.services'):
        return user_denied(request,
                           message="You don't have administrator access to the Service Support module")

    if request.POST:
        if 'cancel' not in request.POST:
            queue = TicketQueue()
            form = QueueForm(
                request.user.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.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)
Exemplo n.º 12
0
def queue_delete(request, queue_id, response_format='html'):
    "Queue delete"

    queue = get_object_or_404(TicketQueue, pk=queue_id)
    if not request.user.profile.has_permission(queue, mode='w'):
        return user_denied(request, message="You don't have access to this Queue")

    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                queue.trash = True
                queue.save()
            else:
                queue.delete()
            return HttpResponseRedirect(reverse('services_settings_view'))
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('services_queue_view', args=[queue.id]))

    query = Q(queue=queue) & Q(status__hidden=False)
    tickets = Object.filter_by_request(request, Ticket.objects.filter(query))
    subqueues = Object.filter_by_request(
        request, TicketQueue.objects.filter(parent=queue))

    context = _get_default_context(request)
    context.update({'queue': queue,
                    'subqueues': subqueues,
                    'tickets': tickets})

    return render_to_response('services/queue_delete', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemplo n.º 13
0
def queue_view(request, queue_id, response_format='html'):
    "Queue view"

    queue = get_object_or_404(TicketQueue, pk=queue_id)
    if not request.user.profile.has_permission(queue):
        return user_denied(request, message="You don't have access to this Queue")

    query = Q(queue=queue)
    if request.GET:
        if 'status' in request.GET and request.GET['status']:
            query = query & _get_filter_query(request.GET)
        else:
            query = query & Q(
                status__hidden=False) & _get_filter_query(request.GET)
    else:
        query = query & Q(status__hidden=False)
    tickets = Object.filter_by_request(request, Ticket.objects.filter(query))

    filters = FilterForm(request.user.profile, 'queue', request.GET)
    subqueues = Object.filter_by_request(
        request, TicketQueue.objects.filter(parent=queue))

    context = _get_default_context(request)
    context.update({'queue': queue,
                    'subqueues': subqueues,
                    'filters': filters,
                    'tickets': tickets})

    return render_to_response('services/queue_view', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemplo n.º 14
0
def status_edit(request, status_id, response_format='html'):
    "TicketStatus edit"

    status = get_object_or_404(TicketStatus, pk=status_id)
    if not request.user.profile.has_permission(status, mode='w') \
            and not request.user.profile.is_admin('anaf'):
        return user_denied(request, "You don't have access to this Ticket Status", response_format)

    if request.POST:
        if 'cancel' not in request.POST:
            form = TicketStatusForm(
                request.user.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.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)
Exemplo n.º 15
0
def file_view(request, file_id, response_format='html'):
    "Single file view page"

    file = get_object_or_404(File, pk=file_id)

    if not request.user.profile.has_permission(file):
        return user_denied(request, message="You don't have access to this File")

    if request.GET and 'download' in request.GET:
        "Return url to download a file"
        fullpath = getattr(settings, 'MEDIA_ROOT', './static/media/')

        data = ''

        try:
            data = open(fullpath + str(file.content)).read()
        except IOError:
            pass

        response = HttpResponse(data, content_type='application/x-download')
        response[
            'Content-Disposition'] = 'attachment; filename="{0!s}"'.format(smart_str(file.content))
        return response

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

    return render_to_response('documents/file_view', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemplo n.º 16
0
def weblink_edit(request, weblink_id, response_format='html'):
    "WebLink edit page"

    link = get_object_or_404(WebLink, pk=weblink_id)

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

    if request.POST:
        if 'cancel' not in request.POST:
            form = WebLinkForm(
                request.user.profile, None, request.POST, instance=link)
            if form.is_valid():
                link = form.save()
                return HttpResponseRedirect(reverse('documents_weblink_view', args=[link.id]))
        else:
            return HttpResponseRedirect(reverse('documents_weblink_view', args=[link.id]))

    else:
        form = WebLinkForm(request.user.profile, None, instance=link)

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

    return render_to_response('documents/weblink_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemplo n.º 17
0
def service_edit(request, service_id, response_format='html'):
    "Service edit"

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

    if request.POST:
        if 'cancel' not in request.POST:
            form = ServiceForm(
                request.user.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.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)
Exemplo n.º 18
0
def field_edit(request, field_id, response_format='html'):
    "ContactField edit"

    field = get_object_or_404(ContactField, pk=field_id)
    if not request.user.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 'cancel' not 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)
Exemplo n.º 19
0
def sla_edit(request, sla_id, response_format='html'):
    "ServiceLevelAgreement edit"

    sla = get_object_or_404(ServiceLevelAgreement, pk=sla_id)
    if not request.user.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 'cancel' not in request.POST:
            form = ServiceLevelAgreementForm(
                request.user.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.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)
Exemplo n.º 20
0
def contact_delete(request, contact_id, response_format='html'):
    "Contact delete"

    contact = get_object_or_404(Contact, pk=contact_id)
    if not request.user.profile.has_permission(contact, mode='w'):
        return user_denied(request,
                           message="You don't have 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)
Exemplo n.º 21
0
def sla_add(request, response_format='html'):
    "ServiceLevelAgreement add"

    if not request.user.profile.is_admin('anaf.services'):
        return user_denied(request,
                           message="You don't have administrator access to the Service Support module")

    if request.POST:
        if 'cancel' not in request.POST:
            sla = ServiceLevelAgreement()
            form = ServiceLevelAgreementForm(
                request.user.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.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)
Exemplo n.º 22
0
def stream_edit(request, stream_id, response_format='html'):
    "Stream edit page"
    user = request.user.profile

    stream = get_object_or_404(MessageStream, pk=stream_id)
    if not request.user.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 'cancel' not 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)
Exemplo n.º 23
0
def type_edit(request, type_id, response_format='html'):
    "ContactType edit"

    contact_type = get_object_or_404(ContactType, pk=type_id)
    if not request.user.profile.has_permission(contact_type, mode='w'):
        return user_denied(request, message="You don't have access to this Contact Type",
                           response_format=response_format)
    identities = Object.filter_by_request(request,
                                          Contact.objects.filter(contact_type=contact_type).order_by('name'))

    if request.POST:
        if 'cancel' not in request.POST:
            form = ContactTypeForm(
                request.user.profile, request.POST, instance=contact_type)
            if form.is_valid():
                contact_type = form.save(request)
                return HttpResponseRedirect(reverse('identities_type_view', args=[contact_type.id]))
        else:
            return HttpResponseRedirect(reverse('identities_type_view', args=[contact_type.id]))
    else:
        form = ContactTypeForm(
            request.user.profile, instance=contact_type)

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

    return render_to_response('identities/contact_type_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemplo n.º 24
0
def stream_checkmail(request, stream_id, response_format='html'):
    "Stream check mail"
    user = request.user.profile

    stream = get_object_or_404(MessageStream, pk=stream_id)
    if not user.has_permission(stream):
        return user_denied(request,
                           message="You don't have access to this Stream",
                           response_format=response_format)

    try:
        stream.process_email()
        messages.add_message(request,
                             messages.INFO,
                             _("E-mails fetched successfully."),
                             fail_silently=True)
    except:
        try:
            messages.add_message(
                request,
                messages.ERROR,
                _("Failed to retrieve messages for this stream. Please check stream settings"
                  ),
                fail_silently=True)
        except:
            pass

    return HttpResponseRedirect(
        reverse('messaging_stream_view', args=[stream.id]))
Exemplo n.º 25
0
def field_edit(request, field_id, response_format='html'):
    "ContactField edit"

    field = get_object_or_404(ContactField, pk=field_id)
    if not request.user.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 'cancel' not 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)
Exemplo n.º 26
0
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.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)
Exemplo n.º 27
0
def field_add(request, response_format='html'):
    "ContactField add"

    if not request.user.profile.is_admin('anaf.identities'):
        return user_denied(request,
                           message="You don't have administrator access to the Infrastructure module",
                           response_format=response_format)

    if request.POST:
        if 'cancel' not 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)
Exemplo n.º 28
0
def folder_edit(request, folder_id, response_format='html'):
    "Folder edit page"

    folder = get_object_or_404(Folder, pk=folder_id)

    if not request.user.profile.has_permission(folder, mode='w'):
        return user_denied(request, message="You don't have access to this Folder")

    if request.POST:
        if 'cancel' not in request.POST:
            form = FolderForm(
                request.user.profile, folder_id, request.POST, instance=folder)
            if form.is_valid():
                folder = form.save()
                return HttpResponseRedirect(reverse('documents_folder_view', args=[folder.id]))
        else:
            return HttpResponseRedirect(reverse('documents_folder_view', args=[folder.id]))

    else:
        form = FolderForm(
            request.user.profile, folder_id, instance=folder)

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

    return render_to_response('documents/folder_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemplo n.º 29
0
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.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 'cancel' not in request.POST:
            form = ContactForm(
                request.user.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.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)
Exemplo n.º 30
0
def document_delete(request, document_id, response_format='html'):
    "Document delete"

    document = get_object_or_404(Document, pk=document_id)

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

    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                document.trash = True
                document.save()
            else:
                document.delete()
            return HttpResponseRedirect(reverse('document_index'))
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('documents_document_view', args=[document.id]))

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

    return render_to_response('documents/document_delete', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemplo n.º 31
0
def contact_view(request, contact_id, attribute='', response_format='html'):
    "Contact view"

    contact = get_object_or_404(Contact, pk=contact_id)
    if not request.user.profile.has_permission(contact):
        return user_denied(request, message="You don't have access to this Contact")
    types = Object.filter_by_request(
        request, ContactType.objects.order_by('name'))

    subcontacts = Object.filter_by_request(request, contact.child_set)
    contact_values = contact.contactvalue_set.order_by('field__name')

    objects = get_contact_objects(
        request.user.profile, contact, preformat=True)

    module = None
    for key in objects:
        if not attribute and objects[key]['count']:
            # attribute = objects[key]['objects'].keys()[0]
            module = objects[key]['module']
        elif attribute in objects[key]['objects'].keys():
            module = objects[key]['module']
            break

    return render_to_response('identities/contact_view',
                              {'contact': contact,
                               'subcontacts': subcontacts,
                               'objects': objects,
                               'current_module': module,
                               'attribute': attribute,
                               'types': types,
                               'contact_values': contact_values},
                              context_instance=RequestContext(request), response_format=response_format)
Exemplo n.º 32
0
def file_edit(request, file_id, response_format='html'):
    "File edit page"

    file = get_object_or_404(File, pk=file_id)
    if not request.user.profile.has_permission(file, mode='w'):
        return user_denied(request, message="You don't have access to this File")

    if request.POST:
        if 'cancel' not in request.POST:
            form = FileForm(
                request.user.profile, None, request.POST, request.FILES, instance=file)
            if form.is_valid():
                file = form.save()
                return HttpResponseRedirect(reverse('documents_file_view', args=[file.id]))
        else:
            return HttpResponseRedirect(reverse('documents_file_view', args=[file.id]))

    else:
        form = FileForm(request.user.profile, None, instance=file)

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

    return render_to_response('documents/file_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemplo n.º 33
0
def contact_edit(request, contact_id, response_format='html'):
    "Contact edit"

    contact = get_object_or_404(Contact, pk=contact_id)
    if not request.user.profile.has_permission(contact, mode='w'):
        return user_denied(request, message="You don't have write access to this Contact")

    if request.POST:
        if 'cancel' not in request.POST:
            form = ContactForm(request.user.profile, contact.contact_type, request.POST,
                               files=request.FILES, instance=contact)
            if form.is_valid():
                contact = form.save(request)
                return HttpResponseRedirect(reverse('identities_contact_view', args=[contact.id]))
        else:
            return HttpResponseRedirect(reverse('identities_contact_view', args=[contact.id]))
    else:
        form = ContactForm(
            request.user.profile, contact.contact_type, instance=contact)

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

    return render_to_response('identities/contact_edit',
                              {'contact': contact,
                               'types': types,
                               'form': form},
                              context_instance=RequestContext(request), response_format=response_format)
Exemplo n.º 34
0
def weblink_delete(request, weblink_id, response_format='html'):
    "WebLink delete"

    link = get_object_or_404(WebLink, pk=weblink_id)

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

    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                link.trash = True
                link.save()
            else:
                link.delete()
            return HttpResponseRedirect(reverse('document_index'))
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('documents_weblink_view', args=[link.id]))

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

    return render_to_response('documents/weblink_delete', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemplo n.º 35
0
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.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 'cancel' not in request.POST:
            form = LocationForm(
                request.user.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.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)
Exemplo n.º 36
0
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.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)
Exemplo n.º 37
0
def settings_view(request, response_format='html'):
    "Settings"

    if not request.user.profile.is_admin('anaf.identities'):
        return user_denied(request, message="You are not an Administrator of the Identities module",
                           response_format=response_format)

    contact_types = ContactType.objects.all().filter(trash=False)
    contact_fields = ContactField.objects.all().filter(trash=False)
    contacts = Object.filter_by_request(
        request, Contact.objects.order_by('name'))

    context = _get_default_context(request)
    context.update({'contact_types': contact_types,
                    'contact_fields': contact_fields,
                    'contacts': contacts})

    if request.POST and 'file' in request.FILES:
        csv_file = request.FILES['file']

        # TODO: check file extension
        content = csv_file.read()
        import_c = ProcessContacts()
        import_c.import_contacts(content)

        return HttpResponseRedirect(reverse('identities_index'))

    return render_to_response('identities/settings_view', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemplo n.º 38
0
def field_add(request, response_format='html'):
    "ContactField add"

    if not request.user.profile.is_admin('anaf.identities'):
        return user_denied(
            request,
            message=
            "You don't have administrator access to the Infrastructure module",
            response_format=response_format)

    if request.POST:
        if 'cancel' not 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)
Exemplo n.º 39
0
def settings_view(request, response_format='html'):
    "Settings"

    if not request.user.profile.is_admin('anaf.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('anaf.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)
Exemplo n.º 40
0
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.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 'cancel' not in request.POST:
            form = ContactForm(request.user.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.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)
Exemplo n.º 41
0
def service_record_add(request, response_format='html'):
    "New service_record form"

    if not request.user.profile.is_admin('anaf.infrastructure'):
        return user_denied(
            request,
            message=
            "You don't have administrator access to the Infrastructure module")

    service_record = ItemServicing()

    if request.POST:
        if 'cancel' not in request.POST:
            form = ServiceRecordForm(request.user.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.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)
Exemplo n.º 42
0
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.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 'cancel' not in request.POST:
            form = LocationForm(request.user.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.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)
Exemplo n.º 43
0
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.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)
Exemplo n.º 44
0
def settings_view(request, response_format='html'):
    "Settings"

    if not request.user.profile.is_admin('anaf.identities'):
        return user_denied(
            request,
            message="You are not an Administrator of the Identities module",
            response_format=response_format)

    contact_types = ContactType.objects.all().filter(trash=False)
    contact_fields = ContactField.objects.all().filter(trash=False)
    contacts = Object.filter_by_request(request,
                                        Contact.objects.order_by('name'))

    context = _get_default_context(request)
    context.update({
        'contact_types': contact_types,
        'contact_fields': contact_fields,
        'contacts': contacts
    })

    if request.POST and 'file' in request.FILES:
        csv_file = request.FILES['file']

        # TODO: check file extension
        content = csv_file.read()
        import_c = ProcessContacts()
        import_c.import_contacts(content)

        return HttpResponseRedirect(reverse('identities_index'))

    return render_to_response('identities/settings_view',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemplo n.º 45
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.profile.has_permission(folder, mode="w"):
        return user_denied(
            request, message="You don't have access to this Knowledge Type")

    if request.POST:
        if 'cancel' not in request.POST:
            form = KnowledgeFolderForm(request.user.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.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)
Exemplo n.º 46
0
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.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)
Exemplo n.º 47
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.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)
Exemplo n.º 48
0
def stream_edit(request, stream_id, response_format='html'):
    "Stream edit page"
    user = request.user.profile

    stream = get_object_or_404(MessageStream, pk=stream_id)
    if not request.user.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 'cancel' not 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)
Exemplo n.º 49
0
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.profile,
                                    mode='r')

    if not request.user.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)
Exemplo n.º 50
0
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.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)
Exemplo n.º 51
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.profile,
                                    mode='r')

    if not request.user.profile.has_permission(category, mode="w"):
        return user_denied(
            request,
            message="You don't have access to this Knowledge Category")

    if request.POST:
        if 'cancel' not in request.POST:
            form = KnowledgeCategoryForm(request.POST, instance=category)
            if form.is_valid():
                category = form.save()
                return HttpResponseRedirect(
                    reverse('knowledge_category_view',
                            args=[category.treepath]))
        else:
            return HttpResponseRedirect(
                reverse('knowledge_category_view', args=[category.treepath]))
    else:
        form = KnowledgeCategoryForm(instance=category)

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

    return render_to_response('knowledge/category_edit',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemplo n.º 52
0
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.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)
Exemplo n.º 53
0
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.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 'cancel' not in request.POST:
            form = ServiceRecordForm(
                request.user.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.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)