-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy patharticle_list.py
More file actions
58 lines (40 loc) · 1.58 KB
/
article_list.py
File metadata and controls
58 lines (40 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from typing import List, Optional
import attrs
from web_poet import Returns
from zyte_common_items.components import Breadcrumb
from zyte_common_items.fields import auto_field
from zyte_common_items.items import ArticleFromList, ArticleList, ArticleListMetadata
from zyte_common_items.processors import breadcrumbs_processor, string_processor
from .base import BasePage, Page
from .mixins import HasMetadata
class _ArticleListProcessors(BasePage.Processors):
breadcrumbs = [breadcrumbs_processor]
canonicalUrl = [string_processor]
class BaseArticleListPage(
BasePage, Returns[ArticleList], HasMetadata[ArticleListMetadata]
):
""":class:`BasePage` subclass for :class:`ArticleList`."""
class Processors(_ArticleListProcessors):
pass
class ArticleListPage(Page, Returns[ArticleList], HasMetadata[ArticleListMetadata]):
""":class:`Page` subclass for :class:`ArticleList`."""
class Processors(_ArticleListProcessors):
pass
@attrs.define
class AutoArticleListPage(BaseArticleListPage):
article_list: ArticleList
@auto_field
def articles(self) -> Optional[List[ArticleFromList]]:
return self.article_list.articles
@auto_field
def breadcrumbs(self) -> Optional[List[Breadcrumb]]:
return self.article_list.breadcrumbs
@auto_field
def canonicalUrl(self) -> Optional[str]:
return self.article_list.canonicalUrl
@auto_field
def metadata(self) -> Optional[ArticleListMetadata]:
return self.article_list.metadata
@auto_field
def url(self) -> Optional[str]:
return self.article_list.url