Git Product home page Git Product logo

wagtail-autocomplete's People

Contributors

brianxu20 avatar brylie avatar chigby avatar dependabot[bot] avatar emilyhorsman avatar flipperpa avatar harrislapiroff avatar higs4281 avatar jeromelebleu avatar joep110 avatar joeyjurjens avatar nickmoreton avatar nim65s avatar rrebase avatar saptaks avatar seb-b avatar simon-retsch avatar timonweb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wagtail-autocomplete's Issues

queryset for AutocompletePanel

Thank you for making AutocompletePanel, I look forward to see it merged in the core wagtail project.

I would like AutocompletePanel to only return a subset of objects from the target_model. Is that a feature you would be interested in implementing? Do you have a suggestion for an alternative way to handle this at the moment?

I was hoping that I could do something like ModelAdmin.get_queryset, to be able to filter depending on request.user

Currently using:

  • Django==2.2.4
  • wagtail==2.6.1
  • wagtail-autocomplete==0.3.1

Edit: I asked the same question on StackOverflow

Doesn't work with custom primary keys

The serialising methods seem to rely on the primary_key being the id field. Passing the primary key around explicitly instead would fix this. Assuming it's JSON and URL serialisable

Better handling of missing URLs

If a dev tries to use an AutocompletePanel but doesn't include the URL patterns, we should either throw an exception or at least render a warning.

page history not working on field with AutocompletePanel

I have an AutocompletePanel sucessfuly assigned to one of my fields. Everything works as expected but page history does not reflect changes made to the corresponding field. If I inspect the content_json field of the two PageRevision pages in question, I do see the change. Yet in the admin UI of the "history" of my page where I compare versions they are marked as identical.

Simply switching back to a FieldPanel correctly shows the changes applied in the admin UI.

Am I missing something in my implementation or is this a bug?
Kind regards.

Question: Using Autocomplete widget in FieldBlock

Hello everyone,

Is it supported to use Autocomplete widget in FieldBlock?

I have successfully created it but am not sure if is supported, recommended or best practice.

Code:

class CountryAutocomplete(Autocomplete):
    target_model = Country
    can_create = False
    is_single = False


class CountriesBlock(FieldBlock):
    def __init__(self, required=True, help_text=None, **kwargs):
        self.field = forms.ModelMultipleChoiceField(
            Country.objects.all(), widget=CountryAutocomplete
        )
        super().__init__(**kwargs)

    def get_prep_value(self, value):
        if value is None:
            return None
        return [obj.pk for obj in value]


class VideoBlock(StructBlock):
    countries = CountriesBlock("countries")

If it is, maybe it would be good idea add example to documentation.

Support for Django 3

wagtail 2.8 came up with support for django 3
https://github.com/wagtail/wagtail/blob/master/CHANGELOG.txt#L20

But when upgrading the packages, wagtail-autocomplete breaks:

  File "/home/dori/.virtualenvs/project/lib/python3.8/site-packages/wagtailautocomplete/wagtail_hooks.py", line 1, in <module>
    from django.contrib.staticfiles.templatetags.staticfiles import static
ModuleNotFoundError: No module named 'django.contrib.staticfiles.templatetags'

As per https://stackoverflow.com/a/59935512, we need to import static from django.templatetags.static instead of django.contrib.staticfiles.templatetags.staticfiles

Submit to PyPI

  • Resolve #13
  • Update docs to include pip install wagtail-autocomplete
  • Submit to PyPI

Support a list of page types

Currently you can specify a model other than wagtailcore.Page but only one. We'd like support for multiple types in the future.

Object of type 'UUID' is not JSON serializable

When I define out my AutocompletePanel and the special field, I get the error Object of type 'UUID' is not JSON serializable. I am using a UUIDField as my pk 'id'. Is there any way to get past this error?

WagTail autocomplete for other models

Since when performing filter, the fieldname is either title or the autocomplete_search_field attribute, the render_page should be amended to add returning autocomplete values using autocomplete_search_field attribute of the record.

