[Zope3-checkins] CVS: zopeproducts/demo/jobboard - browser.py:1.1
interfaces.py:1.1 job.py:1.1 tests.py:1.1
ApproveJobsView.py:NONE IJob.py:NONE IJobList.py:NONE
Job.py:NONE JobCreateView.py:NONE JobList.py:NONE
JobListView.pt:NONE JobView.pt:NONE Tutorial.html:NONE
__init__.py:NONE browser_views.sxd:NONE configure.zcml:NONE
edit.pt:NONE job_board_stories.txt:NONE preview.pt:NONE
review.pt:NONE thanks.pt:NONE
sree
sree at mahiti.org
Tue Dec 16 04:40:52 EST 2003
Update of /cvs-repository/zopeproducts/demo/jobboard
In directory cvs.zope.org:/tmp/cvs-serv5774
Added Files:
browser.py interfaces.py job.py tests.py
Removed Files:
ApproveJobsView.py IJob.py IJobList.py Job.py JobCreateView.py
JobList.py JobListView.pt JobView.pt Tutorial.html __init__.py
browser_views.sxd configure.zcml edit.pt job_board_stories.txt
preview.pt review.pt thanks.pt
Log Message:
At the zope sprint in bangalore by aruna, sree -
=== Added File zopeproducts/demo/jobboard/browser.py ===
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.publisher.browser import BrowserView
from job import Job
class JobCreateView(BrowserView):
""" class to create job entries
>>> from job import JobList
>>> from zope.publisher.browser import TestRequest
>>> from zope.app.tests.placelesssetup import setUp, tearDown
>>> setUp()
>>> class TestJobList:
... context = None
... def add(self, myObj):
... self.tempStorage = myObj
>>>
>>> request = TestRequest()
>>> joblist = TestJobList()
>>> view = JobCreateView(joblist, request)
>>> myThanksPage = view.create(submitter='sree', summary='my job summary',
... description='my desc', contact = 'sree')
>>> joblist.tempStorage.summary
'my job summary'
>>> tearDown()
"""
edit = ViewPageTemplateFile('edit.pt')
preview = ViewPageTemplateFile('preview.pt')
thanks = ViewPageTemplateFile('thanks.pt')
def create(self, submitter='', summary='', description='', contact=''):
# Validation code should go here
job = Job(submitter, summary, description, contact)
self.context.add(job)
return self.thanks()
################################
class ApproveJobsView(BrowserView):
""" class to Approve existing job entries
>>> from job import JobList
>>> from zope.publisher.browser import TestRequest
>>> from zope.app.tests.placelesssetup import setUp, tearDown
>>> setUp()
>>>
>>> request = TestRequest(form={'1':'approve','2':'discard'})
>>> class TestJobList:
... context = None
... tempStorage = []
... def add(self, myObj):
... self.tempStorage.append( myObj)
>>> joblist = JobList()
>>> view = JobCreateView(joblist, request)
>>> myThanksPage = view.create(submitter='sree', summary='my job summary',
... description='my desc', contact = 'sree')
>>> myThanksPage = view.create(submitter='sree2', summary='my summaryy2',
... description='my desc2', contact = 'sree2')
>>> approvedview = ApproveJobsView(joblist, request)
>>> approvedview.approve()
>>> request.response.getHeader('location')
'.'
>>> joblist['1'].state
'approved'
>>> joblist['2'].state
Traceback (most recent call last):
...
KeyError: 2
>>> tearDown()
"""
review = ViewPageTemplateFile('review.pt')
def approve(self):
form = self.request.form
for jobid in form:
try:
job = self.context[jobid]
except:
pass
action = form[jobid]
if action == 'approve':
job.approve()
elif action == 'discard':
del self.context[jobid]
response = self.request.response
if self.context.getPendingIds():
response.redirect('review.html')
else:
response.redirect('.')
=== Added File zopeproducts/demo/jobboard/interfaces.py ===
from zope.interface import Interface
from zope.interface import Attribute
class IJob(Interface):
"""Interface for the basic Job"""
submitter = Attribute("submitter",
"Email address of the submitter")
summary = Attribute("summary",
"One-line summary of the job")
description = Attribute("description",
"Longer description of the job")
contact = Attribute("contact",
"Email address to contact about the job")
state = Attribute("state",
"Current state of the job listing.\n"
"The possible values are defined in JobState.")
salary = Attribute("salary",
"Salary range offered for the job.")
startdate = Attribute("start date",
"Job start date")
def approve():
"Moves the job state to Approved"
class JobState:
"""Possible values of IJob.state."""
PendingApproval = "pending approval"
Approved = "approved"
##############################################################
#
#
#
#
##############################################################
class IJobList(Interface):
def __getitem__(jobid):
"""Returns the job with the given jobid"""
def query(state):
"""Returns a list of Job ids"""
def getApprovedIds():
"""Returns a sequence of ids for job that are in the approved state
"""
def getPendingIds():
"""Returns a sequence of ids for jobs that are in the pending state
"""
def add(job):
"""Add a Job object to the list.
Returns the id assigned to the job.
"""
def __delitem__(jobid):
"""Removes the Job object with the given id from the list.
Raises KeyError if the jobid is not in the list.
"""
=== Added File zopeproducts/demo/jobboard/job.py ===
"""
Job.py
"""
from persistence import Persistent
from interfaces import IJob, JobState, IJobList
from zope.interface import implements
class Job(Persistent):
""" Job Class
>>> myJob = Job(submitter='my name', summary='my summary',
... description='my description',contact='my contact',
... salary='111', startdate='10/01/2003')
>>> myJob.summary
'my summary'
>>> myJob.state
'pending approval'
>>> myJob.approve()
>>> myJob.state
'approved'
"""
implements(IJob)
def __init__(self, submitter, summary, description,
contact, salary=None, startdate=None):
self.submitter = submitter
self.summary = summary
self.description = description
self.contact = contact
self.state = JobState.PendingApproval
self.salary = salary
self.startdate = startdate
def approve(self):
"""Moves the job state to approved"""
self.state = JobState.Approved
##########################################################################
from persistence.dict import PersistentDict
class JobList(Persistent):
""" the Joblist class manages the creation, deletion of job list and
can display the object ids which are in specific states
>>> from job import Job
>>> joblist = JobList()
>>> myJob1 = Job(submitter='my name', summary='my summary',
... description='my description',contact='my contact',
... salary='111', startdate='10/01/2003')
>>> myJob2 = Job(submitter='my name2', summary='my summary2',
... description='my description2',contact='my contact2',
... salary='222', startdate='20/12/2003')
>>> joblist.add(myJob1)
'1'
>>> joblist.add(myJob2)
'2'
>>> joblist.getPendingIds()
['1', '2']
>>> joblist.query('pending approval')
['1', '2']
>>> myJob1.approve()
>>> joblist.getPendingIds()
['2']
>>> joblist.getApprovedIds()
['1']
"""
implements(IJobList)
def __init__(self):
self._lastid = 0
self._jobs = PersistentDict()
def add(self, job):
self._lastid += 1
jobid = self._lastid
self._jobs[jobid] = job
# stringified for parity with query
# this can return an int when query can also return an int
return str(jobid)
def __delitem__(self, jobid):
# accept stringified job ids, see add()
try:
jobid = int(jobid)
except ValueError:
raise KeyError, jobid
del self._jobs[jobid]
def query(self, state):
ids = [jobid
for jobid, job in self._jobs.items()
if job.state == state]
ids.sort()
# this should work returning a list of ints,
# but it exposes a bug in PageTemplates
return map(str, ids)
def __getitem__(self, jobid):
# accept stringified job ids, see add()
try:
jobid = int(jobid)
except ValueError:
raise KeyError, jobid
return self._jobs[jobid]
def getPendingIds(self):
return self.query(JobState.PendingApproval)
def allIds(self):
return self._jobs.items()
#ids.sort()
# this should work returning a list of ints,
# but it exposes a bug in PageTemplates
#return map(str, ids)
def getApprovedIds(self):
return self.query(JobState.Approved)
=== Added File zopeproducts/demo/jobboard/tests.py ===
import unittest, doctest
def test_suite():
return unittest.TestSuite((
doctest.DocTestSuite('zopeproducts.demo.jobboard.job'),
doctest.DocTestSuite('zopeproducts.demo.jobboard.browser'),
))
if __name__ == '__main__': unittest.main()
=== Removed File zopeproducts/demo/jobboard/ApproveJobsView.py ===
=== Removed File zopeproducts/demo/jobboard/IJob.py ===
=== Removed File zopeproducts/demo/jobboard/IJobList.py ===
=== Removed File zopeproducts/demo/jobboard/Job.py ===
=== Removed File zopeproducts/demo/jobboard/JobCreateView.py ===
=== Removed File zopeproducts/demo/jobboard/JobList.py ===
=== Removed File zopeproducts/demo/jobboard/JobListView.pt ===
=== Removed File zopeproducts/demo/jobboard/JobView.pt ===
=== Removed File zopeproducts/demo/jobboard/Tutorial.html ===
=== Removed File zopeproducts/demo/jobboard/__init__.py ===
=== Removed File zopeproducts/demo/jobboard/browser_views.sxd ===
=== Removed File zopeproducts/demo/jobboard/configure.zcml ===
=== Removed File zopeproducts/demo/jobboard/edit.pt ===
=== Removed File zopeproducts/demo/jobboard/job_board_stories.txt ===
=== Removed File zopeproducts/demo/jobboard/preview.pt ===
=== Removed File zopeproducts/demo/jobboard/review.pt ===
=== Removed File zopeproducts/demo/jobboard/thanks.pt ===
More information about the Zope3-Checkins
mailing list