acdh-django-browsing
Advanced tools
+21
| The MIT License (MIT) | ||
| Copyright (c) 2020 Austrian Centre for Digital Humanities at the Austrian Academy of Sciences | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
@@ -1,4 +0,4 @@ | ||
| Metadata-Version: 1.1 | ||
| Metadata-Version: 2.1 | ||
| Name: acdh-django-browsing | ||
| Version: 1.2.4 | ||
| Version: 1.3 | ||
| Summary: Django-App providing some useful things to create browsing views | ||
@@ -9,36 +9,2 @@ Home-page: https://github.com/acdh-oeaw/acdh-django-browsing | ||
| License: MIT License | ||
| Description: ============================= | ||
| acdh-django-browsing | ||
| ============================= | ||
| .. image:: https://badge.fury.io/py/acdh-django-browsing.svg | ||
| :target: https://badge.fury.io/py/acdh-django-browsing | ||
| Django-App providing some useful things to create browsing views | ||
| Quickstart | ||
| ---------- | ||
| Install acdh-django-browsing: | ||
| pip install acdh-django-browsing | ||
| Add it to your `INSTALLED_APPS`: | ||
| .. code-block:: python | ||
| INSTALLED_APPS = ( | ||
| ... | ||
| 'browsing', | ||
| ... | ||
| ) | ||
| build and publish | ||
| rm -rf ./dist | ||
| python setup.py sdist bdist_wheel | ||
| twine upload dist/* | ||
| Platform: UNKNOWN | ||
@@ -53,1 +19,38 @@ Classifier: Environment :: Web Environment | ||
| Classifier: Programming Language :: Python :: 3.6 | ||
| License-File: LICENSE.txt | ||
| ============================= | ||
| acdh-django-browsing | ||
| ============================= | ||
| .. image:: https://badge.fury.io/py/acdh-django-browsing.svg | ||
| :target: https://badge.fury.io/py/acdh-django-browsing | ||
| Django-App providing some useful things to create browsing views | ||
| Quickstart | ||
| ---------- | ||
| Install acdh-django-browsing: | ||
| pip install acdh-django-browsing | ||
| Add it to your `INSTALLED_APPS`: | ||
| .. code-block:: python | ||
| INSTALLED_APPS = ( | ||
| ... | ||
| 'browsing', | ||
| ... | ||
| ) | ||
| build and publish | ||
| rm -rf ./dist | ||
| python setup.py sdist bdist_wheel | ||
| twine upload dist/* | ||
@@ -0,1 +1,2 @@ | ||
| LICENSE.txt | ||
| MANIFEST.in | ||
@@ -2,0 +3,0 @@ README.rst |
@@ -13,3 +13,3 @@ import django_tables2 | ||
| if 'charts' in settings.INSTALLED_APPS: | ||
| if "charts" in settings.INSTALLED_APPS: | ||
| from charts.models import ChartConfig | ||
@@ -26,3 +26,3 @@ from charts.views import create_payload | ||
| class MergeColumn(django_tables2.Column): | ||
| """ renders a column with to checkbox - used to select objects for merging """ | ||
| """renders a column with to checkbox - used to select objects for merging""" | ||
@@ -33,9 +33,6 @@ def __init__(self, *args, **kwargs): | ||
| def render(self, value): | ||
| return mark_safe( | ||
| input_form.format(value, value) | ||
| ) | ||
| return mark_safe(input_form.format(value, value)) | ||
| def get_entities_table(model_class): | ||
| class GenericEntitiesTable(django_tables2.Table): | ||
@@ -47,2 +44,3 @@ id = django_tables2.LinkColumn() | ||
| attrs = {"class": "table table-hover table-striped table-condensed"} | ||
| return GenericEntitiesTable | ||
@@ -52,10 +50,9 @@ | ||
| class GenericFilterFormHelper(FormHelper): | ||
| def __init__(self, *args, **kwargs): | ||
| super(GenericFilterFormHelper, self).__init__(*args, **kwargs) | ||
| self.helper = FormHelper() | ||
| self.form_class = 'genericFilterForm' | ||
| self.form_method = 'GET' | ||
| self.form_class = "genericFilterForm" | ||
| self.form_method = "GET" | ||
| self.helper.form_tag = False | ||
| self.add_input(Submit('Filter', 'Search')) | ||
| self.add_input(Submit("Filter", "Search")) | ||
@@ -66,7 +63,8 @@ | ||
| formhelper_class = None | ||
| context_filter_name = 'filter' | ||
| context_filter_name = "filter" | ||
| paginate_by = 50 | ||
| template_name = 'browsing/generic_list.html' | ||
| template_name = "browsing/generic_list.html" | ||
| init_columns = [] | ||
| enable_merge = False | ||
| excluded_cols = [] | ||
@@ -80,3 +78,5 @@ def get_table_class(self): | ||
| def get_all_cols(self): | ||
| all_cols = list(self.get_table().base_columns.keys()) | ||
| all_cols = { | ||
| key: value.header for key, value in self.get_table().base_columns.items() | ||
| } | ||
| return all_cols | ||
@@ -101,40 +101,42 @@ | ||
| context = super(GenericListView, self).get_context_data() | ||
| context['enable_merge'] = self.enable_merge | ||
| togglable_colums = [x for x in self.get_all_cols() if x not in self.init_columns] | ||
| context['togglable_colums'] = togglable_colums | ||
| context["enable_merge"] = self.enable_merge | ||
| togglable_colums = { | ||
| key: value | ||
| for key, value in self.get_all_cols().items() | ||
| if key not in self.init_columns and key not in self.exclude_columns | ||
| } | ||
| context["togglable_colums"] = togglable_colums | ||
| context[self.context_filter_name] = self.filter | ||
| context['docstring'] = "{}".format(self.model.__doc__) | ||
| context["docstring"] = "{}".format(self.model.__doc__) | ||
| if self.model._meta.verbose_name_plural: | ||
| context['class_name'] = "{}".format(self.model._meta.verbose_name.title()) | ||
| context["class_name"] = "{}".format(self.model._meta.verbose_name.title()) | ||
| else: | ||
| if self.model.__name__.endswith('s'): | ||
| context['class_name'] = "{}".format(self.model.__name__) | ||
| if self.model.__name__.endswith("s"): | ||
| context["class_name"] = "{}".format(self.model.__name__) | ||
| else: | ||
| context['class_name'] = "{}s".format(self.model.__name__) | ||
| context["class_name"] = "{}s".format(self.model.__name__) | ||
| try: | ||
| context['create_view_link'] = self.model.get_createview_url() | ||
| context["create_view_link"] = self.model.get_createview_url() | ||
| except AttributeError: | ||
| context['create_view_link'] = None | ||
| context["create_view_link"] = None | ||
| model_name = self.model.__name__.lower() | ||
| context['entity'] = model_name | ||
| context['app_name'] = self.model._meta.app_label | ||
| if 'charts' in settings.INSTALLED_APPS: | ||
| context["entity"] = model_name | ||
| context["app_name"] = self.model._meta.app_label | ||
| if "charts" in settings.INSTALLED_APPS: | ||
| model = self.model | ||
| app_label = model._meta.app_label | ||
| print(app_label) | ||
| filtered_objs = ChartConfig.objects.filter( | ||
| model_name=model.__name__.lower(), | ||
| app_name=app_label | ||
| model_name=model.__name__.lower(), app_name=app_label | ||
| ) | ||
| context['vis_list'] = filtered_objs | ||
| context['property_name'] = self.request.GET.get('property') | ||
| context['charttype'] = self.request.GET.get('charttype') | ||
| if context['charttype'] and context['property_name']: | ||
| context["vis_list"] = filtered_objs | ||
| context["property_name"] = self.request.GET.get("property") | ||
| context["charttype"] = self.request.GET.get("charttype") | ||
| if context["charttype"] and context["property_name"]: | ||
| qs = self.get_queryset() | ||
| chartdata = create_payload( | ||
| context['entity'], | ||
| context['property_name'], | ||
| context['charttype'], | ||
| context["entity"], | ||
| context["property_name"], | ||
| context["charttype"], | ||
| qs, | ||
| app_label=app_label | ||
| app_label=app_label, | ||
| ) | ||
@@ -147,9 +149,9 @@ context = dict(context, **chartdata) | ||
| model = None | ||
| template_name = 'browsing/generic_create.html' | ||
| template_name = "browsing/generic_create.html" | ||
| def get_context_data(self, **kwargs): | ||
| context = super().get_context_data() | ||
| context['docstring'] = "{}".format(self.model.__doc__) | ||
| context['class_name'] = "{}".format(self.model.__name__) | ||
| context['app_name'] = "{}".format(self.model._meta.app_label) | ||
| context["docstring"] = "{}".format(self.model.__doc__) | ||
| context["class_name"] = "{}".format(self.model.__name__) | ||
| context["app_name"] = "{}".format(self.model._meta.app_label) | ||
| return context | ||
@@ -161,8 +163,8 @@ | ||
| form_class = None | ||
| template_name = 'browsing/generic_create.html' | ||
| template_name = "browsing/generic_create.html" | ||
| def get_context_data(self, **kwargs): | ||
| context = super(BaseCreateView, self).get_context_data() | ||
| context['docstring'] = "{}".format(self.model.__doc__) | ||
| context['class_name'] = "{}".format(self.model.__name__) | ||
| context["docstring"] = "{}".format(self.model.__doc__) | ||
| context["class_name"] = "{}".format(self.model.__name__) | ||
| return context | ||
@@ -174,8 +176,8 @@ | ||
| form_class = None | ||
| template_name = 'browsing/generic_create.html' | ||
| template_name = "browsing/generic_create.html" | ||
| def get_context_data(self, **kwargs): | ||
| context = super(BaseUpdateView, self).get_context_data() | ||
| context['docstring'] = "{}".format(self.model.__doc__) | ||
| context['class_name'] = "{}".format(self.model.__name__) | ||
| context["docstring"] = "{}".format(self.model.__doc__) | ||
| context["class_name"] = "{}".format(self.model.__name__) | ||
| # if self.model.__name__.endswith('s'): | ||
@@ -197,47 +199,47 @@ # context['class_name'] = "{}".format(self.model.__name__) | ||
| field_dict = { | ||
| "name": x.name, | ||
| "help_text": getattr(x, 'help_text', ''), | ||
| } | ||
| "name": x.name, | ||
| "help_text": getattr(x, "help_text", ""), | ||
| } | ||
| try: | ||
| field_dict['extra_fields'] = x.extra | ||
| field_dict["extra_fields"] = x.extra | ||
| except AttributeError: | ||
| field_dict['extra_fields'] = None | ||
| if 'reverse_related' in f_type: | ||
| field_dict["extra_fields"] = None | ||
| if "reverse_related" in f_type: | ||
| values = getattr(instance, x.name, None) | ||
| if values is not None: | ||
| field_dict['value'] = values.all() | ||
| field_dict["value"] = values.all() | ||
| else: | ||
| field_dict['value'] = [] | ||
| if getattr(x, 'related_name', None) is not None: | ||
| field_dict['verbose_name'] = getattr(x, 'related_name', x.name) | ||
| field_dict["value"] = [] | ||
| if getattr(x, "related_name", None) is not None: | ||
| field_dict["verbose_name"] = getattr(x, "related_name", x.name) | ||
| else: | ||
| field_dict['verbose_name'] = getattr(x, 'verbose_name', x.name) | ||
| field_dict['f_type'] = 'REVRESE_RELATION' | ||
| elif 'related.ForeignKey' in f_type: | ||
| field_dict['verbose_name'] = getattr(x, 'verbose_name', x.name) | ||
| field_dict['value'] = getattr(instance, x.name, '') | ||
| field_dict['f_type'] = 'FK' | ||
| elif 'TreeForeignKey' in f_type: | ||
| field_dict['verbose_name'] = getattr(x, 'verbose_name', x.name) | ||
| field_dict['value'] = getattr(instance, x.name, '') | ||
| field_dict['f_type'] = 'FK' | ||
| elif 'related.ManyToManyField' in f_type: | ||
| field_dict["verbose_name"] = getattr(x, "verbose_name", x.name) | ||
| field_dict["f_type"] = "REVRESE_RELATION" | ||
| elif "related.ForeignKey" in f_type: | ||
| field_dict["verbose_name"] = getattr(x, "verbose_name", x.name) | ||
| field_dict["value"] = getattr(instance, x.name, "") | ||
| field_dict["f_type"] = "FK" | ||
| elif "TreeForeignKey" in f_type: | ||
| field_dict["verbose_name"] = getattr(x, "verbose_name", x.name) | ||
| field_dict["value"] = getattr(instance, x.name, "") | ||
| field_dict["f_type"] = "FK" | ||
| elif "related.ManyToManyField" in f_type: | ||
| values = getattr(instance, x.name, None) | ||
| if values is not None: | ||
| field_dict['value'] = values.all() | ||
| field_dict["value"] = values.all() | ||
| else: | ||
| field_dict['value'] = [] | ||
| field_dict['verbose_name'] = getattr(x, 'verbose_name', x.name) | ||
| field_dict['f_type'] = 'M2M' | ||
| elif 'fields.DateTimeField' in f_type: | ||
| field_value = getattr(instance, x.name, '') | ||
| field_dict['verbose_name'] = getattr(x, 'verbose_name', x.name) | ||
| field_dict['f_type'] = 'DateTime' | ||
| field_dict["value"] = [] | ||
| field_dict["verbose_name"] = getattr(x, "verbose_name", x.name) | ||
| field_dict["f_type"] = "M2M" | ||
| elif "fields.DateTimeField" in f_type: | ||
| field_value = getattr(instance, x.name, "") | ||
| field_dict["verbose_name"] = getattr(x, "verbose_name", x.name) | ||
| field_dict["f_type"] = "DateTime" | ||
| if field_value: | ||
| field_dict['value'] = (field_value.strftime("%Y-%m-%d %H:%M:%S")) | ||
| field_dict["value"] = field_value.strftime("%Y-%m-%d %H:%M:%S") | ||
| else: | ||
| field_dict['verbose_name'] = getattr(x, 'verbose_name', x.name) | ||
| field_dict['value'] = f"{getattr(instance, x.name, '')}" | ||
| field_dict['f_type'] = 'SIMPLE' | ||
| field_dict["verbose_name"] = getattr(x, "verbose_name", x.name) | ||
| field_dict["value"] = f"{getattr(instance, x.name, '')}" | ||
| field_dict["f_type"] = "SIMPLE" | ||
| field_dicts.append(field_dict) | ||
| return field_dicts | ||
| return field_dicts |
@@ -1,6 +0,10 @@ | ||
| {% if columns %} | ||
| {% if togglable_colums %} | ||
| <select class="selectpicker" multiple data-selected-text-format="count > 2" name="columns" id="column_selector"> | ||
| {% for x in columns %} | ||
| <option value="{{ x }}">{{ x|title }}</option> | ||
| {% for key, value in togglable_colums.items %} | ||
| {% if key == 'merge' and user.is_authenticated and enable_merge %} | ||
| <option value="{{ key }}">{{ value }}</option> | ||
| {% elif key == 'merge' and not user.is_authenticated %} | ||
| {% elif key != 'merge' %} | ||
| <option value="{{ key }}">{{ value }}</option> | ||
| {% endif %} | ||
| {% endfor %} | ||
@@ -7,0 +11,0 @@ </select> |
@@ -51,6 +51,2 @@ from django import template | ||
| def column_selector(context): | ||
| try: | ||
| return {'columns': context['togglable_colums']} | ||
| except Exception as e: | ||
| print(e) | ||
| return {'columns': None} | ||
| return context |
+39
-36
@@ -1,4 +0,4 @@ | ||
| Metadata-Version: 1.1 | ||
| Metadata-Version: 2.1 | ||
| Name: acdh-django-browsing | ||
| Version: 1.2.4 | ||
| Version: 1.3 | ||
| Summary: Django-App providing some useful things to create browsing views | ||
@@ -9,36 +9,2 @@ Home-page: https://github.com/acdh-oeaw/acdh-django-browsing | ||
| License: MIT License | ||
| Description: ============================= | ||
| acdh-django-browsing | ||
| ============================= | ||
| .. image:: https://badge.fury.io/py/acdh-django-browsing.svg | ||
| :target: https://badge.fury.io/py/acdh-django-browsing | ||
| Django-App providing some useful things to create browsing views | ||
| Quickstart | ||
| ---------- | ||
| Install acdh-django-browsing: | ||
| pip install acdh-django-browsing | ||
| Add it to your `INSTALLED_APPS`: | ||
| .. code-block:: python | ||
| INSTALLED_APPS = ( | ||
| ... | ||
| 'browsing', | ||
| ... | ||
| ) | ||
| build and publish | ||
| rm -rf ./dist | ||
| python setup.py sdist bdist_wheel | ||
| twine upload dist/* | ||
| Platform: UNKNOWN | ||
@@ -53,1 +19,38 @@ Classifier: Environment :: Web Environment | ||
| Classifier: Programming Language :: Python :: 3.6 | ||
| License-File: LICENSE.txt | ||
| ============================= | ||
| acdh-django-browsing | ||
| ============================= | ||
| .. image:: https://badge.fury.io/py/acdh-django-browsing.svg | ||
| :target: https://badge.fury.io/py/acdh-django-browsing | ||
| Django-App providing some useful things to create browsing views | ||
| Quickstart | ||
| ---------- | ||
| Install acdh-django-browsing: | ||
| pip install acdh-django-browsing | ||
| Add it to your `INSTALLED_APPS`: | ||
| .. code-block:: python | ||
| INSTALLED_APPS = ( | ||
| ... | ||
| 'browsing', | ||
| ... | ||
| ) | ||
| build and publish | ||
| rm -rf ./dist | ||
| python setup.py sdist bdist_wheel | ||
| twine upload dist/* | ||
+1
-1
@@ -13,3 +13,3 @@ import os | ||
| name='acdh-django-browsing', | ||
| version='1.2.4', | ||
| version='1.3', | ||
| packages=find_packages(), | ||
@@ -16,0 +16,0 @@ include_package_data=True, |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
36379
2.57%35
2.94%