Exemple #1
0
def remote_edit_metadata(request, entity_id):
    entity = get_object_or_404(Entity, id=entity_id)
    if request.method == 'POST':
        form = MetadataRemoteEditForm(entity, request.user, request.POST)
        if settings.MODERATION_ENABLED:
            if 'button_clicked' in request.POST and request.POST['button_clicked'] != '' and len(request.FILES) > 0:
                if 'submit_changes' == request.POST['button_clicked']:
                    if not can_edit_entity(request.user, entity):
                        raise PermissionDenied
                if 'approve_changes' == request.POST['button_clicked']:
                    if not can_approve_change(request.user, entity):
                        raise PermissionDenied
                if 'discard_changes' == request.POST['button_clicked']:
                    if not can_approve_change(request.user, entity):
                        raise PermissionDenied
        else:
            if not can_edit_entity(request.user, entity):
                        raise PermissionDenied
        result = _handle_metadata_post(request, form, 'entities:entity_view')
        if result is not None:
            return result
    else:
        form = None

    return edit_metadata(request, entity.id, edit_mode='remote',
                         remote_form=form)
Exemple #2
0
def remote_edit_metadata(request, entity_id):
    entity = get_object_or_404(Entity, id=entity_id)
    if request.method == 'POST':
        form = MetadataRemoteEditForm(entity, request.user, request.POST)
        if settings.MODERATION_ENABLED:
            if 'button_clicked' in request.POST and request.POST[
                    'button_clicked'] != '' and len(request.FILES) > 0:
                if 'submit_changes' == request.POST['button_clicked']:
                    if not can_edit_entity(request.user, entity):
                        raise PermissionDenied
                if 'update_changes' == request.POST['button_clicked']:
                    if not can_edit_entity(request.user, entity):
                        raise PermissionDenied
                if 'approve_changes' == request.POST['button_clicked']:
                    if not can_approve_change(request.user, entity):
                        raise PermissionDenied
                if 'discard_changes' == request.POST['button_clicked']:
                    if not can_approve_change(request.user, entity):
                        raise PermissionDenied
        else:
            if not can_edit_entity(request.user, entity):
                raise PermissionDenied
        result = _handle_metadata_post(request, form, 'entities:entity_view')
        if result is not None:
            return result
    else:
        form = None

    return edit_metadata(request,
                         entity.id,
                         edit_mode='remote',
                         remote_form=form)
Exemple #3
0
def edit_metadata(request,
                  entity_id,
                  edit_mode='text',
                  text_form=None,
                  file_form=None,
                  remote_form=None):
    entity = get_object_or_404(Entity, id=entity_id)
    if not can_edit_entity(request.user, entity):
        raise PermissionDenied

    samlmetajs_plugins = getattr(settings, 'SAML_META_JS_PLUGINS',
                                 DEFAULT_SAML_META_JS_PLUGINS)

    return render_to_response('entity/edit_metadata.html', {
        'entity':
        entity,
        'text_html':
        _get_edit_metadata_form(request, entity, 'text', form=text_form),
        'file_html':
        _get_edit_metadata_form(request, entity, 'file', form=file_form),
        'remote_html':
        _get_edit_metadata_form(request, entity, 'remote', form=remote_form),
        'edit_mode':
        edit_mode,
        'samlmetajs_plugins':
        samlmetajs_plugins,
        'needs_google_maps':
        False,
    },
                              context_instance=RequestContext(request))
Exemple #4
0
def remote_edit_metadata(request, entity_id):
    entity = get_object_or_404(Entity, id=entity_id)
    if not can_edit_entity(request.user, entity):
        raise PermissionDenied

    if request.method == 'POST':
        form = MetadataRemoteEditForm(entity, request.user, request.POST)
        result = _handle_metadata_post(request, form, 'remote_edit_metadata')
        if result is not None:
            return result
    else:
        form = None

    return edit_metadata(request, entity.id, edit_mode='remote',
                         remote_form=form)
Exemple #5
0
def entity_remove(request, entity_id):
    entity = get_object_or_404(Entity, id=entity_id)
    if not can_edit_entity(request.user, entity):
        raise PermissionDenied

    if request.method == 'POST':
        username = authorname(request.user)
        commit_msg = u'entity removed'
        entity.metadata.delete(username, commit_msg)
        entity.delete()
        messages.success(request, _('Entity removed succesfully'))
        return HttpResponseRedirect(reverse('entities_list'))

    return render_to_response('entity/remove.html', {
            'entity': entity,
            }, context_instance=RequestContext(request))
Exemple #6
0
def edit_metadata(request, entity_id, edit_mode='text',
                  text_form=None, file_form=None, remote_form=None):
    entity = get_object_or_404(Entity, id=entity_id)
    if not can_edit_entity(request.user, entity):
        raise PermissionDenied

    samlmetajs_plugins = getattr(settings, 'SAML_META_JS_PLUGINS',
                                 DEFAULT_SAML_META_JS_PLUGINS)

    return render_to_response('entity/edit_metadata.html', {
        'entity': entity,
        'text_html': _get_edit_metadata_form(request, entity, 'text',
                                             form=text_form),
        'file_html': _get_edit_metadata_form(request, entity, 'file',
                                             form=file_form),
        'remote_html': _get_edit_metadata_form(request, entity, 'remote',
                                               form=remote_form),
        'edit_mode': edit_mode,
        'samlmetajs_plugins': samlmetajs_plugins,
        'needs_google_maps': False,
    }, context_instance=RequestContext(request))
Exemple #7
0
def entity_remove(request, entity_id):
    entity = get_object_or_404(Entity, id=entity_id)
    if not can_edit_entity(request.user, entity):
        raise PermissionDenied

    if request.method == 'POST':
        username = authorname(request.user)
        commit_msg = u'entity removed'
        try:
            ent_md = EntityMD.objects.get(entity=entity)
            AttributesMD.objects.filter(entity_md=ent_md).delete()
            ent_md.delete()
        except EntityMD.DoesNotExist:
            pass
        entity.metadata.delete(username, commit_msg)
        entity.delete()
        messages.success(request, _('Entity removed succesfully'))
        return HttpResponseRedirect(reverse('entities:entities_list'))

    return render_to_response('entity/remove.html', {
        'entity': entity,
    },
                              context_instance=RequestContext(request))
Exemple #8
0
def metarefresh_edit(request, entity_id):
    entity = get_object_or_404(Entity, id=entity_id)
    if not can_edit_entity(request.user, entity):
        raise PermissionDenied

    if request.method == 'POST':
        form = EditMetarefreshForm(request.POST)
        if form.is_valid():
            entity.metarefresh_frequency = \
                form.cleaned_data['metarefresh_frequency']
            entity.save()
            messages.success(request, _('Metarefresh edited succesfully'))
            return HttpResponseRedirect(reverse('entities:metarefresh_edit',
                                                args=(entity_id,)))
        else:
            messages.error(request, _('Please correct the errors'
                                      ' indicated below'))
    else:
        form = EditMetarefreshForm(instance=entity)

    return render_to_response('entity/edit_metarefresh.html', {
        'entity': entity,
        'form': form,
    }, context_instance=RequestContext(request))