Projet

Général

Profil

0001-WIP-get-rid-of-django-tables-19459.patch

Paul Marillonnet, 30 octobre 2017 18:13

Télécharger (5,97 ko)

Voir les différences:

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(-)
fargo/fargo/tables.py
1
from django.utils.translation import ugettext_lazy as _
2

  
3
import django_tables2 as tables
4

  
5
from . import models
6

  
7

  
8
class DocumentTable(tables.Table):
9
    '''Display the list of documents of the user'''
10
    filename = tables.Column(verbose_name=_('filename').title())
11
    size = tables.TemplateColumn(template_code='{{ record.document.content.size|filesizeformat }}',
12
                                 orderable=False,
13
                                 verbose_name=_('size').title())
14
    created = tables.DateTimeColumn(verbose_name=_('creation date').title())
15

  
16
    class Meta:
17
        model = models.Document
18
        fields = ('filename', 'size', 'created')
19
        empty_text = _('You currently have no documents')
fargo/fargo/views.py
9 9
from django.views.generic import CreateView, DeleteView, UpdateView, View, TemplateView
10 10
from django.core.urlresolvers import reverse
11 11
from django.contrib.auth.decorators import login_required
12
from django.shortcuts import get_object_or_404, resolve_url
12
from django.shortcuts import get_object_or_404, resolve_url, render
13 13
from django.http import (HttpResponse, HttpResponseRedirect,
14 14
                         HttpResponseForbidden, Http404)
15 15
from django.core import signing
......
73 73
            .select_related('document', 'user')
74 74

  
75 75

  
76
class Homepage(Documents, SingleTableMixin, CommonUpload):
76
class Homepage(Documents, CommonUpload):
77 77
    '''Show documents of users, eventually paginate and sort them.'''
78 78
    template_name = 'fargo/home.html'
79 79
    form_class = forms.UploadForm
80
    table_class = tables.DocumentTable
80
    model = models.UserDocument
81 81
    table_pagination = {
82 82
        'per_page': 5,
83 83
    }
......
90 90
    def get_success_url(self):
91 91
        return ''
92 92

  
93
    def get(self, request, *args, **kwargs):
94
        return render(request, self.template_name,
95
                {'user_files': self.model.objects.all()})
96

  
93 97

  
94 98
class PickList(Homepage):
95 99
    template_name = 'fargo/pick.html'
fargo/templates/fargo/home.html
1 1
{% extends "fargo/base.html" %}
2
{% load render_table from django_tables2 %}
3 2
{% load gadjo i18n staticfiles %}
4 3

  
5 4
{% block content %}
......
34 33

  
35 34
  <div class="cell">
36 35
  <h2>{% if site_title %}{{ site_title }}{% else %}{% trans "Portfolio" %}{% endif %}</h2>
36
  {{ user_files }}
37 37
  <div id="user-files">
38
    {% render_table table "fargo/table.html" %}
38
    {% include "fargo/table.html" %}
39 39
    <form id="send-file" method="post" enctype="multipart/form-data">
40 40
      {% csrf_token %}
41 41
      {{ form.non_field_errors }}
fargo/templates/fargo/table.html
1
{% extends "django_tables2/table.html" %}
2
{% load django_tables2 %}
3 1
{% load i18n %}
4 2

  
5
{% block table.thead %}
6
  <thead>
3

  
4
<div class="table-container">
5
<table>
6
    <thead>
7 7
    <tr>
8
      {% for column in table.columns %}
9
        {% if column.orderable %}
10
          <th {{ column.attrs.th.as_html }}>
11
            <a href="{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}">{{ column.header }}</a>
12
          </th>
13
        {% else %}
14
          <th {{ column.attrs.th.as_html }}>{{ column.header }}</th>
15
        {% endif %}
16
      {% endfor %}
17
      <th></th>
18
      <th class="action-column"></th>
8
        <th>Filename</th>
9
        <th>Description</th>
10
        <th>Creation date</th>
11
    </tr>
12
    </thead>
13
    <tbody>
14
    {% for item in user_files%}
15
    <tr>
16
        <th>{{ item.filename }}</th>
17
        <th>{{ item.description }}</th>
18
        <th>{{ item.created }}</th>
19 19
    </tr>
20
  </thead>
21
{% endblock table.thead %}
22

  
23
{% block table.tbody.row %}
24
  <tr class="{{ forloop.counter|divisibleby:2|yesno:"even,odd" }} {{row.record.css_classes}}"
25
      data-url="{{row.record.get_download_url}}"
26
      > {# avoid cycle for Django 1.2-1.6 compatibility #}
27
    {% for column, cell in row.items %}
28
      <td {{ column.attrs.td.as_html }}>{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}</td>
29 20
    {% endfor %}
30
      {% with url=row.record.get_thumbnail_url %}
31
        <td class="thumbnail">{% if url %}<img src="{{ url }}"/>{% endif %}</td>
32
      {% endwith %}
33
    <td class="action-column">
34
      {% block action-column %}
35
      {% if include_edit_link %}
36
        <a class="icon-edit" rel="popup" href="{% url 'edit' pk=row.record.pk %}"></a>
37
      {% endif %}
38
      {% if row.record.deletable_by_user %}
39
      <form method="post" action="{% url 'delete' pk=row.record.pk %}{% querystring %}">
40
        {% csrf_token %}
41
        <button class="icon-remove-sign"></button>
42
      </form>
43
      {% endif %}
44
      {% endblock %}
45
   </td>
46
  </tr>
47
{% endblock table.tbody.row %}
48

  
21
    </tbody>
22
</table>
23
</div>
49 24
{% block pagination.cardinality %}
50 25
{% endblock %}
51
-