Пример #1
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('{0!s}&{1!s}'.format(
                    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')
Пример #2
0
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)
Пример #3
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('{0!s}&{1!s}'.format(
                    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')
Пример #4
0
def widget_contact_me(request, response_format='html'):
    "My Contact card"

    contact = request.user.profile.get_contact()
    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'))
    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
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)
Пример #6
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)
Пример #7
0
def widget_news_social(request, response_format='html'):
    "Widget: Social Activity"

    profile = request.user.profile
    query = _get_filter_query(profile) & Q(record_type='share')
    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('core_dashboard_index'))
    else:
        form = UpdateRecordForm(user=profile)

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

    return render_to_response('news/widgets/social', context,
                              context_instance=RequestContext(request), response_format=response_format)
Пример #8
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)
Пример #9
0
def weblink_add(request, response_format='html'):
    "New web link form"

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

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

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

    return render_to_response('documents/weblink_add', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Пример #10
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)
Пример #11
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)
Пример #12
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)
Пример #13
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)
Пример #14
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)
Пример #15
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)
Пример #16
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)
Пример #17
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)
Пример #18
0
def location_add(request, response_format='html'):
    "New location form"

    if request.POST:
        if 'cancel' not in request.POST:
            location = Location()
            form = LocationForm(request.user.profile,
                                None,
                                request.POST,
                                instance=location)
            if form.is_valid():
                location = form.save()
                location.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('identities_location_view', args=[location.id]))
        else:
            return HttpResponseRedirect(reverse('identities_index'))
    else:
        form = LocationForm(request.user.profile, None)

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

    return render_to_response('identities/location_add',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Пример #19
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)
Пример #20
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)
Пример #21
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)
Пример #22
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)
Пример #23
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)
Пример #24
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)
Пример #25
0
def my_watchlist(request, response_format='html'):
    "Displays news about all objects a User is subscribed to"

    profile = request.user.profile
    query = _get_filter_query(profile, do_recipients=False, filters=request.GET) & Q(
        about__in=profile.subscriptions.all()) & ~Q(author=profile)
    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(commit=False)
            record.body = record.body.replace('\n', ' <br />')
            record.save()
            record.set_user_from_request(request)
            return HttpResponseRedirect(reverse('news_index'))
    else:
        form = UpdateRecordForm(user=profile)

    if response_format == 'rss':
        return ObjectFeed(title=_('My Watchlist'),
                          link=request.path,
                          description=_(
                              'Updates on your watchlist in Anaf'),
                          objects=updates)(request)

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

    return render_to_response('news/my_watchlist', context,
                              context_instance=RequestContext(request), response_format=response_format)
Пример #26
0
def weblink_add_typed(request, folder_id=None, response_format='html'):
    "Web link add to preselected folder"

    folder = None
    if folder_id:
        folder = get_object_or_404(Folder, pk=folder_id)
        if not request.user.profile.has_permission(folder, mode='x'):
            folder = None

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

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

    return render_to_response('documents/weblink_add_typed', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Пример #27
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)
Пример #28
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)
Пример #29
0
def item_add(request, response_format='html'):
    "Add new knowledge item"
    items = Object.filter_permitted(manager=KnowledgeItem.objects,
                                    user=request.user.profile,
                                    mode='r')

    if request.POST:
        if 'cancel' not in request.POST:
            item = KnowledgeItem()
            form = KnowledgeItemForm(request.user.profile,
                                     None,
                                     request.POST,
                                     instance=item)
            if form.is_valid():
                item = form.save()
                item.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('knowledge_item_view',
                            args=[item.folder.treepath, item.treepath]))
        else:
            return HttpResponseRedirect(reverse('knowledge'))
    else:
        form = KnowledgeItemForm(request.user.profile, None)

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

    return render_to_response('knowledge/item_add',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Пример #30
0
def widget_news_index(request, response_format='html'):
    "Widget: All Activity"

    profile = request.user.profile
    query = _get_filter_query(profile) & (
        ~Q(author=profile) | Q(record_type='share') | Q(score__gt=0))
    updates = UpdateRecord.objects.filter(query).distinct()

    # don't do updates if social widget is used
    if Widget.objects.filter(user=profile, widget_name='widget_news_social').exists():
        form = None

    else:
        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('core_dashboard_index'))
        else:
            form = UpdateRecordForm(user=profile)

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

    return render_to_response('news/widgets/index', context,
                              context_instance=RequestContext(request), response_format=response_format)
Пример #31
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)
Пример #32
0
def index(request, response_format='html'):
    "Default index page"

    profile = request.user.profile
    query = _get_filter_query(profile, filters=request.GET)
    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'))
    else:
        form = UpdateRecordForm(user=profile)

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

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

    return render_to_response('news/index', context,
                              context_instance=RequestContext(request), response_format=response_format)
Пример #33
0
def category_add(request, response_format='html'):
    "Add new knowledge category"

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

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

    return render_to_response('knowledge/category_add',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Пример #34
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)
Пример #35
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)
Пример #36
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)
Пример #37
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)
Пример #38
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)
Пример #39
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)
Пример #40
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)
Пример #41
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)
Пример #42
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)
Пример #43
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)
Пример #44
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)
Пример #45
0
def file_upload_typed(request, folder_id=None, response_format='html'):
    "File upload to preselected folder"

    folder = None
    if folder_id:
        folder = get_object_or_404(Folder, pk=folder_id)
        if not request.user.profile.has_permission(folder, mode='x'):
            folder = None

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

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

    return render_to_response('documents/file_upload_typed', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Пример #46
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)
Пример #47
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)
Пример #48
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)
Пример #49
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)