From 5d25c89c96a1cce669bda84d89ebbf561267d1bd Mon Sep 17 00:00:00 2001 From: Paul Marillonnet Date: Mon, 30 Oct 2017 18:10:09 +0100 Subject: [PATCH] WIP get rid of django-tables? (#19459) --- fargo/fargo/tables.py | 19 ------------- fargo/fargo/views.py | 10 +++++-- fargo/templates/fargo/home.html | 4 +-- fargo/templates/fargo/table.html | 61 ++++++++++++---------------------------- 4 files changed, 27 insertions(+), 67 deletions(-) diff --git a/fargo/fargo/tables.py b/fargo/fargo/tables.py index 11ea936..e69de29 100644 --- a/fargo/fargo/tables.py +++ b/fargo/fargo/tables.py @@ -1,19 +0,0 @@ -from django.utils.translation import ugettext_lazy as _ - -import django_tables2 as tables - -from . import models - - -class DocumentTable(tables.Table): - '''Display the list of documents of the user''' - filename = tables.Column(verbose_name=_('filename').title()) - size = tables.TemplateColumn(template_code='{{ record.document.content.size|filesizeformat }}', - orderable=False, - verbose_name=_('size').title()) - created = tables.DateTimeColumn(verbose_name=_('creation date').title()) - - class Meta: - model = models.Document - fields = ('filename', 'size', 'created') - empty_text = _('You currently have no documents') diff --git a/fargo/fargo/views.py b/fargo/fargo/views.py index 78f420d..bd1ef6b 100644 --- a/fargo/fargo/views.py +++ b/fargo/fargo/views.py @@ -9,7 +9,7 @@ from django.views.decorators.clickjacking import xframe_options_exempt from django.views.generic import CreateView, DeleteView, UpdateView, View, TemplateView from django.core.urlresolvers import reverse from django.contrib.auth.decorators import login_required -from django.shortcuts import get_object_or_404, resolve_url +from django.shortcuts import get_object_or_404, resolve_url, render from django.http import (HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404) from django.core import signing @@ -73,11 +73,11 @@ class Documents(object): .select_related('document', 'user') -class Homepage(Documents, SingleTableMixin, CommonUpload): +class Homepage(Documents, CommonUpload): '''Show documents of users, eventually paginate and sort them.''' template_name = 'fargo/home.html' form_class = forms.UploadForm - table_class = tables.DocumentTable + model = models.UserDocument table_pagination = { 'per_page': 5, } @@ -90,6 +90,10 @@ class Homepage(Documents, SingleTableMixin, CommonUpload): def get_success_url(self): return '' + def get(self, request, *args, **kwargs): + return render(request, self.template_name, + {'user_files': self.model.objects.all()}) + class PickList(Homepage): template_name = 'fargo/pick.html' diff --git a/fargo/templates/fargo/home.html b/fargo/templates/fargo/home.html index 3f3a5f1..68496c1 100644 --- a/fargo/templates/fargo/home.html +++ b/fargo/templates/fargo/home.html @@ -1,5 +1,4 @@ {% extends "fargo/base.html" %} -{% load render_table from django_tables2 %} {% load gadjo i18n staticfiles %} {% block content %} @@ -34,8 +33,9 @@

{% if site_title %}{{ site_title }}{% else %}{% trans "Portfolio" %}{% endif %}

+ {{ user_files }}
- {% render_table table "fargo/table.html" %} + {% include "fargo/table.html" %}
{% csrf_token %} {{ form.non_field_errors }} diff --git a/fargo/templates/fargo/table.html b/fargo/templates/fargo/table.html index a2d002c..788742d 100644 --- a/fargo/templates/fargo/table.html +++ b/fargo/templates/fargo/table.html @@ -1,50 +1,25 @@ -{% extends "django_tables2/table.html" %} -{% load django_tables2 %} {% load i18n %} -{% block table.thead %} - + +
+ + - {% for column in table.columns %} - {% if column.orderable %} - - {% else %} - - {% endif %} - {% endfor %} - - + + + + + + + {% for item in user_files%} + + + + - -{% endblock table.thead %} - -{% block table.tbody.row %} - {# avoid cycle for Django 1.2-1.6 compatibility #} - {% for column, cell in row.items %} - {% endfor %} - {% with url=row.record.get_thumbnail_url %} - - {% endwith %} - - -{% endblock table.tbody.row %} - + +
- {{ column.header }} - {{ column.header }}FilenameDescriptionCreation date
{{ item.filename }}{{ item.description }}{{ item.created }}
{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}{% if url %}{% endif %} - {% block action-column %} - {% if include_edit_link %} - - {% endif %} - {% if row.record.deletable_by_user %} - - {% csrf_token %} - - - {% endif %} - {% endblock %} -
+
{% block pagination.cardinality %} {% endblock %} -- 2.11.0