1414from django .core .validators import MinValueValidator
1515from django .db import models
1616from django .utils import timezone
17- from modeltranslation .utils import build_localized_fieldname
1817from django .apps import apps
1918
2019from core import models as core_models
@@ -211,7 +210,7 @@ def get_press(request):
211210 def journals (self , ** filters ):
212211 Journal = apps .get_model ("journal" , "Journal" )
213212 journals = Journal .objects .filter (** filters )
214- return self . apply_journal_ordering (journals )
213+ return Journal . objects . _apply_ordering (journals )
215214
216215 @property
217216 def active_news_items (self ):
@@ -373,7 +372,8 @@ def publishes_conferences(self):
373372
374373 @property
375374 def publishes_journals (self ):
376- return self .public_journals .count () > 0
375+ Journal = apps .get_model ("journal" , "Journal" )
376+ return Journal .objects .public_journals .count () > 0
377377
378378 @cache (600 )
379379 def live_repositories (self ):
@@ -428,37 +428,6 @@ def navigation_items_for_sitemap(self):
428428 def code (self ):
429429 return "press"
430430
431- def apply_journal_ordering_az (self , journals ):
432- """
433- Order a queryset of journals A-Z on English-language journal name.
434- Note that this does not support multilingual journal names:
435- more work is needed on django-modeltranslation to
436- support Django subqueries.
437- :param journals: Queryset of Journal objects
438- """
439- localized_column = build_localized_fieldname (
440- "value" ,
441- settings .LANGUAGE_CODE , # Assumed to be 'en' in default config
442- )
443- name = core_models .SettingValue .objects .filter (
444- journal = models .OuterRef ("pk" ),
445- setting__name = "journal_name" ,
446- )
447- journals .annotate (
448- journal_name = models .Subquery (
449- name .values_list (localized_column , flat = True )[:1 ],
450- output_field = models .CharField (),
451- )
452- )
453- return journals .order_by ("journal_name" )
454-
455- def apply_journal_ordering (self , journals ):
456- if self .order_journals_az :
457- return self .apply_journal_ordering_az (journals )
458- else :
459- # Journals will already have been ordered according to Meta.ordering
460- return journals
461-
462431 @property
463432 def journals_az (self ):
464433 """
@@ -469,68 +438,7 @@ def journals_az(self):
469438 "Use `Press.journals` with Press.order_journals_az turned on."
470439 )
471440 Journal = apps .get_model ("journal" , "Journal" )
472- return self .apply_journal_ordering_az (Journal .objects .all ())
473-
474- @property
475- def public_journals (self ):
476- """
477- Get all journals that are not hidden from the press
478- or designated as conferences.
479- Do not apply ordering yet,
480- since the caller may filter the queryset.
481- """
482- Journal = apps .get_model ("journal" , "Journal" )
483- return Journal .objects .filter (
484- hide_from_press = False ,
485- is_conference = False ,
486- )
487-
488- @property
489- def public_active_journals (self ):
490- """
491- Get all journals that are visible to the press
492- and marked as 'Active' or 'Test' in the publishing status field.
493-
494- Note: Test journals are included so that users can test the journal
495- list safely. A separate mechanism exists to hide them from the press
496- once the press enters normal operation:
497- Journal.hide_from_press.
498- """
499- Journal = apps .get_model ("journal.Journal" )
500- return self .apply_journal_ordering (
501- self .public_journals .filter (
502- status__in = [
503- Journal .PublishingStatus .ACTIVE ,
504- Journal .PublishingStatus .TEST ,
505- ]
506- )
507- )
508-
509- @property
510- def public_archived_journals (self ):
511- """
512- Get all journals that are visible to the press
513- and marked as 'Archived' in the publishing status field.
514- """
515- Journal = apps .get_model ("journal.Journal" )
516- return self .apply_journal_ordering (
517- self .public_journals .filter (
518- status = Journal .PublishingStatus .ARCHIVED ,
519- )
520- )
521-
522- @property
523- def public_coming_soon_journals (self ):
524- """
525- Get all journals that are visible to the press
526- and marked as 'Coming soon' in the publishing status field.
527- """
528- Journal = apps .get_model ("journal.Journal" )
529- return self .apply_journal_ordering (
530- self .public_journals .filter (
531- status = Journal .PublishingStatus .COMING_SOON ,
532- )
533- )
441+ return Journal .objects ._apply_ordering_az (Journal .objects .filter ())
534442
535443 @property
536444 def published_articles (self ):
0 commit comments