def _book_data(self, book):
        persons_pks = [person.pk for person in book.mentions_persons.all()]
        mentions_persons = fields.pack_ids(persons_pks)

        return {
            'author': str(book.author.pk),
            'name': book.name,
            'mentions_persons': mentions_persons
        }
    def _book_data(self, book):
        persons_pks = [person.pk for person in book.mentions_persons.all()]
        mentions_persons = fields.pack_ids(persons_pks)

        return {
            'author': str(book.author.pk),
            'name': book.name,
            'mentions_persons': mentions_persons
        }
Ejemplo n.º 3
0
    def render(self, name, value, attrs=None):
        if value is None:
            value = []

        final_attrs = self.build_attrs(self.attrs)
        final_attrs.update(attrs or {})
        final_attrs.pop('required', None)
        self.html_id = final_attrs.pop('id', name)

        lookup = registry.get(self.channel)

        objects = lookup.get_objects(value)  # always call to get_objects!!!

        current_ids = pack_ids([obj.pk for obj in objects])

        initial = [[lookup.format_item_display(obj), obj.pk]
                   for obj in objects]

        if self.show_help_text:
            help_text = self.help_text
        else:
            help_text = ''

        context = {
            'name': name,
            'html_id': self.html_id,
            'current': value,
            'current_ids': current_ids,
            'current_reprs': mark_safe(json.dumps(initial)),
            'help_text': help_text,
            'extra_attrs': mark_safe(flatatt(final_attrs)),
            'func_slug': self.html_id.replace("-", ""),
            'add_link': self.add_link,
        }
        context.update(
            make_plugin_options(lookup, self.channel, self.plugin_options,
                                initial))
        templates = ('ajax_select/autocompleteselectmultiple_%s.html' %
                     self.channel,
                     'ajax_select/autocompleteselectmultiple.html')
        out = render_to_string(templates, context)
        return mark_safe(out)