def get_context_data(self, **kwargs):
     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[self.context_filter_name] = self.filter
     context['docstring'] = "{}".format(self.model.__doc__)
     if self.model._meta.verbose_name_plural:
         context['class_name'] = "{}".format(self.model._meta.verbose_name.title())
     else:
         if self.model.__name__.endswith('s'):
             context['class_name'] = "{}".format(self.model.__name__)
         else:
             context['class_name'] = "{}s".format(self.model.__name__)
     try:
         context['get_arche_dump'] = self.model.get_arche_dump()
     except AttributeError:
         context['get_arche_dump'] = None
     try:
         context['create_view_link'] = self.model.get_createview_url()
     except AttributeError:
         context['create_view_link'] = None
     try:
         context['download'] = self.model.get_dl_url()
     except AttributeError:
         context['download'] = None
     model_name = self.model.__name__.lower()
     context['entity'] = model_name
     context['app_name'] = self.model._meta.app_label
     context['conf_items'] = list(
         BrowsConf.objects.filter(model_name=model_name)
         .values_list('field_path', '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
         )
         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'],
                 qs,
                 app_label=app_label
             )
             context = dict(context, **chartdata)
     return context
Exemple #2
0
 def get_context_data(self, **kwargs):
     context = super(GenericListViewNew, self).get_context_data()
     context[self.context_filter_name] = self.filter
     context['entity'] = self.entity
     context['vis_list'] = ChartConfig.objects.filter(
         model_name=self.entity)
     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'], qs)
         context = dict(context, **chartdata)
     # context['entity_create_stanbol'] = GenericEntitiesStanbolForm(self.entity)
     return context
Exemple #3
0
    def get_context_data(self, **kwargs):
        context = super(GenericListView, self).get_context_data()
        context[self.context_filter_name] = self.filter
        context['docstring'] = "{}".format(self.model.__doc__)
        if self.model.__name__.endswith('s'):
            context['class_name'] = "{}".format(self.model.__name__)
        else:
            context['class_name'] = "{}s".format(self.model.__name__)
        try:
            context['get_arche_dump'] = self.model.get_arche_dump()
        except AttributeError:
            context['get_arche_dump'] = None
        try:
            context['create_view_link'] = self.model.get_createview_url()
        except AttributeError:
            context['create_view_link'] = None
        try:
            context['dl_csv_link'] = self.model.dl_csv_link()
        except AttributeError:
            context['dl_csv_link'] = None

        model_name = self.model.__name__.lower()
        context['conf_items'] = list(
            BrowsConf.objects.filter(model_name=model_name).values_list(
                'field_path', 'label'))

        context['entity'] = model_name
        print(context['entity'])
        context['vis_list'] = ChartConfig.objects.filter(model_name=model_name)
        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'], qs)
            context = dict(context, **chartdata)
            print(chartdata)
        return context
Exemple #4
0
    def get_context_data(self, **kwargs):
        model = self.get_model()
        context = super(GenericListViewNew, self).get_context_data()
        context[self.context_filter_name] = self.filter
        context['entity'] = self.entity
        context['app_name'] = 'apis_entities'
        entity = self.entity.title()
        context['entity_create_stanbol'] = GenericEntitiesStanbolForm(
            self.entity)
        if 'browsing' in settings.INSTALLED_APPS:
            from browsing.models import BrowsConf
            context['conf_items'] = list(
                BrowsConf.objects.filter(model_name=self.entity).values_list(
                    'field_path', 'label'))
        context['docstring'] = "{}".format(model.__doc__)
        if model._meta.verbose_name_plural:
            context['class_name'] = "{}".format(
                model._meta.verbose_name.title())
        else:
            if model.__name__.endswith('s'):
                context['class_name'] = "{}".format(model.__name__)
            else:
                context['class_name'] = "{}s".format(model.__name__)
        try:
            context['get_arche_dump'] = model.get_arche_dump()
        except AttributeError:
            context['get_arche_dump'] = None
        try:
            context['create_view_link'] = model.get_createview_url()
        except AttributeError:
            context['create_view_link'] = None
        if 'charts' in settings.INSTALLED_APPS:
            app_label = model._meta.app_label
            filtered_objs = ChartConfig.objects.filter(
                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']:
                qs = self.get_queryset()
                chartdata = create_payload(context['entity'],
                                           context['property_name'],
                                           context['charttype'],
                                           qs,
                                           app_label=app_label)
                context = dict(context, **chartdata)
        try:
            context['enable_merge'] = settings.APIS_ENTITIES[
                entity.title()]['merge']
        except KeyError:
            context['enable_merge'] = False
        try:
            togg_cols = settings.APIS_ENTITIES[
                entity.title()]['additional_cols']
        except KeyError:
            togg_cols = []
        if context['enable_merge'] and self.request.user.is_authenticated:
            togg_cols = togg_cols + ['merge']
        context['togglable_colums'] = togg_cols + ENTITIES_DEFAULT_COLS

        return context
Exemple #5
0
 def get_context_data(self, **kwargs):
     context = super(GenericListView, self).get_context_data()
     ct = ContentType.objects.get(
         model=self.model.__name__.lower()).model_class()
     try:
         ct._meta.get_field('polygon')
         poly = True
     except Exception as e:
         poly = False
     if poly:
         points = serialize('geojson',
                            self.get_queryset(),
                            geometry_field='centroid',
                            fields=(
                                'name',
                                'pk',
                            ))
         context['points'] = points
         shapes = serialize('geojson',
                            self.get_queryset(),
                            geometry_field='polygon',
                            fields=(
                                'name',
                                'pk',
                            ))
         context['shapes'] = shapes
     context['self_model_name'] = self.model.__name__.lower()
     context[self.context_filter_name] = self.filter
     context['docstring'] = "{}".format(self.model.__doc__)
     if self.model._meta.verbose_name:
         context['class_name'] = "{}".format(
             self.model._meta.verbose_name.title())
     else:
         context['class_name'] = "{}".format(self.model.__name__)
     try:
         context['get_arche_dump'] = self.model.get_arche_dump()
     except AttributeError:
         context['get_arche_dump'] = None
     try:
         context['create_view_link'] = self.model.get_createview_url()
     except AttributeError:
         context['create_view_link'] = None
     try:
         context['download'] = self.model.get_dl_url()
     except AttributeError:
         context['download'] = None
     model = self.model
     app_label = model._meta.app_label
     context['entity'] = model.__name__.lower()
     filtered_objs = ChartConfig.objects.filter(
         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['self_model_name'] == "site":
         context['enablereldl'] = True
     else:
         context['enablereldl'] = False
     if context['charttype'] and context['property_name']:
         qs = self.get_queryset()
         chartdata = create_payload(context['entity'],
                                    context['property_name'],
                                    context['charttype'],
                                    qs,
                                    app_label=app_label)
         context = dict(context, **chartdata)
     return context