Skip to content

Commit

Permalink
Enabled bulk changes for ListView matllubos#157
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasRychtecky committed Jan 14, 2016
1 parent 3542dbc commit f867aa3
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 65 deletions.
27 changes: 20 additions & 7 deletions is_core/generic_views/table_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals

from django.core.urlresolvers import reverse
from django.views.generic.base import TemplateView
from django.db.models.fields import FieldDoesNotExist
from django.forms.forms import pretty_name
Expand Down Expand Up @@ -208,18 +209,30 @@ def _get_list_filter(self):
def _get_add_url(self):
return self.core.get_add_url(self.request)

def is_bulk_change_enabled(self):
return hasattr(self.core, 'get_bulk_change_url_name') and self.core.get_bulk_change_url_name()

def get_context_data(self, **kwargs):
context_data = super(TableView, self).get_context_data(**kwargs)
context_data.update({
'add_url': self._get_add_url(),
'view_type': self.view_type,
'add_button_value': self.core.model._ui_meta.add_button_verbose_name %
{'verbose_name': self.core.model._meta.verbose_name,
'verbose_name_plural': self.core.model._meta.verbose_name_plural},
'export_types': self._get_export_types()
})
'add_url': self._get_add_url(),
'view_type': self.view_type,
'add_button_value': self.core.model._ui_meta.add_button_verbose_name % {
'verbose_name': self.core.model._meta.verbose_name,
'verbose_name_plural': self.core.model._meta.verbose_name_plural},
'export_types': self._get_export_types(),
'enable_bulk_change': self.is_bulk_change_enabled(),
'bulk_change_snippet_name': self.get_bulk_change_snippet_name(),
'bulk_change_form_url': self.get_bulk_change_form_url(),
})
return context_data

def get_bulk_change_snippet_name(self):
return '-'.join(('default', self.model._meta.object_name.lower(), 'form'))

def get_bulk_change_form_url(self):
return reverse(self.core.get_bulk_change_url_name()) if self.is_bulk_change_enabled() else None

This comment has been minimized.

Copy link
@matllubos

matllubos Jan 14, 2016

+1 if


def has_get_permission(self, **kwargs):
return self.core.has_ui_read_permission(self.request)

Expand Down
Binary file modified is_core/locale/cs/LC_MESSAGES/django.mo
Binary file not shown.
120 changes: 75 additions & 45 deletions is_core/locale/cs/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,56 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.4.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-12-13 13:41+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"POT-Creation-Date: 2016-01-14 15:18+0100\n"
"PO-Revision-Date: 2016-01-14 15:22+0100\n"
"Last-Translator: FULL NAME <[email protected]>\n"
"Language: Czech\n"
"Language: cs\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
"Language-Team: \n"
"X-Generator: Poedit 1.8.1\n"

#: actions.py:49 filters/default_filters.py:192
#: templates/forms/inline_table.html:26 templates/generic_views/table.html:52
#: utils/__init__.py:154
#: templates/forms/inline_table.html:54 templates/generic_views/table.html:81
#: utils/__init__.py:170
msgid "Yes"
msgstr "Ano"

#: actions.py:50 filters/default_filters.py:192
#: templates/forms/inline_table.html:26 templates/generic_views/table.html:52
#: utils/__init__.py:154
#: templates/forms/inline_table.html:54 templates/generic_views/table.html:81
#: utils/__init__.py:170
msgid "No"
msgstr "Ne"

#: actions.py:51 templates/forms/inline_table.html:26
#: templates/generic_views/table.html:52
#: actions.py:51 templates/forms/inline_table.html:54
#: templates/generic_views/table.html:81
msgid "Are you sure?"
msgstr "Jste si jisti?"

#: main.py:290 generic_views/__init__.py:176
msgid "Home"
msgstr "Home"

#: main.py:456
#, python-format
msgid "Do you really want to delete \"%s\""
msgstr "Opravdu chcete odstranit položku \"%s\""

#: main.py:458
msgid "Delete"
msgstr "Smazat"

#: main.py:459
#, python-format
msgid "Record \"%s\" was deleted"
msgstr "Záznam\"%s\" byl smazán"

This comment has been minimized.

Copy link
@matllubos

matllubos Jan 14, 2016

space missing

This comment has been minimized.

Copy link
@LukasRychtecky

LukasRychtecky Jan 15, 2016

Author Owner

Fixed


#: main.py:488
msgid "Edit"
msgstr "Upravit"

