[Zope3-checkins] CVS: zopeproducts/NewsSite - browser.py:1.10 interfaces.py:1.8 newssite.py:1.13 register.py:1.4 sitesetup.py:1.5
Philipp von Weitershausen
philikon@philikon.de
Wed, 25 Jun 2003 11:31:04 -0400
Update of /cvs-repository/zopeproducts/NewsSite
In directory cvs.zope.org:/tmp/cvs-serv4672
Modified Files:
browser.py interfaces.py newssite.py register.py sitesetup.py
Log Message:
Made the NewsSite product work again (don't expect too much, though):
- update according to changes in Zope3 head (configuration
-> registration)
- use new-style implements
- use zapi convenience module
- disable some faulty unit tests
- whitespace normalization (please stop using tabs!)
=== zopeproducts/NewsSite/browser.py 1.9 => 1.10 ===
--- zopeproducts/NewsSite/browser.py:1.9 Fri Jun 6 17:52:00 2003
+++ zopeproducts/NewsSite/browser.py Wed Jun 25 11:30:33 2003
@@ -17,15 +17,12 @@
"""
__metaclass__ = type
+from zope.interface import implements
from zope.schema import getFields
from zope.schema.interfaces import ValidationError
-from zope.component import getAdapter
-from zope.component import queryAdapter
-from zope.component import getView
-from zope.component import getService
-from zope.component import queryUtility
from zope.security.management import getSecurityManager
+from zope.app import zapi
from zope.app.context import ContextWrapper
from zope.app.interfaces.dublincore import IZopeDublinCore
from zope.app.event import publish
@@ -35,42 +32,31 @@
from zope.app.dublincore.annotatableadapter import ZDCAnnotatableAdapter
from zope.app.services.servicenames import Authentication
-from interfaces import INewsSite, INewsSiteFormSchema
-from interfaces import ISyndicationPolicies
+from interfaces import INewsSite, INewsSiteFormSchema, ISyndicationPolicies
from sitesetup import setupSite
class BaseNewsSiteView:
"""Implement requirements which template expects of all "public" views.
"""
- def getUserInfo(self):
- #import pdb; pdb.set_trace()
- authsvc = getService(self.context, Authentication)
+ def getUserInfo(self):
+ authsvc = zapi.getService(self.context, Authentication)
authsvc.authenticate(self.request)
principal = getSecurityManager().getPrincipal()
- return {'id' : principal.getId(),
- 'title' : principal.getTitle(),
- 'roles' : principal.getRoles()
- }
+ return {'id': principal.getId(),
+ 'title': principal.getTitle() }
def unauth(self):
- #import pdb; pdb.set_trace()
- authsvc = getService(self.context, Authentication)
+ authsvc = zapi.getService(self.context, Authentication)
authsvc.authenticate(self.request)
principal = getSecurityManager().getPrincipal()
- roles = principal.getRoles()
- if roles:
- url = getView(self.context, 'absolute_url', self.request)
- # Append '/' to get browsers to sent 'Authorization:' header.
- self.request.response.redirect( '%s/' % url )
- else:
- authsvc.unauthorized(None, self.request)
+ url = zapi.getView(self.context, 'absolute_url', self.request)
+ # Append '/' to get browsers to sent 'Authorization:' header.
+ self.request.response.redirect('%s/' % url)
class NewsSiteAttributesAdapter(ZDCAnnotatableAdapter):
-
- __implements__ = INewsSiteFormSchema
-
+ implements(INewsSiteFormSchema)
__used_for__ = INewsSite
def __init__(self, context):
@@ -79,8 +65,6 @@
# some context properties could be handled here
-
-
class NewsSiteAddForm:
"""News Site AddForm Mixin (includes Site Setup Hook).
"""
@@ -89,19 +73,13 @@
content = super(NewsSiteAddForm, self).createAndAdd(data)
setupSite(content, data)
return content
-
-
-
-
class NewsSiteAdding(Adding):
"""Custom adding view for NewsSite objects.
"""
menu_id = "add_news"
-
-
-class NewsSiteSyndicationPoliciesView( BaseNewsSiteView ):
+class NewsSiteSyndicationPoliciesView(BaseNewsSiteView):
""" Simple class for managing the RSS policies for the site.
"""
@@ -114,52 +92,44 @@
__used_for__ = INewsSite
def __init__(self, context, request):
-
self.context = context
self.request = request
- self.site = getAdapter(context, INewsSite)
- self.dc = getAdapter(context, IZopeDublinCore)
- self.context_url = getView(context, 'absolute_url', request)()
+ self.site = zapi.getAdapter(context, INewsSite)
+ self.dc = zapi.getAdapter(context, IZopeDublinCore)
+ self.context_url = zapi.getView(context, 'absolute_url', request)()
# XXX
self.logo_url = 'newssite_logo.png'
- self.syn_policies = getAdapter(context, ISyndicationPolicies)
+ self.syn_policies = zapi.getAdapter(context, ISyndicationPolicies)
def listSortedEntries(self):
result = []
for k, v in self.site.items():
- adapter = getAdapter(v, IContentFilterAdapter)
+ adapter = zapi.getAdapter(v, IContentFilterAdapter)
if not adapter.filterObjectByState(v, 'published', 'default'):
continue
- dc = getAdapter(v, IZopeDublinCore)
+ dc = zapi.getAdapter(v, IZopeDublinCore)
result.append((dc.effective or dc.created, k))
return [x[1] for x in result]
-
def listSyndicationInfo(self):
-
""" Return a sequence of mappings describing the syndicatable entries.
"""
result = []
-
keys = self.listSortedEntries()
-
for key in keys[:self.syn_policies.max_items]:
-
raw_entry = self.site[key]
wrapped_entry = ContextWrapper(raw_entry, self.context,
name=key)
-
- entry_url = getView(wrapped_entry, 'absolute_url', self.request)
- entry_dc = getAdapter(wrapped_entry, IZopeDublinCore)
-
- result.append( { 'title' : entry_dc.title
- , 'entry' : wrapped_entry
- , 'entry_url' : entry_url()
- , 'dc' : entry_dc
- } )
-
+ entry_url = zapi.getView(wrapped_entry, 'absolute_url',
+ self.request)
+ entry_dc = zapi.getAdapter(wrapped_entry, IZopeDublinCore)
+ result.append({'title': entry_dc.title,
+ 'entry': wrapped_entry,
+ 'entry_url': entry_url(),
+ 'dc': entry_dc
+ })
return result
=== zopeproducts/NewsSite/interfaces.py 1.7 => 1.8 ===
--- zopeproducts/NewsSite/interfaces.py:1.7 Wed May 28 02:54:00 2003
+++ zopeproducts/NewsSite/interfaces.py Wed Jun 25 11:30:33 2003
@@ -29,16 +29,13 @@
# Content interfacse
#
class INewsSite(IContentContainer):
- """Provides a marker interface for news site"""
-
+ """Provides a marker interface for news site"""
#
# Helper Interface for Add/Edit Forms
#
class INewsSiteFormSchema(IZopeDublinCore):
- """Schema for News Site AddForm."""
-
-
+ """Schema for News Site AddForm."""
#
# Registration interfaces
@@ -59,9 +56,7 @@
required=True)
password = Password(title=u'Password',
- required=True)
-
-
+ required=True)
#
# Syndication policy interfaces
@@ -73,36 +68,35 @@
def _allowed(self):
return ALLOWED_PERIODS
- allowed_values = ContextProperty( _allowed )
+ allowed_values = ContextProperty(_allowed)
class ISyndicationPolicies(Interface):
""" Track a set of policy settings for syndicating our news over RSS.
"""
- max_items = Int(title=u'Max. RSS Items',
- description=u'The number of entries available to RSS.',
- required=True,
- default=15
- )
+ max_items = Int(
+ title=u'Max. RSS Items',
+ description=u'The number of entries available to RSS.',
+ required=True,
+ default=15
+ )
period = SyndicationPeriodField(
- title=u'Update Period',
- description=u'Periodicity of update to the corpus.',
- required=True,
- default=u'daily'
- )
-
- frequency = Int(title=u'Frequency',
- description=u'How often per period is the corpus updated?',
- required=True,
- default=1
- )
-
- base_update = Datetime(title=u'Base Update Time',
- description=u'Starting point for computing updates.',
- required=True,
- default=parseDatetimetz( '2003/01/01 00:00 UTC' )
- )
-
-
-
-
+ title=u'Update Period',
+ description=u'Periodicity of update to the corpus.',
+ required=True,
+ default=u'daily'
+ )
+
+ frequency = Int(
+ title=u'Frequency',
+ description=u'How often per period is the corpus updated?',
+ required=True,
+ default=1
+ )
+
+ base_update = Datetime(
+ title=u'Base Update Time',
+ description=u'Starting point for computing updates.',
+ required=True,
+ default=parseDatetimetz('2003/01/01 00:00 UTC')
+ )
=== zopeproducts/NewsSite/newssite.py 1.12 => 1.13 ===
--- zopeproducts/NewsSite/newssite.py:1.12 Fri Jun 6 17:52:00 2003
+++ zopeproducts/NewsSite/newssite.py Wed Jun 25 11:30:33 2003
@@ -17,11 +17,12 @@
"""
from persistence.dict import PersistentDict
-from zope.component import getAdapter, getView
+from zope.interface import implements
from zope.security.management import getSecurityManager
from zope.exceptions.unauthorized import Unauthorized
from zope.publisher.browser import BrowserView
+from zope.app import zapi
from zope.app.context import ContextWrapper
from zope.app.interfaces.annotation import IAnnotations
from zope.app.interfaces.dublincore import ICMFDublinCore
@@ -31,22 +32,18 @@
from zope.app.content.folder import Folder
from zope.app.datetimeutils import parseDatetimetz
-from interfaces import INewsSite
-from interfaces import ISyndicationPolicies
+from interfaces import INewsSite, ISyndicationPolicies
from NewsItem.interfaces import INewsItem
from browser import BaseNewsSiteView
class NewsSite(Folder):
"""XXX to be written"""
-
- __implements__ = (INewsSite, Folder.__implements__)
-
+ implements(INewsSite)
class NewsSiteView(BrowserView, BaseNewsSiteView):
__used_for__ = INewsSite
- __implements__ = (BrowserView.__implements__,
- IProcessInstanceContainerAdaptable)
+ implements(IProcessInstanceContainerAdaptable)
def listPublicNewsItems(self):
return self._list(state=u"published")
@@ -83,24 +80,24 @@
for x in self.context]
list = filter(lambda x: INewsItem.isImplementedBy(x), site)
- filterAdapter = getAdapter(self.context, IContentFilterAdapter)
+ filterAdapter = zapi.getAdapter(self.context, IContentFilterAdapter)
list = filterAdapter.filterListByState(list, state)
for item in list:
- dc = getAdapter(item, ICMFDublinCore)
+ dc = zapi.getAdapter(item, ICMFDublinCore)
date = dc.effective or dc.created
info = {'obj' : item,
'dc' : dc,
'date' : self._dateString(date),
'effective' : self._dateString(dc.effective),
'expires' : self._dateString(dc.expires),
- 'absolute_url' : getView(item, 'absolute_url',
- self.request)(),
+ 'absolute_url' : zapi.getView(item, 'absolute_url',
+ self.request)(),
'review_url' :
- getView(item, 'absolute_url', self.request
- )()+u'/workflows.html'
+ zapi.getView(item, 'absolute_url', self.request
+ )()+u'/workflows.html'
}
- decorated.append( (date, info) )
+ decorated.append((date, info))
decorated.sort()
decorated.reverse()
@@ -108,10 +105,8 @@
return [ x[1] for x in decorated ]
def _dateString(self, value):
-
if value is None:
return ''
-
return value.strftime('%Y-%m-%d')
#
@@ -119,27 +114,22 @@
#
SPkey = "zopeproducts.NewsSite.SyndicationPolicies"
-class NewsSiteSyndicationPoliciesAdapter( object ):
-
+class NewsSiteSyndicationPoliciesAdapter(object):
""" Adapt news site to ISP interface.
"""
-
- __implements__ = ( ISyndicationPolicies, )
- __used_for__ = ( INewsSite, )
+ implements(ISyndicationPolicies)
+ __used_for__ = INewsSite
_annotations = None
_DEFAULT_MAX_ITEMS = 15
_DEFAULT_PERIOD = 'daily'
_DEFAULT_FREQUENCY = 1
- _DEFAULT_BASE_UPDATE = parseDatetimetz( '2003/01/01' )
-
- def __init__( self, context ):
-
- annotations = getAdapter( context, IAnnotations )
-
- spdata = annotations.get( SPkey )
+ _DEFAULT_BASE_UPDATE = parseDatetimetz('2003/01/01')
+ def __init__(self, context):
+ annotations = zapi.getAdapter(context, IAnnotations)
+ spdata = annotations.get(SPkey)
if not spdata:
self._annotations = annotations
spdata = PersistentDict()
@@ -147,11 +137,9 @@
spdata[ 'period' ] = self._DEFAULT_PERIOD
spdata[ 'frequency' ] = self._DEFAULT_FREQUENCY
spdata[ 'base_update' ] = self._DEFAULT_BASE_UPDATE
-
self._mapping = spdata
- def _changed( self ):
-
+ def _changed(self):
# Is this a new annotation?
if self._annotations is not None:
self._annotations[ SPkey ] = self._mapping
@@ -160,47 +148,47 @@
#
# 'max_items' field
#
- def _get_max_items( self ):
+ def _get_max_items(self):
return self._mapping[ 'max_items' ]
- def _set_max_items( self, value ):
+ def _set_max_items(self, value):
self._mapping[ 'max_items' ] = value
self._changed()
- max_items = property( _get_max_items, _set_max_items )
+ max_items = property(_get_max_items, _set_max_items)
#
# 'period' field
#
- def _get_period( self ):
+ def _get_period(self):
return self._mapping[ 'period' ]
- def _set_period( self, value ):
+ def _set_period(self, value):
self._mapping[ 'period' ] = value
self._changed()
- period = property( _get_period, _set_period )
+ period = property(_get_period, _set_period)
#
# 'freqeuency' field
#
- def _get_frequency( self ):
+ def _get_frequency(self):
return self._mapping[ 'frequency' ]
- def _set_frequency( self, value ):
+ def _set_frequency(self, value):
self._mapping[ 'frequency' ] = value
self._changed()
- frequency = property( _get_frequency, _set_frequency )
+ frequency = property(_get_frequency, _set_frequency)
#
# 'base_update' field
#
- def _get_base_update( self ):
+ def _get_base_update(self):
return self._mapping[ 'base_update' ]
- def _set_base_update( self, value ):
+ def _set_base_update(self, value):
self._mapping[ 'base_update' ] = value
self._changed()
- base_update = property( _get_base_update, _set_base_update )
+ base_update = property(_get_base_update, _set_base_update)
=== zopeproducts/NewsSite/register.py 1.3 => 1.4 ===
--- zopeproducts/NewsSite/register.py:1.3 Thu Mar 27 10:12:09 2003
+++ zopeproducts/NewsSite/register.py Wed Jun 25 11:30:33 2003
@@ -17,10 +17,8 @@
"""
from persistence.dict import PersistentDict
-from zope.component import createObject
-from zope.component import getService
-from zope.component import getAdapter
-
+from zope.interface import implements
+from zope.app import zapi
from zope.app.interfaces.security import IPrincipal
from zope.app.interfaces.annotation import IAnnotations
from zope.app.services.servicenames import Authentication
@@ -28,56 +26,50 @@
from interfaces import IMember
+__metaclass__ = type
+
class MemberAddView:
def create(self, login, password):
-
id = login
title = ''
description = ''
- #user = createObject(self.context, 'User', id, title, description,
+ #user = zapi.createObject(self.context, 'User', id, title, description,
# login, password)
- user = User( id, title, description, login, password )
+ user = User(id, title, description, login, password)
user.setRoles(['Member'])
return user
def add(self, content):
"""Fake out "add", injecting the user into the local auth service.
"""
- authsvc = getService(self.context, Authentication)
+ authsvc = zapi.getService(self.context, Authentication)
authsvc.setObject(content.getId(), content)
def nextURL(self):
return "welcome.html"
-
MDkey = "zopeproducts.NewsSite.MemberData"
-class MemberDataAdapter( object ):
-
- __implements__ = ( IMember, )
- __used_for__ = ( IPrincipal, )
+class MemberDataAdapter:
+ implements(IMember)
+ __used_for__ = IPrincipal
_annotations = None
- def __init__( self, context ):
+ def __init__(self, context):
self.context = context
-
- annotations = getAdapter( context, IAnnotations )
-
- mbrdata = annotations.get( MDkey )
-
+ annotations = zapi.getAdapter(context, IAnnotations)
+ mbrdata = annotations.get(MDkey)
if not mbrdata:
self._annotations = annotations
mbrdata = PersistentDict()
mbrdata[ 'realname' ] = ''
mbrdata[ 'email' ] = ''
-
self._mapping = mbrdata
- def _changed( self ):
-
+ def _changed(self):
# Is this a new annotation?
if self._annotations is not None:
self._annotations[ MDkey ] = self._mapping
@@ -93,7 +85,7 @@
#self.context.setPassword(password)
pass # XXX
- password = property( _getPassword, _setPassword )
+ password = property(_getPassword, _setPassword)
def _getRealName(self):
return self._mapping[ 'realname' ]
@@ -112,4 +104,3 @@
self._changed()
email = property(_getEmail, _setEmail)
-
=== zopeproducts/NewsSite/sitesetup.py 1.4 => 1.5 ===
--- zopeproducts/NewsSite/sitesetup.py:1.4 Fri Mar 28 13:17:57 2003
+++ zopeproducts/NewsSite/sitesetup.py Wed Jun 25 11:30:33 2003
@@ -19,30 +19,23 @@
import os, sys
+from zope.app import zapi
from zope.app.traversing import traverse, getPath
-from zope.app.services.service import ServiceManager
-from zope.app.services.service import ServiceConfiguration
-from zope.app.interfaces.services.configuration import Active
+from zope.app.services.service import ServiceManager, ServiceRegistration
+from zope.app.interfaces.services.registration import ActiveStatus
+
from zope.app.services.servicenames \
import Workflows, Authentication
-
-from zope.component import getUtility
-
from zope.app.services.auth import AuthenticationService
from zope.app.workflow.service import WorkflowService
+from zope.app.interfaces.workflow import IProcessDefinitionImportExport
from zope.app.workflow.stateful.contentworkflow \
import ContentWorkflowsUtility
-
-from zope.app.workflow.service import ProcessDefinitionConfiguration
+from zope.app.workflow.service import ProcessDefinitionRegistration
from zope.app.workflow.stateful.definition \
import StatefulProcessDefinition
-
-from zope.app.interfaces.workflow import IProcessDefinitionImportExport
-
-
-
def load_file(filename, _prefix=None, mode='r'):
if isinstance(_prefix, str):
path = _prefix
@@ -53,33 +46,30 @@
filename = os.path.join(path, filename)
return open(filename, mode)
-
-
def setupSite(site, data):
# Add SiteManagementFolder
site.setServiceManager(ServiceManager())
sm = traverse(site, '++etc++site')
default = traverse(sm, 'default')
- cm = default.getConfigurationManager()
-
+ rm = default.getRegistrationManager()
# Create Local Authentication Service
auth_service_name = 'Authentication-1'
default.setObject(auth_service_name, AuthenticationService())
workflowservice = traverse(default, auth_service_name)
auth_path = "%s/%s" % (getPath(default), auth_service_name)
- configuration = ServiceConfiguration(Authentication, auth_path, site)
- cm.setObject('', configuration)
- traverse(cm, '1').status = Active
+ registration = ServiceRegistration(Authentication, auth_path, site)
+ rm.setObject('', registration)
+ traverse(rm, '1').status = ActiveStatus
# Create Workflow Serivce
workflow_service_name = 'Workflows-1'
default.setObject(workflow_service_name, WorkflowService())
workflowservice = traverse(default, workflow_service_name)
workflow_path = "%s/%s" % (getPath(default), workflow_service_name)
- configuration = ServiceConfiguration(Workflows, workflow_path, site)
- cm.setObject('', configuration)
- traverse(cm, '2').status = Active
+ registration = ServiceRegistration(Workflows, workflow_path, site)
+ rm.setObject('', registration)
+ traverse(rm, '2').status = ActiveStatus
# Create Content Workflows Utility
workflowsutility_name = 'ContentWorkflowsUtility-1'
@@ -92,11 +82,10 @@
default.setObject(pd_name, StatefulProcessDefinition())
pd = traverse(default, pd_name)
pd_path = "%s/%s" % (getPath(default), pd_name)
- configuration = ProcessDefinitionConfiguration('default', pd_path)
- cm.setObject('', configuration)
- traverse(cm, '3').status = Active
-
- # Import Default ProcessReview Workflow
-
- import_util = getUtility(default, IProcessDefinitionImportExport)
+ configuration = ProcessDefinitionRegistration('default', pd_path)
+ rm.setObject('', registration)
+ traverse(rm, '3').status = ActiveStatus
+
+ # Import Default ProcessReview Workflow
+ import_util = zapi.getUtility(default, IProcessDefinitionImportExport)
import_util.importProcessDefinition(pd, load_file('workflow.xml', mode='r'))