diff options
Diffstat (limited to 'lib/srtgui/widgets.py')
-rw-r--r-- | lib/srtgui/widgets.py | 156 |
1 files changed, 68 insertions, 88 deletions
diff --git a/lib/srtgui/widgets.py b/lib/srtgui/widgets.py index e0033e16..b491a1c4 100644 --- a/lib/srtgui/widgets.py +++ b/lib/srtgui/widgets.py @@ -29,27 +29,16 @@ from django.template import Context, Template from django.template import VariableDoesNotExist from django.template import TemplateSyntaxError from django.core.serializers.json import DjangoJSONEncoder -from django.core.exceptions import FieldError -from django.utils import timezone -from django.http import JsonResponse -from django.urls import reverse from orm.models import SrtSetting, Cve -from srtgui.templatetags.projecttags import sectohms, get_tasks -from srtgui.templatetags.projecttags import json as template_json import types import json import collections import re -import os from srtgui.tablefilter import TableFilterMap - -try: - from urllib import unquote_plus -except ImportError: - from urllib.parse import unquote_plus +from urllib.parse import unquote_plus import logging logger = logging.getLogger("srt") @@ -249,14 +238,10 @@ class ToasterTable(TemplateView): if "all" in action_name: return - try: - table_filter = self.filter_map.get_filter(filter_name) - action = table_filter.get_action(action_name) - action.set_filter_params(action_params) - self.queryset = action.filter(self.queryset) - except KeyError: - # pass it to the user - programming error here - raise + table_filter = self.filter_map.get_filter(filter_name) + action = table_filter.get_action(action_name) + action.set_filter_params(action_params) + self.queryset = action.filter(self.queryset) def apply_orderby(self, orderby): # Note that django will execute this when we try to retrieve the data @@ -357,76 +342,71 @@ class ToasterTable(TemplateView): 'error': "ok", } - try: - for model_obj in page.object_list: - # Use collection to maintain the order - required_data = collections.OrderedDict() - - for col in self.columns: - field = col['field_name'] - if not field: - field = col['static_data_name'] - if not field: - raise NoFieldOrDataName("Must supply a field_name or" - "static_data_name for column" - "%s.%s" % - (self.__class__.__name__, col) - ) - - # Check if we need to process some static data - if "static_data_name" in col and col['static_data_name']: - # Overwrite the field_name with static_data_name - # so that this can be used as the html class name - col['field_name'] = col['static_data_name'] - - try: - # Render the template given - required_data[col['static_data_name']] = \ - self.render_static_data( - col['static_data_template'], model_obj) - except (TemplateSyntaxError, - VariableDoesNotExist) as e: - logger.error("could not render template code" - "%s %s %s", - col['static_data_template'], - e, self.__class__.__name__) - required_data[col['static_data_name']] =\ - '<!--error-->' + for model_obj in page.object_list: + # Use collection to maintain the order + required_data = collections.OrderedDict() + + for col in self.columns: + field = col['field_name'] + if not field: + field = col['static_data_name'] + if not field: + raise NoFieldOrDataName("Must supply a field_name or" + "static_data_name for column" + "%s.%s" % + (self.__class__.__name__, col) + ) + + # Check if we need to process some static data + if "static_data_name" in col and col['static_data_name']: + # Overwrite the field_name with static_data_name + # so that this can be used as the html class name + col['field_name'] = col['static_data_name'] + + try: + # Render the template given + required_data[col['static_data_name']] = \ + self.render_static_data( + col['static_data_template'], model_obj) + except (TemplateSyntaxError, + VariableDoesNotExist) as e: + logger.error("could not render template code" + "%s %s %s", + col['static_data_template'], + e, self.__class__.__name__) + required_data[col['static_data_name']] =\ + '<!--error-->' + + else: + # Traverse to any foriegn key in the field + # e.g. recipe__layer_version__name + model_data = None + + if "__" in field: + for subfield in field.split("__"): + if not model_data: + # The first iteration is always going to + # be on the actual model object instance. + # Subsequent ones are on the result of + # that. e.g. forieng key objects + model_data = getattr(model_obj, + subfield) + else: + model_data = getattr(model_data, + subfield) else: - # Traverse to any foriegn key in the field - # e.g. recipe__layer_version__name - model_data = None - - if "__" in field: - for subfield in field.split("__"): - if not model_data: - # The first iteration is always going to - # be on the actual model object instance. - # Subsequent ones are on the result of - # that. e.g. forieng key objects - model_data = getattr(model_obj, - subfield) - else: - model_data = getattr(model_data, - subfield) - - else: - model_data = getattr(model_obj, - col['field_name']) - - # We might have a model function as the field so - # call it to return the data needed - if isinstance(model_data, types.MethodType): - model_data = model_data() - - required_data[col['field_name']] = model_data - - data['rows'].append(required_data) - - except FieldError: - # pass it to the user - programming-error here - raise + model_data = getattr(model_obj, + col['field_name']) + + # We might have a model function as the field so + # call it to return the data needed + if isinstance(model_data, types.MethodType): + model_data = model_data() + + required_data[col['field_name']] = model_data + + data['rows'].append(required_data) # apply any row data customization override before converted to JSON data = self.apply_row_customization(data) |