Пример #1
0
    def get(self, request, obj_id=None):
        from apps.realms import get_realms
        if obj_id is None:  # Запрошен список всех известных категорий.
            item = get_category_lists(
                init_kwargs={
                    'show_title': True,
                    'show_links': lambda cat: reverse(self.realm.get_details_urlname(), args=[cat.id])
                },
                additional_parents_aliases=get_category_aliases_under())
            return self.render(request, {'item': item})

        # Выводим список материалов (разбитых по областям сайта) для конкретной категории.
        category_model = get_category_model()
        category = get_object_or_404(category_model.objects.select_related('parent'), pk=obj_id)

        realm_list = []
        for realm in get_realms():
            if hasattr(realm.model, 'categories'):  # ModelWithCategory
                objs = realm.model.get_objects_in_category(category)[:5]
                if objs:
                    realm_list.append({
                        'objects': objs,
                        'url': reverse(realm.get_tags_urlname(), args=[category.id]),
                        'realm': realm
                    })

        return self.render(request, {self.realm.name: category, 'item': category, 'realm_list': realm_list})
Пример #2
0
def index(request):
    """Индексная страница."""
    from .realms import get_realms

    realms_data = []
    realms_registry = get_realms()

    externals = ExternalResource.objects.filter(realm_name__in=realms_registry.keys())
    externals = {k: list(v) for k, v in groupby(externals, attrgetter('realm_name'))}

    max_additional = 5

    for name, realm in realms_registry.items():
        if not realm.show_on_main:
            continue

        realm_externals = externals.get(name, [])
        count_externals = len(realm_externals)

        count_locals = 1
        if count_externals < max_additional:
            count_locals += max_additional - count_externals

        realm_locals = realm.model.get_actual()[:count_locals]

        main = realm_locals[0]
        additional = list(realm_locals[1:]) + realm_externals

        realms_data.append({
            'cls': realm,
            'main': main,
            'additional': additional,
        })

    return render(request, 'index.html', {'realms_data': realms_data})
Пример #3
0
def index(request):
    """Индексная страница."""
    from .realms import get_realms

    realms_data = []
    realms_registry = get_realms()

    externals = ExternalResource.objects.filter(realm_name__in=realms_registry.keys())
    externals = {k: list(v) for k, v in groupby(externals, attrgetter('realm_name'))}

    for name, realm in realms_registry.items():
        if not realm.show_on_main:
            continue

        realm_externals = externals.get(name, [])
        locals_count = 1
        if not realm_externals:
            locals_count = 2

        realms_data.append({
            'cls': realm,
            'locals': realm.model.get_actual()[:locals_count],
            'externals': realm_externals,
        })

    return render(request, 'index.html', {'realms_data': realms_data})
Пример #4
0
    def get(self, request, obj_id=None):
        from apps.realms import get_realms
        realms = get_realms().values()

        if obj_id is None:  # Запрошен список всех известных категорий.
            item = get_category_lists(
                init_kwargs={
                    'show_title': True,
                    'show_links': lambda cat: reverse(self.realm.get_details_urlname(), args=[cat.id])
                },
                additional_parents_aliases=get_category_aliases_under())
            return self.render(request, {'item': item, 'realms': realms})

        # Выводим список материалов (разбитых по областям сайта) для конкретной категории.
        category = get_object_or_404(Category.objects.select_related('parent'), pk=obj_id)

        realms_links = OrderedDict()
        for realm in realms:
            realm_model = realm.model

            if not hasattr(realm_model, 'categories'):  # ModelWithCategory
                continue

            items = realm_model.get_objects_in_category(category)

            if not items:
                continue

            realm_title = realm_model.get_verbose_name_plural()

            _, plural = realm.get_names()

            realms_links[realm_title] = (plural, items)

        return self.render(request, {self.realm.name: category, 'item': category, 'realms_links': realms_links})
Пример #5
0
    def ready(self):
        from apps.realms import get_realms

        for realm in get_realms().values():
            # Привязываем область к моделям, она понадобится для вычисления URL.
            realm.model.realm = realm

        # Регистрируем фоновые задания, путём импорта любого символа.
        from .tasks import task_send_messages
Пример #6
0
    def get(self, request, obj_id=None):
        from apps.realms import get_realms
        realms = get_realms().values()

        if obj_id is None:  # Запрошен список всех известных категорий.
            item = get_category_lists(
                init_kwargs={
                    'show_title':
                    True,
                    'show_links':
                    lambda cat: reverse(self.realm.get_details_urlname(),
                                        args=[cat.id])
                },
                additional_parents_aliases=get_category_aliases_under())
            return self.render(request, {'item': item, 'realms': realms})

        # Выводим список материалов (разбитых по областям сайта) для конкретной категории.
        category_model = get_category_model()
        category = get_object_or_404(
            category_model.objects.select_related('parent'), pk=obj_id)

        realms_links = OrderedDict()
        for realm in realms:
            realm_model = realm.model

            if not hasattr(realm_model, 'categories'):  # ModelWithCategory
                continue

            items = realm_model.get_objects_in_category(category)

            if not items:
                continue

            realm_title = realm_model.get_verbose_name_plural()

            _, plural = realm.get_names()

            realms_links[realm_title] = (plural, items)

        return self.render(
            request, {
                self.realm.name: category,
                'item': category,
                'realms_links': realms_links
            })
Пример #7
0
def index(request):
    """Индексная страница."""
    from .realms import get_realms

    realms_data = []
    realms_registry = get_realms()

    externals = ExternalResource.objects.filter(
        realm_name__in=realms_registry.keys())
    externals = {
        k: list(v)
        for k, v in groupby(externals, attrgetter('realm_name'))
    }

    max_additional = 5

    for name, realm in realms_registry.items():
        if not realm.show_on_main:
            continue

        realm_externals = externals.get(name, [])
        count_externals = len(realm_externals)

        count_locals = 1
        if count_externals < max_additional:
            count_locals += max_additional - count_externals

        realm_locals = realm.model.get_actual()[:count_locals]

        if realm_locals:
            main = realm_locals[0]
            additional = list(
                realm_locals[1:]) + realm_externals[:max_additional]
        else:
            main = {}
            additional = []

        realms_data.append({
            'cls': realm,
            'main': main,
            'additional': additional,
        })

    return render(request, 'index.html', {'realms_data': realms_data})
Пример #8
0
 def ready(self):
     from apps.realms import get_realms
     for realm in get_realms():
         realm.model.realm = realm  # Привязываем область к моделям, она понадобится для вычисления URL.
Пример #9
0
def index(request):
    from .realms import get_realms
    return render(request, 'index.html', {'realms': get_realms()})