def render_page(page):
    if getattr(page, 'specific', None):
        # For support of non-Page models like Snippets.
        page = page.specific
    if callable(getattr(page, 'autocomplete_label', None)):
        title = page.autocomplete_label()
    elif getattr(page, 'autocomplete_search_field', None):  # added
        title = getattr(page, getattr(page, 'autocomplete_search_field', None))
    else:
        title = page.title
    return dict(pk=page.pk, title=title)

`page_type` optional, `is_single` removed

Both page_type and is_single should be able to be deduced from the related field.

page_type should be made optional. It should default to whatever model the related field points to. It should remain as an option to account for cases where the developer wants to limit to a model subclass.

is_single should be deprecated. There's no reason to use is_single=True for a ParentalManyToManyField any more than there is to use is_single=False for a ParentalKey.

AutocompletePanel does not work if is used inside "through" model of a manytomany

Example case:

from django.db import models

from modelcluster.models import ClusterableModel
from modelcluster.fields import ParentalKey, ParentalManyToManyField


class Book(ClusterableModel):
    title = models.CharField(max_length=100)
    synopsis = models.TextField()
    # ...
    
    panels = [
        FieldPanel('title'),
        InlinePanel('authors')
    ]


class Author(models.Model):
    name = models.CharField(max_lenght=100)
    # ...

    autocomplete_search_field = 'name'
    
    def autocomplete_label(self):
        return self.name
    
    @classmethod
    def autocomplete_create(cls, name):
        return cls.objects.create(name=name)


class BookAuthor(models.Model):
    ROLES = (
        ('principal', 'Principal'),
        ('collaborator', 'Collaborator'),
        ('reviewer', 'Reviewer'),
    )
    book = ParentalKey(Book, related_name="authors")
    author = models.ForeignKey(Author, on_delete=models.CASCADE)
    role = models.CharField(max_length=15, choices=ROLES)

    panels =  [
        FieldPanel('book'),
        AutocompletePanel('author', page_type=Author),
        FieldPanel('role')
    ]

The problem is that, after pressing "new" button inside book's edition interface, AutocompletePanel does not render anything, but no error appear in js or django console. Simply the field is gone.

I've tried to use ClusterableModel for BookAuthor instead of models.Model and ParentalKey('Author') instead of models.ForeignKey but it still not working, so I think that maybe it is some kind of bug.

More explicit behavior when using with ManyToMany/non-clusterable

Autocomplete requires a clusterable model and a parentalmanytomany field, but if you use a non-clusterable model and a standard manytomany, it just silently fails to write.

Two proposed solutions:

  • Make it work with non-clusterables
  • Have it throw an error/display a warning when someone tries to use it with non-clusterables

Published 0.8.1 release uses wrong colors

When installing the latest release, the autocomplete-widget looks weird:
widget in selected state
search box

It seems like the released package uses a temporarily generated dist.css, with custom colors. If I regenerate the dist.css from scratch as documented here, I get the right colors:
Bildschirmfoto vom 2022-05-31 19-11-47

Needed release of package after release Wagtail 2.9

The latest version of wagtail-autocomplete on the PyPi is 0.5 and is not working with Wagtail 2.9.

There is proper change on the master branch https://github.com/wagtail/wagtail-autocomplete/blob/master/wagtailautocomplete/urls/admin.py which fixes the issue below.

Error:
ModuleNotFoundError: No module named 'wagtail.admin.decorators'

require_admin_access since wagtail 2.9 not exists under wagtail.admin.decorators.

Could you please release a new version?

Add documentation for AutocompletePanel

  • Basic AutocompletePanel usage
  • Transition from PageChooserPanel or SnippetChooserPanel
  • ClusterableModel example
  • Clearer explanation of single vs multi usage
  • Public API
  • Add some illustrative gifs of it in action
  • Custom properties on models: autocomplete_create and autocomplete_label

