mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Introduced consolidated object table template
This commit is contained in:
@@ -159,6 +159,7 @@ def aggregate(request, pk):
|
|||||||
child_prefixes = add_available_prefixes(aggregate.prefix, child_prefixes)
|
child_prefixes = add_available_prefixes(aggregate.prefix, child_prefixes)
|
||||||
|
|
||||||
prefix_table = PrefixTable(child_prefixes)
|
prefix_table = PrefixTable(child_prefixes)
|
||||||
|
prefix_table.model = Prefix
|
||||||
if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'):
|
if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'):
|
||||||
prefix_table.base_columns['pk'].visible = True
|
prefix_table.base_columns['pk'].visible = True
|
||||||
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator})\
|
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator})\
|
||||||
@@ -262,6 +263,7 @@ def prefix(request, pk):
|
|||||||
if child_prefixes:
|
if child_prefixes:
|
||||||
child_prefixes = add_available_prefixes(prefix.prefix, child_prefixes)
|
child_prefixes = add_available_prefixes(prefix.prefix, child_prefixes)
|
||||||
child_prefix_table = PrefixTable(child_prefixes)
|
child_prefix_table = PrefixTable(child_prefixes)
|
||||||
|
child_prefix_table.model = Prefix
|
||||||
if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'):
|
if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'):
|
||||||
child_prefix_table.base_columns['pk'].visible = True
|
child_prefix_table.base_columns['pk'].visible = True
|
||||||
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator})\
|
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator})\
|
||||||
@@ -337,6 +339,7 @@ def prefix_ipaddresses(request, pk):
|
|||||||
.select_related('vrf', 'interface__device', 'primary_for')
|
.select_related('vrf', 'interface__device', 'primary_for')
|
||||||
|
|
||||||
ip_table = IPAddressTable(ipaddresses)
|
ip_table = IPAddressTable(ipaddresses)
|
||||||
|
ip_table.model = IPAddress
|
||||||
if request.user.has_perm('ipam.change_ipaddress') or request.user.has_perm('ipam.delete_ipaddress'):
|
if request.user.has_perm('ipam.change_ipaddress') or request.user.has_perm('ipam.delete_ipaddress'):
|
||||||
ip_table.base_columns['pk'].visible = True
|
ip_table.base_columns['pk'].visible = True
|
||||||
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator})\
|
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator})\
|
||||||
|
@@ -71,7 +71,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
{% include 'ipam/inc/prefix_table.html' with table=prefix_table table_template='panel_table.html' heading='Child Prefixes' %}
|
{% include 'utilities/obj_table.html' with table=prefix_table table_template='panel_table.html' heading='Child Prefixes' bulk_edit_url='ipam:prefix_bulk_edit' bulk_delete_url='ipam:prefix_bulk_delete' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
<h1>Aggregates</h1>
|
<h1>Aggregates</h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
{% include 'ipam/inc/aggregate_table.html' %}
|
{% include 'utilities/obj_table.html' with bulk_edit_url='ipam:aggregate_bulk_edit' bulk_delete_url='ipam:aggregate_bulk_delete' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
{% include 'inc/filter_panel.html' %}
|
{% include 'inc/filter_panel.html' %}
|
||||||
|
@@ -1,22 +0,0 @@
|
|||||||
{% load render_table from django_tables2 %}
|
|
||||||
{% if perms.ipam.change_aggregate or perms.ipam.delete_aggregate %}
|
|
||||||
<form method="post" class="form form-horizontal">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input type="hidden" name="redirect_url" value="{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" />
|
|
||||||
{% render_table table table_template|default:'table.html' %}
|
|
||||||
{% if perms.ipam.change_aggregate %}
|
|
||||||
<button type="submit" name="_edit" formaction="{% url 'ipam:aggregate_bulk_edit' %}" class="btn btn-warning btn-sm">
|
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
|
||||||
Edit Selected
|
|
||||||
</button>
|
|
||||||
{% endif %}
|
|
||||||
{% if perms.ipam.delete_aggregate %}
|
|
||||||
<button type="submit" name="_delete" formaction="{% url 'ipam:aggregate_bulk_delete' %}" class="btn btn-danger btn-sm">
|
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
|
||||||
Delete Selected
|
|
||||||
</button>
|
|
||||||
{% endif %}
|
|
||||||
</form>
|
|
||||||
{% else %}
|
|
||||||
{% render_table table table_template|default:'table.html' %}
|
|
||||||
{% endif %}
|
|
@@ -1,22 +0,0 @@
|
|||||||
{% load render_table from django_tables2 %}
|
|
||||||
{% if perms.ipam.change_ipaddress or perms.ipam.delete_ipaddress %}
|
|
||||||
<form method="post" class="form form-horizontal">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input type="hidden" name="redirect_url" value="{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" />
|
|
||||||
{% render_table table table_template|default:'table.html' %}
|
|
||||||
{% if perms.ipam.change_ipaddress %}
|
|
||||||
<button type="submit" name="_edit" formaction="{% url 'ipam:ipaddress_bulk_edit' %}" class="btn btn-warning btn-sm">
|
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
|
||||||
Edit Selected
|
|
||||||
</button>
|
|
||||||
{% endif %}
|
|
||||||
{% if perms.ipam.delete_ipaddress %}
|
|
||||||
<button type="submit" name="_delete" formaction="{% url 'ipam:ipaddress_bulk_delete' %}" class="btn btn-danger btn-sm">
|
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
|
||||||
Delete Selected
|
|
||||||
</button>
|
|
||||||
{% endif %}
|
|
||||||
</form>
|
|
||||||
{% else %}
|
|
||||||
{% render_table table table_template|default:'table.html' %}
|
|
||||||
{% endif %}
|
|
@@ -1,22 +0,0 @@
|
|||||||
{% load render_table from django_tables2 %}
|
|
||||||
{% if perms.ipam.change_prefix or perms.ipam.delete_prefix %}
|
|
||||||
<form method="post" class="form form-horizontal">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input type="hidden" name="redirect_url" value="{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" />
|
|
||||||
{% render_table table table_template|default:'table.html' %}
|
|
||||||
{% if perms.ipam.change_prefix %}
|
|
||||||
<button type="submit" name="_edit" formaction="{% url 'ipam:prefix_bulk_edit' %}" class="btn btn-warning btn-sm">
|
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
|
||||||
Edit Selected
|
|
||||||
</button>
|
|
||||||
{% endif %}
|
|
||||||
{% if perms.ipam.delete_prefix %}
|
|
||||||
<button type="submit" name="_delete" formaction="{% url 'ipam:prefix_bulk_delete' %}" class="btn btn-danger btn-sm">
|
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
|
||||||
Delete Selected
|
|
||||||
</button>
|
|
||||||
{% endif %}
|
|
||||||
</form>
|
|
||||||
{% else %}
|
|
||||||
{% render_table table table_template|default:'table.html' %}
|
|
||||||
{% endif %}
|
|
@@ -1,14 +0,0 @@
|
|||||||
{% load render_table from django_tables2 %}
|
|
||||||
{% if perms.ipam.delete_rir %}
|
|
||||||
<form method="post" class="form form-horizontal">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input type="hidden" name="redirect_url" value="{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" />
|
|
||||||
{% render_table table table_template|default:'table.html' %}
|
|
||||||
<button type="submit" name="_delete" formaction="{% url 'ipam:rir_bulk_delete' %}" class="btn btn-danger btn-sm">
|
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
|
||||||
Delete Selected
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
{% else %}
|
|
||||||
{% render_table table table_template|default:'table.html' %}
|
|
||||||
{% endif %}
|
|
@@ -1,22 +0,0 @@
|
|||||||
{% load render_table from django_tables2 %}
|
|
||||||
{% if perms.ipam.change_vlan or perms.ipam.delete_vlan %}
|
|
||||||
<form method="post" class="form form-horizontal">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input type="hidden" name="redirect_url" value="{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" />
|
|
||||||
{% render_table table table_template|default:'table.html' %}
|
|
||||||
{% if perms.ipam.change_vlan %}
|
|
||||||
<button type="submit" name="_edit" formaction="{% url 'ipam:vlan_bulk_edit' %}" class="btn btn-warning btn-sm">
|
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
|
||||||
Edit Selected
|
|
||||||
</button>
|
|
||||||
{% endif %}
|
|
||||||
{% if perms.ipam.delete_vlan %}
|
|
||||||
<button type="submit" name="_delete" formaction="{% url 'ipam:vlan_bulk_delete' %}" class="btn btn-danger btn-sm">
|
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
|
||||||
Delete Selected
|
|
||||||
</button>
|
|
||||||
{% endif %}
|
|
||||||
</form>
|
|
||||||
{% else %}
|
|
||||||
{% render_table table table_template|default:'table.html' %}
|
|
||||||
{% endif %}
|
|
@@ -33,7 +33,7 @@
|
|||||||
<h1>IP Addresses</h1>
|
<h1>IP Addresses</h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
{% include 'ipam/inc/ipaddress_table.html' %}
|
{% include 'utilities/obj_table.html' with bulk_edit_url='ipam:ipaddress_bulk_edit' bulk_delete_url='ipam:ipaddress_bulk_delete' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
|
@@ -97,7 +97,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
{% if child_prefix_table.rows %}
|
{% if child_prefix_table.rows %}
|
||||||
{% include 'ipam/inc/prefix_table.html' with table=child_prefix_table table_template='panel_table.html' heading='Child Prefixes' parent=prefix %}
|
{% include 'utilities/obj_table.html' with table=child_prefix_table table_template='panel_table.html' heading='Child Prefixes' parent=prefix bulk_edit_url='ipam:prefix_bulk_edit' bulk_delete_url='ipam:prefix_bulk_delete' %}
|
||||||
{% elif prefix.new_subnet %}
|
{% elif prefix.new_subnet %}
|
||||||
<a href="{% url 'ipam:prefix_add' %}?prefix={{ prefix.new_subnet }}{% if prefix.vrf %}&vrf={{ prefix.vrf.pk }}{% endif %}{% if prefix.site %}&site={{ prefix.site.pk }}{% endif %}" class="btn btn-success">
|
<a href="{% url 'ipam:prefix_add' %}?prefix={{ prefix.new_subnet }}{% if prefix.vrf %}&vrf={{ prefix.vrf.pk }}{% endif %}{% if prefix.site %}&site={{ prefix.site.pk }}{% endif %}" class="btn btn-success">
|
||||||
<i class="glyphicon glyphicon-plus" aria-hidden="true"></i> Add Child Prefix
|
<i class="glyphicon glyphicon-plus" aria-hidden="true"></i> Add Child Prefix
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
{% include 'ipam/inc/prefix_header.html' with active_tab='ip-addresses' %}
|
{% include 'ipam/inc/prefix_header.html' with active_tab='ip-addresses' %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
{% include 'ipam/inc/ipaddress_table.html' with table=ip_table table_template='panel_table.html' heading='IP Addresses' %}
|
{% include 'utilities/obj_table.html' with table=ip_table table_template='panel_table.html' heading='IP Addresses' bulk_edit_url='ipam:ipaddress_bulk_edit' bulk_delete_url='ipam:ipaddress_bulk_delete' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -7,11 +7,11 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
{% if perms.ipam.add_prefix %}
|
{% if perms.ipam.add_prefix %}
|
||||||
<a href="{% url 'ipam:prefix_add' %}" class="btn btn-primary">
|
<a href="{{ action_urls.add }}" class="btn btn-primary">
|
||||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||||
Add a prefix
|
Add a prefix
|
||||||
</a>
|
</a>
|
||||||
<a href="{% url 'ipam:prefix_import' %}" class="btn btn-info">
|
<a href="{{ action_urls.import }}" class="btn btn-info">
|
||||||
<span class="glyphicon glyphicon-import" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-import" aria-hidden="true"></span>
|
||||||
Import prefixes
|
Import prefixes
|
||||||
</a>
|
</a>
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<h1>Prefixes</h1>
|
<h1>Prefixes</h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
{% include 'ipam/inc/prefix_table.html' %}
|
{% include 'utilities/obj_table.html' with bulk_edit_url='ipam:prefix_bulk_edit' bulk_delete_url='ipam:prefix_bulk_delete' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
<h1>RIRs</h1>
|
<h1>RIRs</h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
{% include 'ipam/inc/rir_table.html' %}
|
{% include 'utilities/obj_table.html' with bulk_delete_url='ipam:rir_bulk_delete' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
<h1>VLANs</h1>
|
<h1>VLANs</h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
{% include 'ipam/inc/vlan_table.html' %}
|
{% include 'utilities/obj_table.html' with bulk_edit_url='ipam:vlan_bulk_edit' bulk_delete_url='ipam:vlan_bulk_delete' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
<h1>VRFs</h1>
|
<h1>VRFs</h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
{% include 'ipam/inc/vrf_table.html' %}
|
{% include 'utilities/obj_table.html' with bulk_edit_url='ipam:vrf_bulk_edit' bulk_delete_url='ipam:vrf_bulk_delete' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
|
@@ -1,17 +1,18 @@
|
|||||||
{% load render_table from django_tables2 %}
|
{% load render_table from django_tables2 %}
|
||||||
{% if perms.ipam.change_vrf or perms.ipam.delete_vrf %}
|
{% load helpers %}
|
||||||
|
{% if table.model|user_can_change:request.user or table.model|user_can_delete:request.user %}
|
||||||
<form method="post" class="form form-horizontal">
|
<form method="post" class="form form-horizontal">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="redirect_url" value="{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" />
|
<input type="hidden" name="redirect_url" value="{{ request.path }}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" />
|
||||||
{% render_table table table_template|default:'table.html' %}
|
{% render_table table table_template|default:'table.html' %}
|
||||||
{% if perms.ipam.change_vrf %}
|
{% if bulk_edit_url and table.model|user_can_change:request.user %}
|
||||||
<button type="submit" name="_edit" formaction="{% url 'ipam:vrf_bulk_edit' %}" class="btn btn-warning btn-sm">
|
<button type="submit" name="_edit" formaction="{% url bulk_edit_url %}" class="btn btn-warning btn-sm">
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||||
Edit Selected
|
Edit Selected
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if perms.ipam.delete_vrf %}
|
{% if bulk_delete_url and table.model|user_can_delete:request.user %}
|
||||||
<button type="submit" name="_delete" formaction="{% url 'ipam:vrf_bulk_delete' %}" class="btn btn-danger btn-sm">
|
<button type="submit" name="_delete" formaction="{% url bulk_delete_url %}" class="btn btn-danger btn-sm">
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
||||||
Delete Selected
|
Delete Selected
|
||||||
</button>
|
</button>
|
@@ -11,7 +11,7 @@ register = template.Library()
|
|||||||
# Filters
|
# Filters
|
||||||
#
|
#
|
||||||
|
|
||||||
@register.filter(name='oneline')
|
@register.filter()
|
||||||
def oneline(value):
|
def oneline(value):
|
||||||
"""
|
"""
|
||||||
Replace each line break with a single space
|
Replace each line break with a single space
|
||||||
@@ -19,7 +19,7 @@ def oneline(value):
|
|||||||
return value.replace('\n', ' ')
|
return value.replace('\n', ' ')
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name='getlist')
|
@register.filter()
|
||||||
def getlist(value, arg):
|
def getlist(value, arg):
|
||||||
"""
|
"""
|
||||||
Return all values of a QueryDict key
|
Return all values of a QueryDict key
|
||||||
@@ -27,7 +27,7 @@ def getlist(value, arg):
|
|||||||
return value.getlist(arg)
|
return value.getlist(arg)
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name='gfm', is_safe=True)
|
@register.filter(is_safe=True)
|
||||||
def gfm(value):
|
def gfm(value):
|
||||||
"""
|
"""
|
||||||
Render text as GitHub-Flavored Markdown
|
Render text as GitHub-Flavored Markdown
|
||||||
@@ -36,11 +36,29 @@ def gfm(value):
|
|||||||
return mark_safe(html)
|
return mark_safe(html)
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter()
|
||||||
|
def user_can_add(model, user):
|
||||||
|
perm_name = '{}:add_{}'.format(model._meta.app_label, model.__class__.__name__.lower())
|
||||||
|
return user.has_perm(perm_name)
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter()
|
||||||
|
def user_can_change(model, user):
|
||||||
|
perm_name = '{}:change_{}'.format(model._meta.app_label, model.__class__.__name__.lower())
|
||||||
|
return user.has_perm(perm_name)
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter()
|
||||||
|
def user_can_delete(model, user):
|
||||||
|
perm_name = '{}:delete_{}'.format(model._meta.app_label, model.__class__.__name__.lower())
|
||||||
|
return user.has_perm(perm_name)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Tags
|
# Tags
|
||||||
#
|
#
|
||||||
|
|
||||||
@register.simple_tag(name='querystring_toggle')
|
@register.simple_tag()
|
||||||
def querystring_toggle(request, multi=True, page_key='page', **kwargs):
|
def querystring_toggle(request, multi=True, page_key='page', **kwargs):
|
||||||
"""
|
"""
|
||||||
Add or remove a parameter in the HTTP GET query string
|
Add or remove a parameter in the HTTP GET query string
|
||||||
|
@@ -2,7 +2,7 @@ from django.conf import settings
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.admin.views.decorators import staff_member_required
|
from django.contrib.admin.views.decorators import staff_member_required
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse, NoReverseMatch
|
||||||
from django.db import transaction, IntegrityError
|
from django.db import transaction, IntegrityError
|
||||||
from django.db.models import ProtectedError
|
from django.db.models import ProtectedError
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
@@ -31,7 +31,8 @@ class ObjectListView(View):
|
|||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
||||||
object_ct = ContentType.objects.get_for_model(self.queryset.model)
|
model = self.queryset.model
|
||||||
|
object_ct = ContentType.objects.get_for_model(model)
|
||||||
|
|
||||||
if self.filter:
|
if self.filter:
|
||||||
self.queryset = self.filter(request.GET, self.queryset).qs
|
self.queryset = self.filter(request.GET, self.queryset).qs
|
||||||
@@ -58,17 +59,16 @@ class ObjectListView(View):
|
|||||||
|
|
||||||
# Construct the table based on the user's permissions
|
# Construct the table based on the user's permissions
|
||||||
table = self.table(self.queryset)
|
table = self.table(self.queryset)
|
||||||
|
table.model = model
|
||||||
if 'pk' in table.base_columns and any([request.user.has_perm(perm) for perm in self.edit_permissions]):
|
if 'pk' in table.base_columns and any([request.user.has_perm(perm) for perm in self.edit_permissions]):
|
||||||
table.base_columns['pk'].visible = True
|
table.base_columns['pk'].visible = True
|
||||||
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator})\
|
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator})\
|
||||||
.configure(table)
|
.configure(table)
|
||||||
|
|
||||||
export_templates = ExportTemplate.objects.filter(content_type=object_ct)
|
|
||||||
|
|
||||||
return render(request, self.template_name, {
|
return render(request, self.template_name, {
|
||||||
'table': table,
|
'table': table,
|
||||||
'filter_form': self.filter_form(request.GET, label_suffix='') if self.filter_form else None,
|
'filter_form': self.filter_form(request.GET, label_suffix='') if self.filter_form else None,
|
||||||
'export_templates': export_templates,
|
'export_templates': ExportTemplate.objects.filter(content_type=object_ct),
|
||||||
})
|
})
|
||||||
|
|
||||||
def alter_queryset(self, request):
|
def alter_queryset(self, request):
|
||||||
|
Reference in New Issue
Block a user