def get_all_entity_publications(context, entity = None): """ Lists all the Entity's articles """ if entity == None: entity = work_out_entity(context, entity) if entity.abstract_entity: real_entity = entity._get_real_ancestor else: real_entity = entity all_publications = BibliographicRecord.objects.filter( authored__visible = True, authored__researcher__person__member_of__entity__in=real_entity.get_descendants(include_self=True)) \ .distinct() \ .order_by('publication__type', '-publication_date') ordered_publications = [] for information in PUBLICATION_INFORMATION: publication_type = information['type'] # because we cant use information['type'] inside a .filter() publications = all_publications.filter(publication__type = publication_type).order_by('-publication_date',) for publication in publications: publication.kind = information['name'] ordered_publications.append(publication) return { "all_publications": ordered_publications, }
def get_selected_entity_publications(context, heading=None, format = "short", max_items = 20, entity = None): """ Lists Entity's selected articles """ selected_publications = [] if entity == None: entity = work_out_entity(context, entity) if entity.abstract_entity: real_entity = entity._get_real_ancestor else: real_entity = entity all_publications = BibliographicRecord.objects.filter(authored__visible = True, authored__researcher__person__member_of__entity__in=real_entity.get_descendants(include_self=True) ).distinct() for information in PUBLICATION_INFORMATION: publication_type = information['type'] # because we want to use it a bit later publications = all_publications.filter(publication__type = publication_type) for publication in publications: publication.template = "includes/" + publication_type + ".html" selected_publications.append(publication) selected_publications.sort(reverse = True, key=operator.attrgetter('publication_date')) #selected_publications.sort(key=lambda x: x[0].publication_date) return {"selected_publications": selected_publications[0:max_items], "heading": heading, "format": format, "entity": entity,}
def render(self, context, instance, placeholder): LINK_ATTRIBUTES = { "news-and-events": "news_page_menu_title", "contacts-and-people": "contacts_page_menu_title", "publications": "publications_page_menu_title", "vacancies-and-studentships": "vacancies_page_menu_title", } EntityAutoPageLinkPluginEditor.AUTO_PAGES print "-- in render of CMSContactsAndPeoplePlugin --" # find out what kind of information we're linking to LINK_TUPLE = EntityAutoPageLinkPluginEditor.AUTO_PAGES[instance.link_to] print "LINK_TUPLE", LINK_TUPLE entity = work_out_entity(context, None) if instance.entity and instance.entity != entity: link = instance.entity.get_absolute_url() + LINK_TUPLE[1] link_title = instance.entity.short_name + ': ' + getattr(entity,LINK_TUPLE[2]) else: link_title = getattr(entity,LINK_TUPLE[2]) link = entity.get_absolute_url() + LINK_TUPLE[1] if instance.text_override: link_title = instance.text_override print EntityAutoPageLinkPluginEditor.AUTO_PAGES[instance.link_to][2] context.update({ 'link': link, 'link_title': link_title, }) return context
def render(self, context, instance, placeholder): print "in EntityDirectoryPluginPublisher" if instance.entity: entity = instance.entity else: entity = work_out_entity(context, None) root_entity = entity descendants = entity.get_descendants() if descendants: # find our base level first_level = descendants[0].level # filter to maximum sub-level depth if instance.levels: maximum_level = first_level + instance.levels descendants = descendants.filter(level__lt = maximum_level) # apply all the attributes we need to our descendant entities for descendant in descendants: # reset the level, so that first_level is 0 descendant.level = descendant.level - first_level if descendant.website and (descendant.level < instance.display_descriptions_to_level or instance.display_descriptions_to_level == None): descendant.description = descendant.website.get_meta_description() context.update({ 'entities': descendants, 'directory': instance, }) return context
def render(self, context, instance, placeholder): print "-- in render of CMSVacanciesPlugin --" if instance.entity: entity = instance.entity else: entity = work_out_entity(context, None) vacancies = studentships = [] more_vacancies = False max_items = instance.limit_to more_studentships = False print "instance.display", instance.display if instance.heading_level == 0: instance.heading_level = None if instance.display == 0 or instance.display == 1: print "getting vacancies" vacancies = Vacancy.objects.filter( Q(hosted_by__in=entity.get_descendants(include_self = True)) | Q(also_advertise_on__in=entity.get_descendants(include_self = True)), closing_date__gte = items_expire_after ).distinct() if len(vacancies) > max_items: more_vacancies = True if instance.display == 0 or instance.display == 2: print "getting studentships" studentships = Studentship.objects.filter( Q(hosted_by__in=entity.get_descendants(include_self = True)) | Q(also_advertise_on__in=entity.get_descendants(include_self = True)), closing_date__gte = items_expire_after ).distinct() if len(studentships) > max_items: more_studentships = True cols = "columns1" vacancies_class = studentships_class = "firstcolumn" if vacancies and studentships: cols="columns2" vacancies_class = "firstcolumn" studentships_class = "lastcolumn" print "entity:",entity print "format:", instance.get_format_display() context.update({ 'entity': entity, 'vacancies': vacancies, 'studentships': studentships, 'format': instance.get_format_display(), 'heading_level': instance.heading_level, 'vacancies_heading': instance.vacancies_heading_text, 'studentships_heading': instance.studentships_heading_text, 'vacancies_class': vacancies_class, 'studentships_class': studentships_class, 'more_vacancies': more_vacancies, 'more_studentships': more_studentships, 'vacancies': vacancies[0: max_items], 'studentships': studentships[0: max_items], 'more_vacancies_link': instance.more_vacancies_link, 'more_studentships_link': instance.more_studentships_link, 'cols': cols, 'object': instance, 'placeholder': placeholder, }) print "returning from render of CMSVacanciesPlugin" return context
def render(self, context, instance, placeholder): #print self.render_template instance.entity = getattr(instance, "entity", None) or work_out_entity(context, None) instance.type = getattr(instance, "type", "plugin") try: render_template = instance.render_template except AttributeError: pass get_news_and_events(instance) context.update({ 'everything': instance, 'placeholder': placeholder, }) return context
def render(self, context, instance, placeholder): instance.entity = getattr(instance, "entity", None) or work_out_entity(context, None) self.set_defaults(instance) self.get_items(instance) self.add_link_to_main_page(instance) self.add_links_to_other_items(instance) self.set_limits_and_indexes(instance) self.determine_layout_settings(instance) self.set_layout_classes(instance) instance.lists = self.lists context.update({ 'everything': instance, 'placeholder': placeholder, }) return context
def render(self, context, instance, placeholder): instance.entity = getattr(instance, "entity", None) or work_out_entity( context, None) self.set_defaults(instance) self.get_items(instance) self.add_link_to_main_page(instance) self.add_links_to_other_items(instance) self.set_limits_and_indexes(instance) self.determine_layout_settings(instance) self.set_layout_classes(instance) instance.lists = self.lists context.update({ 'everything': instance, 'placeholder': placeholder, }) return context
def render(self, context, instance, placeholder): self.entity = getattr(instance, "entity", None) or \ work_out_entity(context, None) self.lister = PublicationsLister( listkinds=[ ("publications", PublicationsListLatest), ], entity=self.entity, limit_to=instance.limit_to, item_format=instance.format, favourites_only=instance.favourites_only, ) context.update({ 'lister': self.lister, 'placeholder': placeholder, }) return context
def render(self, context, instance, placeholder): self.entity = getattr(instance, "entity", None) or \ work_out_entity(context, None) self.lister = VacanciesAndStudentshipsPluginLister( entity=self.entity, display=instance.display, order_by=instance.order_by, layout=instance.layout, limit_to=instance.limit_to, item_format=instance.format, list_format=instance.list_format, # request=instance.request ) context.update({ 'lister': self.lister, 'placeholder': placeholder, }) return context
def render(self, context, instance, placeholder): #print self.render_template print "-- in render of CMSNewsAndEventsPlugin --" instance.entity = instance.entity or work_out_entity(context, None) instance.type = "plugin" try: render_template = instance.render_template except AttributeError: pass get_news_and_events(instance) context.update({ 'entity': instance.entity, 'news': instance.news, 'actual_events': instance.events, 'layout': instance.layout, 'news_and_events': instance, 'placeholder': placeholder, }) print "returning context" return context
def render(self, context, instance, placeholder): if instance.entity: entity = instance.entity else: entity = work_out_entity(context, None) print "ok so far" entities = entity.get_descendants(include_self = True) memberships = Membership.objects.filter(entity__in = entities).order_by('entity', '-importance_to_entity') nest = memberships.values('entity',).distinct().count() > 1 or False print nest print "returning context" context.update({ 'entity': entity, 'memberships': memberships, 'nest': nest, }) return context
def render(self, context, instance, placeholder): # get a tuple containing for example: # (u'Contacts & people', 'contact', 'contacts_page_menu_title') LINK_TUPLE = EntityAutoPageLinkPluginEditor.AUTO_PAGES[instance.link_to] kind = LINK_TUPLE[1] field_name = LINK_TUPLE[2] entity = work_out_entity(context, None) if entity or instance.entity: link = instance.entity.get_related_info_page_url(kind) if instance.entity and instance.entity != entity: link_title = instance.entity.short_name + ': ' + getattr(instance.entity,field_name) else: link_title = getattr(instance.entity, field_name) if instance.text_override: link_title = instance.text_override context.update({ 'link': link, 'link_title': link_title, }) return context