def index(request): """ Press index page, displays blocks of HomepageElement objects :param request: HttpRequest object :return: HttpResponse object or journal_views.home if there is a request,journal """ if request.journal is not None: # if there's a journal, then we render the _journal_ homepage, not the press return journal_views.home(request) homepage_elements = core_models.HomepageElement.objects.filter( content_type=request.model_content_type, object_id=request.press.pk, active=True).order_by('sequence') template = "press/press_index.html" context = { 'homepage_elements': homepage_elements, } # call all registered plugin block hooks to get relevant contexts for hook in settings.PLUGIN_HOOKS.get('yield_homepage_element_context', []): hook_module = plugin_loader.import_module(hook.get('module')) function = getattr(hook_module, hook.get('function')) element_context = function(request, homepage_elements) for k, v in element_context.items(): context[k] = v return render(request, template, context)
def home(request): """ Renders a journal homepage. :param request: the request associated with this call :return: a rendered template of the journal homepage """ issues_objects = models.Issue.objects.filter(journal=request.journal) sections = submission_models.Section.objects.filter( journal=request.journal) homepage_elements = core_models.HomepageElement.objects.filter( content_type=request.model_content_type, object_id=request.journal.pk, active=True).order_by('sequence') template = 'journal/index.html' context = { 'homepage_elements': homepage_elements, 'issues': issues_objects, 'sections': sections, } # call all registered plugin block hooks to get relevant contexts for hook in settings.PLUGIN_HOOKS.get('yield_homepage_element_context', []): hook_module = plugin_loader.import_module(hook.get('module')) function = getattr(hook_module, hook.get('function')) element_context = function(request, homepage_elements) for k, v in element_context.items(): context[k] = v return render(request, template, context)