|
Revision 606
(checked in by mylan, 2 years ago)
|
Replace 'adsense_template' Page template for Python script.
|
- Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 |
from Products.CMFCore.utils import getToolByName |
|---|
| 2 |
from config import ADSENSE_MAP |
|---|
| 3 |
|
|---|
| 4 |
def getCustomerId(context): |
|---|
| 5 |
pp = getToolByName(context, 'portal_properties') |
|---|
| 6 |
try: |
|---|
| 7 |
return pp.adsense_properties.getProperty('customer_id') or None |
|---|
| 8 |
except: |
|---|
| 9 |
return None |
|---|
| 10 |
|
|---|
| 11 |
def getCompiledAdsense(context, format, marker=""): |
|---|
| 12 |
if not ADSENSE_MAP.has_key(format): |
|---|
| 13 |
return marker |
|---|
| 14 |
width = ADSENSE_MAP[format]['width'] |
|---|
| 15 |
height = ADSENSE_MAP[format]['height'] |
|---|
| 16 |
customer_id = getCustomerId(context) |
|---|
| 17 |
if not customer_id: |
|---|
| 18 |
return marker |
|---|
| 19 |
try: |
|---|
| 20 |
return context.adsense_template(customer_id = customer_id \ |
|---|
| 21 |
,adsense_width=width \ |
|---|
| 22 |
,adsense_height=height \ |
|---|
| 23 |
,adsense_format=format \ |
|---|
| 24 |
) |
|---|
| 25 |
except: |
|---|
| 26 |
return marker |
|---|
| 27 |
|
|---|
| 28 |
def getAdsenseMap(): |
|---|
| 29 |
return ADSENSE_MAP |
|---|