Example #1
0
def frontendadmin_delete(context, model_object, label=None):

    # Check if `model_object` is a model-instance
    if not isinstance(model_object, Model):
        raise template.TemplateSyntaxError, "'%s' argument must be a model-instance" % model_object

    app_label = model_object._meta.app_label
    model_name = model_object._meta.module_name

    template_context = {
        'delete_link':
        reverse('frontendadmin_delete',
                kwargs={
                    'app_label': app_label,
                    'model_name': model_name,
                    'instance_id': model_object.pk,
                }),
        'next_link':
        context['request'].META['PATH_INFO'],
        'label':
        label,
    }

    # Check for permission
    if check_permission(request=context['request'],
                        mode_name='delete',
                        app_label=app_label,
                        model_name=model_name):
        template_context['has_permission'] = True
    else:
        template_context['has_permission'] = False
    context.update(template_context)
    return context
Example #2
0
def frontendadmin_delete(context, model_object, label=None):
 
    # Check if `model_object` is a model-instance
    if not isinstance(model_object, Model):
        raise template.TemplateSyntaxError, "'%s' argument must be a model-instance" % model_object
 
    app_label = model_object._meta.app_label
    model_name = model_object._meta.module_name
 
    template_context = {
        'delete_link': reverse('frontendadmin_delete', kwargs={
            'app_label': app_label,
            'model_name': model_name,
            'instance_id': model_object.pk,
        }),
        'next_link': context['request'].META['PATH_INFO'],
        'label': label,
    }
 
    # Check for permission
    if check_permission(request=context['request'], mode_name='delete',
                                                    app_label=app_label,
                                                    model_name=model_name):
        template_context['has_permission'] = True
    else:
        template_context['has_permission'] = False
    context.update(template_context)
    return context
Example #3
0
def frontendadmin_add(context, queryset_object, label=None):

    # Check if `queryset_object` is a queryset
    if not isinstance(queryset_object, QuerySet):
        raise template.TemplateSyntaxError, "'%s' argument must be a queryset" % queryset_object

    app_label = queryset_object.model._meta.app_label
    model_name = queryset_object.model._meta.module_name

    template_context = {
        'add_link':
        reverse('frontendadmin_add',
                kwargs={
                    'app_label': app_label,
                    'model_name': model_name,
                }),
        'next_link':
        context['request'].META['PATH_INFO'],
        'label':
        label,
    }

    # Check for permission
    if check_permission(request=context['request'],
                        mode_name='add',
                        app_label=app_label,
                        model_name=model_name):
        template_context['has_permission'] = True
    else:
        template_context['has_permission'] = False
    context.update(template_context)
    return context
Example #4
0
def frontendadmin_add(context, queryset_object, label=None):
 
    # Check if `queryset_object` is a queryset
    if not isinstance(queryset_object, QuerySet):
        raise template.TemplateSyntaxError, "'%s' argument must be a queryset" % queryset_object
 
    app_label = queryset_object.model._meta.app_label
    model_name = queryset_object.model._meta.module_name
 
    template_context = {
        'add_link': reverse('frontendadmin_add', kwargs={
            'app_label': app_label,
            'model_name': model_name,
        }),
        'next_link': context['request'].META['PATH_INFO'],
        'label': label,
    }
 
    # Check for permission
    if check_permission(request=context['request'], mode_name='add',
                                                    app_label=app_label,
                                                    model_name=model_name):
        template_context['has_permission'] = True
    else:
        template_context['has_permission'] = False
    context.update(template_context)
    return context
def frontendadmin_delete(context, model_object, label=None):

    # Check if `model_object` is a model-instance
    if not isinstance(model_object, Model):
        raise template.TemplateSyntaxError("'%s' argument must be a model-instance" % model_object)

    app_label = model_object._meta.app_label
    model_name = model_object._meta.module_name

    template_context = {
        "delete_link": reverse(
            "frontendadmin_delete",
            kwargs={"app_label": app_label, "model_name": model_name, "instance_id": model_object.pk},
        ),
        "next_link": context["request"].META["PATH_INFO"],
        "label": label,
    }

    # Check for permission
    if check_permission(request=context["request"], mode_name="delete", app_label=app_label, model_name=model_name):
        template_context["has_permission"] = True
    else:
        template_context["has_permission"] = False
    context.update(template_context)
    return context
