| 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( |
|---|
| 34 | "gsm_access", |
|---|
| 35 | accessor="gsm_access", |
|---|
| 36 | vocabulary=DisplayList(zip(["", ] + access_lst, |
|---|
| 37 | ["Open access", ] + access_lst)), |
|---|
| 38 | default="", |
|---|
| 39 | schemata="GoogleSitemap", |
|---|
| 40 | widget=SelectionWidget( |
|---|
| 41 | label="Access", |
|---|
| 42 | description="Specifies whether an article is available to " |
|---|
| 43 | "all readers (in case of the emtpy field, or only to " |
|---|
| 44 | "those with a free or paid membership to your site.", |
|---|
| 45 | format="radio"), |
|---|
| 46 | ), |
|---|
| 47 | ExtendableLinesField( |
|---|
| 48 | "gsm_genres", |
|---|
| 49 | accessor="gsm_genres", |
|---|
| 50 | vocabulary=DisplayList(zip(genres_lst, genres_lst)), |
|---|
| 51 | schemata="GoogleSitemap", |
|---|
| 52 | default=(), |
|---|
| 53 | widget=MultiSelectionWidget( |
|---|
| 54 | label="Genres", |
|---|
| 55 | description="Select one or more properties for an article, " |
|---|
| 56 | "namely, whether it is a press release, " |
|---|
| 57 | "a blog post, an opinion, an op-ed piece, " |
|---|
| 58 | "user-generated content, or satire.", |
|---|
| 59 | format="checkbox"), |
|---|
| 60 | ), |
|---|
| 61 | ExtendableStringField( |
|---|
| 62 | "gsm_stock", |
|---|
| 63 | accessor="gsm_stock", |
|---|
| 64 | default="", |
|---|
| 65 | schemata="GoogleSitemap", |
|---|
| 66 | widget=StringWidget( |
|---|
| 67 | label="Stock Tickers", |
|---|
| 68 | description="A comma-separated list of up to 5 stock tickers " |
|---|
| 69 | "of the companies, mutual funds, or other financial " |
|---|
| 70 | "entities that are the main subject of the article. " |
|---|
| 71 | "Relevant primarily for business articles. Each ticker " |
|---|
| 72 | "must be prefixed by the name of its stock exchange, " |
|---|
| 73 | "and must match its entry in Google Finance. " |
|---|
| 74 | "For example, \"NASDAQ:AMAT\" (but not \"NASD:AMAT\"), " |
|---|
| 75 | "or \"BOM:500325\" (but not \"BOM:RIL\").", |
|---|
| 76 | size=70), |
|---|
| 77 | ), |
|---|
| 78 | ] |
|---|
| 79 | |
|---|
| 80 | def __init__(self, context): |
|---|
| 81 | self.context = context |
|---|
| 82 | |
|---|
| 83 | def getFields(self): |
|---|
| 84 | return self.fields |
|---|