#: auth_token/forms.py:32
msgid "Remember user"
msgstr "Zapamatovat uživatele"
Expand Down Expand Up @@ -83,10 +107,6 @@ msgstr "Pole pro čtení nemůže být validováno"
msgid "Search..."
msgstr "Hledat..."

#: generic_views/__init__.py:176 main.py:276
msgid "Home"
msgstr "Home"

#: generic_views/form_views.py:31
msgid "Object was saved successfully."
msgstr "Položka byla úspěšně uložena."
Expand Down Expand Up @@ -138,24 +158,6 @@ msgstr "Položka \"%(obj)s\" typu %(name)s byla úspěšně upravena."
msgid "There are no items"
msgstr "Žádné položky"

#: main.py:442
#, python-format
msgid "Do you really want to delete \"%s\""
msgstr "Opravdu chcete odstranit položku \"%s\""

#: main.py:444
msgid "Delete"
msgstr "Smazat"

#: main.py:445
#, python-format
msgid "Record \"%s\" was deleted"
msgstr "Záznam\"%s\" byl smazán"

#: main.py:474
msgid "Edit"
msgstr "Upravit"

#: middleware/__init__.py:31
msgid "Unprocessable Entity"
msgstr "Nezpracovatelná entita"
Expand All @@ -173,16 +175,20 @@ msgstr "Přidat %(verbose_name)s"
msgid "(None)"
msgstr "---"

#: rest/resource.py:206
#: rest/resource.py:209
#, python-format
msgid "Cannot resolve filter \"%s\""
msgstr "Není možné filtrovat data dle hodnoty: \"%s\""

#: rest/resource.py:219
#: rest/resource.py:222
#, python-format
msgid "Cannot resolve Order value \"%s\" into fields"
msgstr "Není možné řadit dle hodnoty: \"%s\""

#: rest/resource.py:270
msgid "Too many object have been requested for a bulk change"
msgstr "Příliš mnoho objektů k hromadné změně"

This comment has been minimized.

Copy link
@matllubos

matllubos Jan 14, 2016

nebylo by lepší dát něco jako

Můžete změnit maximálně XY objektů v jednom requestu. Nebo něco podobného

This comment has been minimized.

Copy link
@LukasRychtecky

LukasRychtecky Jan 15, 2016

Author Owner

Fixed


#: templates/500.html:5
msgid "Internal Server Error (500)"
msgstr "Interní chyba serveru (500)"
Expand All @@ -195,53 +201,73 @@ msgstr "Interní chyba. Služba je dočasně nedostupná."
msgid "Loading..."
msgstr "Načítám..."

#: templates/home.html:4
msgid "Welcome"
msgstr "Vítejte"

#: templates/forms/default_form.html:27
msgid "Fields marked with <span class=\"required\">*</span> are required"
msgstr "Položky označené <span class=\"required\">*</span> jsou povinné"

#: templates/forms/inline_table.html:9 templates/generic_views/table.html:20
#: templates/forms/inline_table.html:10 templates/generic_views/table.html:20
msgid "Displayed"
msgstr "Zobrazeny"

#: templates/forms/inline_table.html:9 templates/generic_views/table.html:20
#: templates/forms/inline_table.html:10 templates/generic_views/table.html:20
msgid "&#37;d to &#37;d"
msgstr "&#37;d do &#37;d"

#: templates/forms/inline_table.html:10 templates/generic_views/table.html:21
#: templates/forms/inline_table.html:11 templates/generic_views/table.html:21
msgid "of"
msgstr "z"

#: templates/forms/inline_table.html:17 templates/generic_views/table.html:28
#: templates/forms/inline_table.html:18 templates/generic_views/table.html:28
msgid "Previous"
msgstr "Předchozí"

#: templates/forms/inline_table.html:18 templates/generic_views/table.html:29
#: templates/forms/inline_table.html:19 templates/generic_views/table.html:29
msgid "Next"
msgstr "Následující"

#: templates/forms/inline_table.html:26 templates/generic_views/table.html:52
#: templates/forms/inline_table.html:36 templates/generic_views/table.html:59
msgid "Columns"
msgstr "Sloupce"

#: templates/forms/inline_table.html:48 templates/generic_views/table.html:71
#, python-format
msgid ""
"There are some filters on hidden fields: <span class=\"columns\">"
"%(columns)s</span>. Do you want to <span class=\"delete-filtering\">delete "
"filtering</span>?"
msgstr ""
"Na skryté sloupce jsou aplikovány filtry: <span class=\"columns\">"
"%(columns)s</span>. Opravdu chcete <span class=\"delete-filtering"
"\">odstranit filtrování </span>?"