Example #6
0
def _get_instance(request,
                  mode_name,
                  app_label,
                  model_name,
                  instance_id=None,
                  form=None,
                  form_fields=None,
                  form_exclude=None):
    '''
    Returns the model and an instance_form for the given arguments. If an primary
    key (instance_id) is given, it will return also the instance.

    If the user has no permission to add, change or delete the object, a
    HttpResponse is returned.
    '''
    # Check for permission to add/change/delete this object
    if not check_permission(request, mode_name, app_label, model_name):
        return HttpResponseForbidden('You have no permission to do this!')

    try:
        model = get_model(app_label, model_name)
    # Model does not exist
    except AttributeError:
        return HttpResponseForbidden('This model does not exist!')
    label = '%s.%s' % (app_label, model_name)
    # get form for model
    if label in FORMS and not form:
        form = import_function(FORMS[label])
    elif model in site._registry and not form:
        form = site._registry[model].form
    elif form is None:
        form = FrontendAdminModelForm

    if label in EXCLUDES:
        form_exclude = EXCLUDES[label]
    if label in FIELDS:
        form_fields = FIELDS[label]

    instance_form = modelform_factory(model,
                                      form=form,
                                      fields=form_fields,
                                      exclude=form_exclude)
    # if instance_id is set, grab this model object
    if instance_id:
        instance = model.objects.get(pk=instance_id)
        return model, instance_form, instance
    return model, instance_form
def frontendadmin_add(context, queryset_object, label=None):

    # Check if `queryset_object` is a queryset
    if not isinstance(queryset_object, QuerySet):
        raise template.TemplateSyntaxError, "'%s' argument must be a queryset" % queryset_object

    app_label = queryset_object.model._meta.app_label
    model_name = queryset_object.model._meta.module_name

    template_context = {
        "add_link": reverse("frontendadmin_add", kwargs={"app_label": app_label, "model_name": model_name}),
        "next_link": context["request"].META["PATH_INFO"],
        "label": label,
    }

    # Check for permission
    if check_permission(request=context["request"], mode_name="add", app_label=app_label, model_name=model_name):
        template_context["has_permission"] = True
    context.update(template_context)
    return context
Example #8
0
def _get_instance(request, mode_name, app_label, model_name, instance_id=None,
                                            form=None,
                                            form_fields=None,
                                            form_exclude=None):
    '''
    Returns the model and an instance_form for the given arguments. If an primary
    key (instance_id) is given, it will return also the instance.

    If the user has no permission to add, change or delete the object, a
    HttpResponse is returned.
    '''
    # Check for permission to add/change/delete this object
    if not check_permission(request, mode_name, app_label, model_name):
        return HttpResponseForbidden('You have no permission to do this!')

    try:
        model = get_model(app_label, model_name)
    # Model does not exist
    except AttributeError:
        return HttpResponseForbidden('This model does not exist!')
    label = '%s.%s' % (app_label, model_name)
    # get form for model
    if label in FORMS and not form:
        form = import_function(FORMS[label])
    elif model in site._registry and not form:
        form = site._registry[model].form
    elif form is None:
        form = FrontendAdminModelForm
    
    if label in EXCLUDES:
        form_exclude = EXCLUDES[label]
    if label in FIELDS:
        form_fields = FIELDS[label]

    instance_form = modelform_factory(model, form=form,
                                      fields=form_fields, exclude=form_exclude)
    # if instance_id is set, grab this model object
    if instance_id:
        instance = model.objects.get(pk=instance_id)
        return model, instance_form, instance
    return model, instance_form