1 | from zope.component import adapts |
---|
2 | from zope.interface import implements |
---|
3 | from archetypes.schemaextender.field import ExtensionField |
---|
4 | from archetypes.schemaextender.interfaces import ISchemaExtender |
---|
5 | |
---|
6 | from Products.Archetypes.public import SelectionWidget |
---|
7 | from Products.Archetypes.public import StringWidget |
---|
8 | from Products.Archetypes.public import MultiSelectionWidget |
---|
9 | from Products.Archetypes.public import LinesField |
---|
10 | from Products.Archetypes.public import StringField |
---|
11 | from Products.Archetypes.public import DisplayList |
---|
12 | |
---|
13 | from quintagroup.plonegooglesitemaps.interfaces import INewsSitemapProvider |
---|
14 | |
---|
15 | |
---|
16 | class ExtendableStringField(ExtensionField, StringField): |
---|
17 | """An extendable string field.""" |
---|
18 | |
---|
19 | |
---|
20 | class ExtendableLinesField(ExtensionField, LinesField): |
---|
21 | """An extendable string field.""" |
---|
22 | |
---|
23 | access_lst = ["Subscription", "Registration"] |
---|
24 | genres_lst = ["PressRelease", "Satire", "Blog", "OpEd", "Opinion", \ |
---|
25 | "UserGenerated"] |
---|
26 | |
---|
27 | |
---|
28 | class NewsExtender(object): |
---|
29 | adapts(INewsSitemapProvider) |
---|
30 | implements(ISchemaExtender) |
---|
31 | |
---|
32 | fields = [ |
---|
33 | ExtendableStringField("gsm_access", |
---|
34 | accessor="gsm_access", |
---|
35 | vocabulary=DisplayList(zip(["", ] + access_lst, \ |
---|
36 | ["Open access", ] + access_lst)), |
---|
37 | default="", |
---|
38 | schemata="GoogleSitemap", |
---|
39 | widget=SelectionWidget( |
---|
40 | label="Access", |
---|
41 | description="Specifies whether an article is available to " \ |
---|
42 | "all readers (in case of the emtpy field, or only to " \ |
---|
43 | "those with a free or paid membership to your site.", |
---|
44 | format="radio"), |
---|
45 | ), |
---|
46 | ExtendableLinesField("gsm_genres", |
---|
47 | accessor="gsm_genres", |
---|
48 | vocabulary=DisplayList(zip(genres_lst, genres_lst)), |
---|
49 | schemata="GoogleSitemap", |
---|
50 | default=(), |
---|
51 | widget=MultiSelectionWidget( |
---|
52 | label="Genres", |
---|
53 | description="Select one or more properties for an article, " \ |
---|
54 | "namely, whether it is a press release, a blog post, an " \ |
---|
55 | "opinion, an op-ed piece, user-generated content, " \ |
---|
56 | "or satire.", |
---|
57 | format="checkbox"), |
---|
58 | ), |
---|
59 | ExtendableStringField("gsm_stock", |
---|
60 | accessor="gsm_stock", |
---|
61 | default="", |
---|
62 | schemata="GoogleSitemap", |
---|
63 | widget=StringWidget( |
---|
64 | label="Stock Tickers", |
---|
65 | description="A comma-separated list of up to 5 stock tickers "\ |
---|
66 | "of the companies, mutual funds, or other financial " \ |
---|
67 | "entities that are the main subject of the article. " \ |
---|
68 | "Relevant primarily for business articles. Each ticker " \ |
---|
69 | "must be prefixed by the name of its stock exchange, " \ |
---|
70 | "and must match its entry in Google Finance. " \ |
---|
71 | "For example, \"NASDAQ:AMAT\" (but not \"NASD:AMAT\"), " \ |
---|
72 | "or \"BOM:500325\" (but not \"BOM:RIL\").", |
---|
73 | size=70), |
---|
74 | ), |
---|
75 | ] |
---|
76 | |
---|
77 | def __init__(self, context): |
---|
78 | self.context = context |
---|
79 | |
---|
80 | def getFields(self): |
---|
81 | return self.fields |
---|