#: templates/forms/inline_table.html:54 templates/generic_views/table.html:81
msgid "Do you really want to delete &#37;s?"
msgstr "Opravdu chcete odstranit položku &#37;s?"

#: templates/forms/inline_table.html:36 templates/generic_views/table.html:62
#: templates/forms/inline_table.html:65 templates/generic_views/table.html:93
msgid "Actions"
msgstr "Akce"

#: templates/forms/inline_table.html:46 templates/generic_views/table.html:72
#: templates/forms/inline_table.html:76
#: templates/generic_views/table.html:104
msgid "There are no items."
msgstr "Žádné položky"

#: templates/forms/login_form.html:5 templates/registration/login.html:4
msgid "Login"
msgstr "Login"

#: templates/generic_views/table.html:41
#: templates/generic_views/table.html:42
msgid "Exports"
msgstr "Export"

#: templates/home.html:4
msgid "Welcome"
msgstr "Vítejte"
#: templates/generic_views/table.html:77
msgid "Bulk change"
msgstr "Hromadná změna"

#: templates/registration/login.html:14
msgid "Please Sign In"
Expand All @@ -263,6 +289,10 @@ msgstr "Děkujeme za čas strávený s tímto webem."
msgid "Log in again"
msgstr "Přihlásit se znovu"

#: templates/views/bulk-change-view.html:6
msgid "Affected rows"
msgstr "Počet záznamů ke změně"

#: views/csrf.py:7
msgid "Csrf Token expired"
msgstr "Neplatný Csrf Token"
Expand Down
16 changes: 15 additions & 1 deletion is_core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from is_core.rest.factory import modelrest_factory
from is_core.rest.datastructures import ModelRestFieldset
from is_core.forms.models import SmartModelForm
from is_core.views import BulkChangeFormView


class ISCoreBase(type):
Expand Down Expand Up @@ -116,6 +117,13 @@ class ModelISCore(PermissionsMixin, ISCore):
form_class = SmartModelForm

ordering = None
bulk_change_url_name = None

def get_view_classes(self):
view_classes = super(ModelISCore, self).get_view_classes()
if self.is_bulk_change_enabled():
view_classes['bulk-change'] = (r'/bulk-change/?$', BulkChangeFormView)

This comment has been minimized.

Copy link
@matllubos

matllubos Jan 14, 2016

zde bys měl využít název který máš definovaný v core (ale bez IS)

This comment has been minimized.

Copy link
@LukasRychtecky

LukasRychtecky Jan 15, 2016

Author Owner

Fixed

return view_classes

def get_form_fields(self, request, obj=None):
return self.form_fields
Expand Down Expand Up @@ -178,6 +186,12 @@ def get_list_actions(self, request, obj):
def get_default_action(self, request, obj):
return None

def is_bulk_change_enabled(self):
return self.get_bulk_change_url_name() is not None

def get_bulk_change_url_name(self):
return self.bulk_change_url_name


class UIISCore(PermissionsUIMixin, ISCore):
abstract = True
Expand Down Expand Up @@ -431,7 +445,7 @@ def get_rest_class(self):
def get_resource_patterns(self):
resource_patterns = super(RestModelISCore, self).get_resource_patterns()
resource_patterns.update(DoubleRestPattern(
self.get_rest_class(),
self.get_rest_class(),
self.default_rest_resource_pattern_class, self
).patterns)
return resource_patterns
Expand Down
8 changes: 6 additions & 2 deletions is_core/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ def patterns(self):
self.resource_class, self.core, ('get', 'put', 'delete'), clone_view_class=False
)
result['api'] = self.pattern_class(
'api-%s' % self.core.get_menu_group_pattern_name(), self.core.site_name, r'^/?$', self.resource_class, self.core,
('get', 'post'), clone_view_class=False
'api-%s' % self.core.get_menu_group_pattern_name(), self.core.site_name, r'^/?$', self.resource_class,
self.core, self._get_api_allowed_methods(), clone_view_class=False
)
return result

def _get_api_allowed_methods(self):
return (('get', 'post') + (
('put',) if hasattr(self.core, 'is_bulk_change_enabled') and self.core.is_bulk_change_enabled() else ()))
Loading

0 comments on commit f867aa3

Please sign in to comment.