...
 
Commits (2)
......@@ -209,7 +209,16 @@ class LavaTable(tables.Table):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.length = settings.DEFAULT_TABLE_LENGTH
self.request = kwargs.pop("request", None)
if (
self.request
and self.request.user.is_authenticated
and hasattr(self.request.user, "extendeduser")
and self.request.user.extendeduser.table_length
):
self.length = self.request.user.extendeduser.table_length
else:
self.length = settings.DEFAULT_TABLE_LENGTH
self._empty_text = mark_safe(
'<div style="text-align: center">No data available in table</div>'
)
......
......@@ -100,7 +100,7 @@ class SuiteView(LavaView):
@BreadCrumb("Results", parent=lava_index)
def index(request):
data = ResultsView(request, model=TestSuite, table_class=ResultsTable)
result_table = ResultsIndexTable(data.get_table_data())
result_table = ResultsIndexTable(data.get_table_data(), request=request)
RequestConfig(request, paginate={"per_page": result_table.length}).configure(
result_table
)
......@@ -131,7 +131,9 @@ def query(request):
def testjob(request, job):
job = get_restricted_job(request.user, pk=job, request=request)
data = ResultsView(request, model=TestSuite, table_class=TestJobResultsTable)
suite_table = TestJobResultsTable(data.get_table_data().filter(job=job))
suite_table = TestJobResultsTable(
data.get_table_data().filter(job=job), request=request
)
failed_definitions = []
yaml_dict = OrderedDict()
with contextlib.suppress(TestData.DoesNotExist):
......@@ -231,7 +233,9 @@ def suite(request, job, pk):
job = get_restricted_job(request.user, pk=job, request=request)
test_suite = get_object_or_404(TestSuite, name=pk, job=job)
data = SuiteView(request, model=TestCase, table_class=SuiteTable)
suite_table = SuiteTable(data.get_table_data().filter(suite=test_suite))
suite_table = SuiteTable(
data.get_table_data().filter(suite=test_suite), request=request
)
RequestConfig(request, paginate={"per_page": suite_table.length}).configure(
suite_table
)
......
......@@ -114,7 +114,9 @@ def chart_list(request):
group_view = GroupChartView(
request, group, model=Chart, table_class=GroupChartTable
)
table = GroupChartTable(group_view.get_table_data(prefix), prefix=prefix)
table = GroupChartTable(
group_view.get_table_data(prefix), request=request, prefix=prefix
)
search_data.update(table.prepare_search_data(group_view))
discrete_data.update(table.prepare_discrete_data(group_view))
terms_data.update(table.prepare_terms_data(group_view))
......@@ -125,7 +127,7 @@ def chart_list(request):
prefix = "other_"
other_view = OtherChartView(request, model=Chart, table_class=OtherChartTable)
other_chart_table = OtherChartTable(
other_view.get_table_data(prefix), prefix=prefix
other_view.get_table_data(prefix), request=request, prefix=prefix
)
config = RequestConfig(request, paginate={"per_page": other_chart_table.length})
config.configure(other_chart_table)
......@@ -136,7 +138,9 @@ def chart_list(request):
if request.user.is_authenticated:
prefix = "user_"
view = UserChartView(request, model=Chart, table_class=UserChartTable)
user_chart_table = UserChartTable(view.get_table_data(prefix), prefix=prefix)
user_chart_table = UserChartTable(
view.get_table_data(prefix), request=request, prefix=prefix
)
config = RequestConfig(request, paginate={"per_page": user_chart_table.length})
config.configure(user_chart_table)
search_data.update(user_chart_table.prepare_search_data(view))
......
......@@ -153,7 +153,9 @@ def query_list(request):
group_view = GroupQueryView(
request, group, model=Query, table_class=GroupQueryTable
)
table = GroupQueryTable(group_view.get_table_data(prefix), prefix=prefix)
table = GroupQueryTable(
group_view.get_table_data(prefix), request=request, prefix=prefix
)
search_data.update(table.prepare_search_data(group_view))
discrete_data.update(table.prepare_discrete_data(group_view))
terms_data.update(table.prepare_terms_data(group_view))
......@@ -164,7 +166,7 @@ def query_list(request):
prefix = "other_"
other_view = OtherQueryView(request, model=Query, table_class=OtherQueryTable)
other_query_table = OtherQueryTable(
other_view.get_table_data(prefix), prefix=prefix
other_view.get_table_data(prefix), request=request, prefix=prefix
)
config = RequestConfig(request, paginate={"per_page": other_query_table.length})
config.configure(other_query_table)
......@@ -174,7 +176,9 @@ def query_list(request):
prefix = "user_"
view = UserQueryView(request, model=Query, table_class=UserQueryTable)
user_query_table = UserQueryTable(view.get_table_data(prefix), prefix=prefix)
user_query_table = UserQueryTable(
view.get_table_data(prefix), request=request, prefix=prefix
)
config = RequestConfig(request, paginate={"per_page": user_query_table.length})
config.configure(user_query_table)
search_data.update(user_query_table.prepare_search_data(view))
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-06-25 14:38
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [("lava_scheduler_app", "0041_notification_charfield_to_textfield")]
operations = [
migrations.AddField(
model_name="extendeduser",
name="table_length",
field=models.PositiveSmallIntegerField(
blank=True,
default=None,
help_text="leave empty for system default",
null=True,
verbose_name="Table length",
),
)
]
......@@ -83,6 +83,14 @@ class ExtendedUser(models.Model):
max_length=40, default=None, null=True, blank=True, verbose_name="IRC server"
)
table_length = models.PositiveSmallIntegerField(
verbose_name="Table length",
help_text="leave empty for system default",
default=None,
null=True,
blank=True,
)
def __str__(self):
return "%s: %s@%s" % (self.user, self.irc_handle, self.irc_server)
......
This diff is collapsed.
......@@ -21,6 +21,8 @@
<dd><a href="{% url 'password_change' %}"><span class="glyphicon glyphicon-lock"></span> Update</a></dd>
<dt>IRC settings</dt>
<dd>Server: {{ user.extendeduser.irc_server|default:"None" }}; Handle: {{ user.extendeduser.irc_handle|default:"None" }};<a data-toggle="modal" href="#irc_modal"> Update</a></dd>
<dt>Default table length</dt>
<dd>{{ user.extendeduser.table_length|default:"System default" }} <a data-toggle="modal" href="#table_length_modal">Update</a></dd>
</dl>
</div>
......@@ -48,6 +50,30 @@
</div>
</div>
<!-- Modal HTML -->
<div id="table_length_modal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Update table length setting</h4>
</div>
<form id="table_length_form" method="post" action="{% url 'lava.update_table_length_setting' %}">
{% csrf_token %}
<div class="modal-body well">
<div id="irc_errors" class="errorlist" style="color: red;"></div>
{{ table_length_form.as_p }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input class="btn btn-primary" type="submit" value="Save" />
</div>
</form>
</div>
</div>
</div>
<div class="col-md-6">
<h4 class="modal-header">Groups</h4>
{% with groups=user.groups.all %}
......
......@@ -40,7 +40,12 @@ from lava_scheduler_app.api.tags import SchedulerTagsAPI
from lava_scheduler_app.api.workers import SchedulerWorkersAPI
from lava_server.api import LavaMapper
from lava_server.views import index, me, update_irc_settings
from lava_server.views import (
index,
me,
update_irc_settings,
update_table_length_setting,
)
handler403 = "lava_server.views.permission_error"
handler500 = "lava_server.views.server_error"
......@@ -85,6 +90,13 @@ urlpatterns = [
update_irc_settings,
name="lava.update_irc_settings",
),
url(
r"^{mount_point}update-table-length-setting/$".format(
mount_point=settings.MOUNT_POINT
),
update_table_length_setting,
name="lava.update_table_length_setting",
),
url(
r"^{mount_point}accounts/".format(mount_point=settings.MOUNT_POINT),
include("django.contrib.auth.urls"),
......
......@@ -44,6 +44,13 @@ class ExtendedUserIRCForm(forms.ModelForm):
widgets = {"user": forms.HiddenInput}
class ExtendedUserTableLengthForm(forms.ModelForm):
class Meta:
model = ExtendedUser
fields = ("table_length", "user")
widgets = {"user": forms.HiddenInput}
@BreadCrumb(_("LAVA"))
def index(request):
# Load and render the template
......@@ -58,6 +65,9 @@ def me(request): # pylint: disable=invalid-name
ExtendedUser.objects.get_or_create(user=request.user)
data = {
"irc_form": ExtendedUserIRCForm(instance=request.user.extendeduser),
"table_length_form": ExtendedUserTableLengthForm(
instance=request.user.extendeduser
),
"bread_crumb_trail": BreadCrumbTrail.leading_to(
me, you=request.user.get_full_name() or request.user.username
),
......@@ -75,6 +85,16 @@ def update_irc_settings(request):
return HttpResponseRedirect(reverse("lava.me"))
@login_required
@require_POST
def update_table_length_setting(request):
extended_user = request.user.extendeduser
form = ExtendedUserTableLengthForm(request.POST, instance=extended_user)
if form.is_valid():
extended_user = form.save()
return HttpResponseRedirect(reverse("lava.me"))
@requires_csrf_token
def server_error(request, template_name="500.html"):
exc_type, value, _ = sys.exc_info()
......