Esempio n. 1
0
 def get_formsets(self, request, obj=None):
     if not obj:
         raise StopIteration()
     types = defaultdict(lambda: 0)
     for label, variable in get_variables_from_template(obj.template.path).items():
         types[variable['type']] += 1
     for inline in self.inline_instances:
         if inline.model in types:
             inline.max_num = types[inline.model]
             yield inline.get_formset(request, obj)
Esempio n. 2
0
 def render(self, context, instance, placeholder):
     context = super(TextPluginNextGeneration, self).render(context, instance, placeholder)
     t = template.loader.get_template(instance.template.path)
     variables = get_variables_from_template(t)
     for label, variable in variables.items():
         model_type = variable['type']
         var, created = model_type.objects.select_related(*model_type.select_related).get_or_create(text_ng=instance, label=label)
         context[label] = var.value
     context.update({'body': mark_safe(t.render(context))})
     return context
 def save_model(self, request, obj, form, change):
     super(TextPluginNextGeneration,
           self).save_model(request, obj, form, change)
     for label, variable in get_variables_from_template(
             obj.template.path).items():
         model_class = variable['type']
         initial_field_values = variable['initial_field_values']
         model_class.objects.get_or_create(text_ng=obj,
                                           label=label,
                                           defaults=initial_field_values)
Esempio n. 4
0
 def render(self, context, instance, placeholder):
     context = super(TextPluginNextGeneration, self).render(context, instance, placeholder)
     t = template.loader.get_template(instance.template.path)
     variables = get_variables_from_template(t)
     for label, variable in variables.items():
         model_type = variable['type']
         var, created = model_type.objects.select_related(*model_type.select_related).get_or_create(text_ng=instance, label=label)
         context[label] = var.value
     context.update({'body': mark_safe(t.render(context))})
     return context
 def save_model(self, request, obj, form, change):
     super(TextPluginNextGeneration, self).save_model(request, obj, form, change)
     for label, variable in get_variables_from_template(obj.template.path).items():
         model_class = variable['type']
         initial_field_values = variable['initial_field_values']
         model_class.objects.get_or_create(
             text_ng=obj,
             label=label,
             defaults=initial_field_values
         )
Esempio n. 6
0
 def change_view(self, request, object_id, extra_context=None, form_url=''):
     obj = self.get_object(request, object_id)
     types = defaultdict(lambda: 0)
     for label, variable in get_variables_from_template(obj.template.path).items():
         types[variable['type']] += 1
         variable['type'].objects.get_or_create(text_ng=obj, label=label)
     self.inline_instances = []
     self.inlines = []
     for model_class in types.keys():
         inline = self.get_inline_for_model(model_class)
         inline.max_num = types[model_class]
         self.inlines.append(inline)
         self.inline_instances.append(inline(self.model, self.admin_site))
     return super(TextPluginNextGeneration, self).change_view(request, object_id, extra_context=extra_context, form_url=form_url)
Esempio n. 7
0
    def get_inline_instances(self, request, obj=None):
        inline_instances = []

        if obj and obj.pk:
            types = defaultdict(lambda: 0)

            for label, variable in get_variables_from_template(obj.template.path).items():
                types[variable['type']] += 1
                variable['type'].objects.get_or_create(text_ng=obj, label=label)

            for model_class in types.keys():
                inline = self.get_inline_for_model(model_class)
                inline.max_num = types[model_class]
                inline_instances.append(inline(self.model, self.admin_site))
        return inline_instances
    def render(self, context, instance, placeholder):
        context = super(TextPluginNextGeneration,
                        self).render(context, instance, placeholder)
        template = get_template(instance.template.path)
        variables = get_variables_from_template(template)

        for label, variable in variables.items():
            model_class = variable['type']
            initial_field_values = variable['initial_field_values']
            instance_context_name = '%s_instance' % label
            model_queryset = model_class.objects.select_related(
                *model_class.select_related)
            var = model_queryset.get_or_create(
                text_ng=instance, label=label,
                defaults=initial_field_values)[0]
            context[label] = var.value
            context[instance_context_name] = var
        context.update({'body': mark_safe(template.render(context))})
        return context
    def render(self, context, instance, placeholder):
        context = super(TextPluginNextGeneration, self).render(context, instance, placeholder)
        template = get_template(instance.template.path)
        variables = get_variables_from_template(template)

        for label, variable in variables.items():
            model_class = variable['type']
            initial_field_values = variable['initial_field_values']
            instance_context_name = '%s_instance'% label
            model_queryset = model_class.objects.select_related(*model_class.select_related)
            var = model_queryset.get_or_create(
                text_ng=instance,
                label=label,
                defaults=initial_field_values
            )[0]
            context[label] = var.value
            context[instance_context_name] = var
        context.update({'body': mark_safe(template.render(context))})
        return context
    def get_inline_instances(self, request, obj=None):
        inline_instances = []

        if obj and obj.pk:
            variables = get_variables_from_template(obj.template.path).items()
            types = SortedDict()
            for label, variable in variables:
                model_class = variable['type']
                initial_field_values = variable['initial_field_values']
                types[model_class] = types.get(model_class,
                                               0)  # can't use defaultdict :(
                types[model_class] += 1
                model_class.objects.get_or_create(
                    text_ng=obj, label=label, defaults=initial_field_values)

            for model_class in types.keys():
                inline = self.get_inline_for_model(model_class)
                inline.max_num = types[model_class]
                inline_instance = inline(self.model, self.admin_site)
                inline_instances.append(inline_instance)
        return inline_instances
    def get_inline_instances(self, request, obj=None):
        inline_instances = []

        if obj and obj.pk:
            variables = get_variables_from_template(obj.template.path).items()
            types = defaultdict(int)
            for label, variable in variables:
                model_class = variable['type']
                initial_field_values = variable['initial_field_values']
                types[model_class] += 1
                model_class.objects.get_or_create(
                    text_ng=obj,
                    label=label,
                    defaults=initial_field_values
                )

            for model_class in types.keys():
                inline = self.get_inline_for_model(model_class)
                inline.max_num = types[model_class]
                inline_instance = inline(self.model, self.admin_site)
                inline_instances.append(inline_instance)
        return inline_instances
Esempio n. 12
0
 def save_model(self, request, obj, form, change):
     super(TextPluginNextGeneration, self).save_model(request, obj, form, change)
     for label, variable in get_variables_from_template(obj.template.path).items():
         variable['type'].objects.get_or_create(text_ng=obj, label=label)
Esempio n. 13
0
 def save_model(self, request, obj, form, change):
     super(TextPluginNextGeneration, self).save_model(request, obj, form, change)
     for label, variable in get_variables_from_template(obj.template.path).items():
         variable['type'].objects.get_or_create(text_ng=obj, label=label)