Add Jest tests

  • Suggestions component renders received suggestions
  • Active suggestion in Suggestions component manipulable by keyboard
  • .search--has-input applied when the component is visible and has suggestions
  • fill me

Expose autocomplete javascript widgets

At pressfreedomtracker, we have used the autocomplete components as part of our react filter, though the flow has been very copy-pasty. It would be better to have a more standardized way of exposing autocomplete javascript widgets so that they can be used outside of the admin fields and in the generated site pages as well.

Autocomplete Manager

As the amount of customization offered on autocompletable objects grows, it seems useful to organize the customizable attributes and methods into a single object. This idea grew out of the discussion in #47.

Currently you can customize autocomplete properties like so:

class MyAutocompletableModel(ClusterableModel):
    name = models.CharField(max_length=255)

    autocomplete_search_field = 'name'

    def autocomplete_label(self):
        return self.name

    @classmethod
    def autocomplete_create(kls: type, value: str):
        return kls.objects.create(name=value)

If implemented now, #36 would add yet another classmethod to the mix. To clean this up and keep it more organized, we'll introduce a new AutocompleteManager type. The default autocomplete manager would look something like this:

class AutocompleteManager(object):
    search_field = 'title'
    label_field = 'title'

    def search(self, model_class: type, value: str) -> QuerySet:
        query_kwargs = {'{}__icontains'.format(self.search_field): value}
        return model_class.objects.filter(**query_kwargs)

    def label(self, obj: models.Model) -> str:
        return getattr(obj, self.label_field)

A subclass of it might look like

class SearchingAutocompleteManager(AutocompleteManager):
    def search(self, model_class: type, value: str) -> QuerySet:
        return model_class.objects.search(value)

    # Notice that no `create` method is specified by default,
    # but can be specified on a subclass
    def create(self, model_class: type, value: str) -> models.Model:
        return model_class.objects.create(title=value)

    def label(self, obj: models.Model) -> str:
        return obj.__unicode__()

You would register a particular manager with a particular target either declaratively:

class MyAutocompletingPage(Page):
    # ...
    autocomplete_manager = SearchingAutocompleteManager()

or with a class decorator:

@autocompletable(SearchingAutocompleteManager())
class MyAutocompletingPage(Page):
    # ...

Handle server errors related to blank API exclusion clauses

When we upgraded to 0.6, we started getting server errors from pages using wagtail-autocomplete.

The autocomplete forms were generating faulty API calls like these:

/admin/autocomplete/search/?query=mortgage&type=ask_cfpb.AnswerPage&exclude=,,
/admin/autocomplete/search/?query=&type=ask_cfpb.AnswerPage&exclude=

I found two problems:

  • There was a mix of variable names 'id' and 'pk' used for primary keys in React code.

  • The search view wasn't catching bad parameters because it was testing an unevaluated query. was swallowing exceptions caused by bad parameters.

These are addressed in PR #77.

Ordering

Thanks for a great project! Like it a lot.

I have a request from a client to be able order the selected objects. Is that something that has been considered for development? Or is it already supported?

Input text hidden behind search icon

The search text is hidden behind the search icon. It seems like the paddin-left: 44px property was overridden and thus not in effect.

Wagtail version: 2.12.2
Django version: 3.1.6
Wagtail autocomplete version: 0.6

image

More elegant solution for deleted objects

Currently, #101 returns a 404 with the message that some objects might be missing or deleted. A more elegant solution would be to provide better error messages and error handling to indicate whether some objects got deleted and which id got deleted instead of returning a generic error message.

Possibility to query multiple fields for autocompleting

Right know we can supply which field the autocomplete should use like so:
autocomplete_search_field = "title_en"

I'm proposing we should allow querying more than one field. E.g.:
autocomplete_search_field = "title_en,title_sv"

Currently I monkey patched this in our project, but I'd be happy to contribute if this is something you'd want in this package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.