|
1 | 1 | import graphene |
| 2 | +from django.conf import settings |
2 | 3 | from django.contrib.contenttypes.models import ContentType |
3 | 4 | from django.dispatch import receiver |
4 | 5 | from django.utils.translation import gettext_lazy as _ |
@@ -223,20 +224,29 @@ def PagesQuery(): |
223 | 224 | registry.pages[type(WagtailPage)] = Page |
224 | 225 |
|
225 | 226 | class Mixin: |
226 | | - pages = QuerySetList( |
227 | | - graphene.NonNull(lambda: PageInterface), |
228 | | - content_type=graphene.Argument( |
| 227 | + pages_kwargs = { |
| 228 | + "content_type": graphene.Argument( |
229 | 229 | graphene.String, |
230 | 230 | description=_("Filter by content type. Uses the `app.Model` notation."), |
231 | 231 | ), |
232 | | - in_site=graphene.Argument( |
| 232 | + "in_site": graphene.Argument( |
233 | 233 | graphene.Boolean, |
234 | 234 | description=_("Filter to pages in the current site only."), |
235 | 235 | default_value=False, |
236 | 236 | ), |
237 | | - enable_search=True, |
238 | | - required=True, |
239 | | - ) |
| 237 | + "enable_search": True, |
| 238 | + "required": True, |
| 239 | + } |
| 240 | + if getattr(settings, "WAGTAIL_I18N_ENABLED", False): |
| 241 | + pages_kwargs["language_code"] = graphene.Argument( |
| 242 | + graphene.String, |
| 243 | + description=_( |
| 244 | + "Filter to pages with the given language code as defined in `WAGTAIL_CONTENT_LANGUAGES`." |
| 245 | + ), |
| 246 | + ) |
| 247 | + |
| 248 | + pages = QuerySetList(graphene.NonNull(lambda: PageInterface), **pages_kwargs) |
| 249 | + |
240 | 250 | page = graphene.Field( |
241 | 251 | PageInterface, |
242 | 252 | id=graphene.Int(), |
@@ -289,6 +299,10 @@ def resolve_pages(self, info, **kwargs): |
289 | 299 | else: |
290 | 300 | pages = pages.filter(content_type=ctype) |
291 | 301 |
|
| 302 | + language_code = kwargs.pop("language_code", "") |
| 303 | + if language_code and getattr(settings, "WAGTAIL_I18N_ENABLED", False): |
| 304 | + pages = pages.filter(locale__language_code=language_code) |
| 305 | + |
292 | 306 | return resolve_queryset(pages, info, **kwargs) |
293 | 307 |
|
294 | 308 | # Return a specific page, identified by ID or Slug. |
|
0 commit comments