Zope Products newbie question.

M

mir nazim

Hi,
I am a PHP developer. i am currently studying Zope and want to migrate
to it. I have developed a school management system in PHP. but now I
want to implement it in Zope. I have worked through The Zope Book 2.6
and Zope Developers Guide quickly(not thoroughly). My problem is that
I am confused where to start.

I am giving a brief account of what I want to do.

I have Identified Following class structure.


class Person(Persistent):
# inherits from Persistence.Persistent. to be stored in ZODB
# Data Members:
self.firstName
self.midName
self.lastName
self.sex
self.dob
# And other data members like address, city, phone etc.

# Methods:
getFistName(self)
getMidName(self)
getLastName(self)
getSex(self)
getDob(self)
setFistName(self)
setMidName(self)
setLastName(self)
setSex(self)
setDob(self)


class Student(Person):
# inherits from Person.
# Data Members specific to students like;
# Fee Status, class, course etc.

# Data Members:
# method for accessing and modifying attribute of student


System is supposed to admit students and assign unique ids to
them. student object will be stored in ZODB. searching on id, first,
mid and last names and possibly on other attributes like sex, date of
birth etc has to be provided. system is to be used by end users and
not zope administrators.

Now the problem is that I am confused how to implement these
classes. Should I implement them as ZClass or in External methods or
as a Zope Product. Please Clarify. Also tell me how, actually, am I
supposed to start. small code sample can be a of great help. Links to
similar free projects undertaken on zope can be useful.

PS: Actually it is a small part of overall system which provides
transport management, class/course management, exam/result management,
employees payrolls and basic accounting for high schools. but to start
with it should be enough to help me get a better feel of zope.

Thanks...

Mir Nazim.
 
P

Peter Maas

mir said:
Now the problem is that I am confused how to implement these
classes. Should I implement them as ZClass or in External methods or
as a Zope Product. Please Clarify. Also tell me how, actually, am I
supposed to start. small code sample can be a of great help. Links to
similar free projects undertaken on zope can be useful.

- Write Zope Products to enhance the Zope Server itself, e.g.
authenticate against an LDAP server.

- Write Python scripts if you want your code to be tightly integrated
into the ZOPE machinery.

- Write external methods if you want your code to be free from ZOPE's
restrictions (e.g. code that is supposed to work outside of ZOPE
as well).

- Write ZClasses if you want to control your app via ZMI (Zope Management
Interface).

To port from PHP I would start with external methods. If you want
your application objects stored in ZOPE (and not in an external db)
do that with Python scripts. If you want to manage your application
with ZMI (e.g. insert student objects into a ZOPE folder) use ZClass
objects.

Mit freundlichen Gruessen,

Peter Maas
 
J

Josef Meile

- Write Zope Products to enhance the Zope Server itself, e.g.
authenticate against an LDAP server.
I would also say that this makes mantainment easier; however, the first
product will be a little bit complicate to do. But once you get it, you
will be able to develop more.
- Write external methods if you want your code to be free from ZOPE's
restrictions (e.g. code that is supposed to work outside of ZOPE
as well).
You can also use class and module assertions to achieve this.
- Write ZClasses if you want to control your app via ZMI (Zope Management
Interface).
ZClasses is a good way to prototyping, but they are hard to maintain and
zope core developers doesn't focus much on mantaining them (There was
recently a discussion about this on the zope list). The other problem is
that once you get used to ZClasses, you don't want to leave them. That
was my case. But now I understand that Python based Products are more
robust and I'm migrating now.
To port from PHP I would start with external methods. If you want
your application objects stored in ZOPE (and not in an external db)
do that with Python scripts. If you want to manage your application
with ZMI (e.g. insert student objects into a ZOPE folder) use ZClass
objects.
You can also achieve this with a python product, however, it will be
more complicated as I said before. Anyway, python Clases is the way to
go for me.

Ah, another thing: don't use DTML, use Zope Page Templates, which
separate logic from presentation. Also consult the most current Zope
Book at: http://www.plope.org. This book now emphasizes on coding ZPT
instead of DTML

Finally, do a search on the zope list: lists.zope.org. This topic has
been covered dozen of times and that's the most indicated place for your
questions.

Regards,
Josef
 
D

Duncan Booth

(e-mail address removed) (mir nazim) wrote in
Hi,
I am a PHP developer. i am currently studying Zope and want to migrate
to it. I have developed a school management system in PHP. but now I
want to implement it in Zope. I have worked through The Zope Book 2.6
and Zope Developers Guide quickly(not thoroughly). My problem is that
I am confused where to start.

I am giving a brief account of what I want to do.

I have Identified Following class structure.


class Person(Persistent):
# inherits from Persistence.Persistent. to be stored in ZODB
# Data Members:
self.firstName
self.midName
self.lastName
self.sex
self.dob
# And other data members like address, city, phone etc.

# Methods:
getFistName(self)
getMidName(self)
getLastName(self)
getSex(self)
getDob(self)
setFistName(self)
setMidName(self)
setLastName(self)
setSex(self)
setDob(self)


class Student(Person):
# inherits from Person.
# Data Members specific to students like;
# Fee Status, class, course etc.

# Data Members:
# method for accessing and modifying attribute of student


System is supposed to admit students and assign unique ids to
them. student object will be stored in ZODB. searching on id, first,
mid and last names and possibly on other attributes like sex, date of
birth etc has to be provided. system is to be used by end users and
not zope administrators.

Now the problem is that I am confused how to implement these
classes. Should I implement them as ZClass or in External methods or
as a Zope Product. Please Clarify. Also tell me how, actually, am I
supposed to start. small code sample can be a of great help. Links to
similar free projects undertaken on zope can be useful.
These days, I would start off using Plone and Archetypes. There is even a
tool (ArchgenXML) which will allow you to start off by drawing a UML
diagram of exactly what you have above and will then automatically convert
this into the Python code to produce the appropriate Zope/Plone objects.
Attributes in UML become attributes on the Zope objects, and operations in
the UML can become views, forms, actions or simply methods in Zope.
References between objects are also carried across into Zope: every
archetypes object automatically gets assigned a unique id which is used to
maintain the references between objects.

Archetypes works on the basis that you define a schema for each object,
this describes the fields in the object and which editing widgets you want
to use in forms. The accessors and mutators are generated automatically, so
unless you need to change the default behaviour you can ignore them. The
schema lets you specify not just the type of values but whether they are
indexed for searching, the allowed vocabulary, validation rules and so on.

You can create and edit your Archetypes objects using a standard form which
is generated based on the fields in the schema. As a minimum you need to
write a Zope page template to display each object.

For an introduction to Archetypes see
http://www.zopemag.com/Issue006/Section_Articles/article_IntroToArchteypes.
html and for an example of the UML modelling see
http://plone.org/documentation/archetypes/archgenxml-manual
(go up one level to http://plone.org/documentation/archetypes for the main
archetypes documentation)
 
I

Istvan Albert

mir said:
Now the problem is that I am confused how to implement these
classes. Should I implement them as ZClass or in External methods or
as a Zope Product. Please Clarify. Also tell me how, actually, am I
supposed to start. small code sample can be a of great help. Links to
similar free projects undertaken on zope can be useful.

Here is what I do, your mileage may vary.

I develop "standard" python classes for all the functionality
that has nothing to do with the display (business logic).
I develop, test and re-use these classes without Zope.

I deploy these classes in the module path of the python that
runs zope and I make them available in Zope (needs a few lines).

These classes can be now stored in sessions, used in python scripts etc.
Everything is managed by python scripts. These create and
prepare the classes then call Zope page templates and pass down these
objects as parameters of the templates. This way is clear from
the arguments what any given page can and cannot display.

It is a very clean architecture that repeatedly surprises me by
its long term maintainability.

I have puttered around for very long with dtml, external methods and
ZClasses, these features are great for "hooking" PHP or JSP minded people
(in fact this is how I got interested originally) but I would never touch
them anymore.

I.
 
L

Lee Harr

Hi,
I am a PHP developer. i am currently studying Zope and want to migrate
to it. I have developed a school management system in PHP. but now I
want to implement it in Zope. I have worked through The Zope Book 2.6
and Zope Developers Guide quickly(not thoroughly). My problem is that
I am confused where to start.
System is supposed to admit students and assign unique ids to
them. student object will be stored in ZODB. searching on id, first,
mid and last names and possibly on other attributes like sex, date of
birth etc has to be provided. system is to be used by end users and
not zope administrators.

Now the problem is that I am confused how to implement these
classes. Should I implement them as ZClass or in External methods or
as a Zope Product. Please Clarify. Also tell me how, actually, am I
supposed to start. small code sample can be a of great help. Links to
similar free projects undertaken on zope can be useful.

PS: Actually it is a small part of overall system which provides
transport management, class/course management, exam/result management,
employees payrolls and basic accounting for high schools. but to start
with it should be enough to help me get a better feel of zope.


I have worked with Zope and Python quite a bit with databases.
My approach lately has been to use a relational database (postgres)
for the data and just provide interfaces with Zope (and most
recently with Twisted/ nevow).

For instance, if your data were in a database working with PHP
you could just write interface code and access the same database
with Zope.

If you are just getting started with Zope, you may want to look
at Zope 3, as I understand it is quite different from the current
Zope system.

I moved to nevow for my current project because I want to run
the entire system on Pentium I systems (database, web front-end,
and a curses front-end also) and Zope was too heavy. So far
nevow is working out very well.

Years ago (before finding python) I used PHP quite a bit also.
I remember trying to use an object oriented style and running
in to a lot of strange problems. When I saw Python, I said
"Oooh. Now I understand object oriented!" I read that the PHP
object system was majorly overhauled for PHP5, but I also
read that it is still not quite right. I should take a look
though and see for myself...
 
M

mir nazim

Istvan Albert said:
I develop "standard" python classes for all the functionality
that has nothing to do with the display (business logic).
I develop, test and re-use these classes without Zope.

I deploy these classes in the module path of the python that
runs zope and I make them available in Zope (needs a few lines).

These classes can be now stored in sessions, used in python scripts etc.
Everything is managed by python scripts. These create and
prepare the classes then call Zope page templates and pass down these
objects as parameters of the templates. This way is clear from
the arguments what any given page can and cannot display.

It is a very clean architecture that repeatedly surprises me by
its long term maintainability.

I have puttered around for very long with dtml, external methods and
ZClasses, these features are great for "hooking" PHP or JSP minded people
(in fact this is how I got interested originally) but I would never touch
them anymore.
Seems cool. Please eleborate it a bit. possibly with some examples.
Thanks.
 
W

Wade Leftwich

Hi,
I am a PHP developer. i am currently studying Zope and want to migrate
to it. I have developed a school management system in PHP. but now I
want to implement it in Zope. I have worked through The Zope Book 2.6
and Zope Developers Guide quickly(not thoroughly). My problem is that
I am confused where to start.

Another post said "Don't use ZClasses", which is very good advice.

Python "Products" are a bit hard to get started with, but you'll be
happier in the long and medium-run. The best howto's I have found are
in the books "Zope Bible" and "Definitive Guide to Plone" (by Andy
McKay, just published, and really excellent. Order via the author's
website [ http://zopezen.org/ ] so he gets a commission).

I usually start developing a Zope project using only Scripts, Page
Templates, occcasional External Methods, and ZSQL Methods. Often
that's all you need to finish a project too.

-- Wade Leftwich
Ithaca, NY
 
I

Istvan Albert

mir said:
Seems cool. Please eleborate it a bit. possibly with some examples.

It is one of those things that are not well explained in the
Zope docs ... adn this post too seems like it should belong
to a Zope group.

Yet I heard python people say that the Zope model does not allow one
to approach a problem in a more rigorous, 'programatic' way.
This is only partly true. Here is how one could go about it
in what I think is the so called MVC, Model-View-Controller
pattern.

Let's say that we have a situation where one would need
to make use of an instance of a custom User.User class
located in a custom package named foo. (Note that I'm typing
this in so it might have typos in it.)

---

step 0. write and test the foo package and User.User class

---

step 1. you need to deploy your package into the
zope python. I use distutils:

<zope_python> setup.py install

the only thing here is that it is easy to forget and
use the "other" python ... then you are trying to track
probelms that don't actually exists, can be very annoying

--

step 2. enable the classes in Zope. Create a folder in the
Products directory called <whatever you want> Place the
following __init__.py file in this folder:

from AccessControl import allow_module, allow_class, allow_type
from foo import User
allow_module('foo.User')
allow_class(User.User)
allow_type(type(User))

--

step 3. to use your class here is the hello.py python script that
read the user instance from a session.

from foo import User

hello_zpt = container['hello.zpt']
error_zpt = container['error.zpt']

user = container.REQUEST.SESSION.get(key='user', None)

if user:
# I can do here whatever I want to with the user instance
if user.user_type == 'Troll':
msg= 'Go away!'
else:
msg ='Howdy!'
return home_zpt(user=user, msg=msg)
else:
return error_zpt(msg='Please log in!')

---

step 4. in hello.zpt then I have something like this:

A message for user <b tal:content="options/user/user_name"/> of type
<b tal:content="options/user/user_type"/> :
<b tal:content="options/msg"/>

---

I believe that The User.User class -> hello.py -> hello.zpt chain
forms what is called the MVC (Model-View-Controller) pattern.

The model is the class instance itself, the controller is hello.py and the view
is in hello.zpt. I found that it takes a lot of discipline to stay outside
the zpt files without computing all kinds of intermediate results in them.

When making small 'adjustments' it is very tempting to do them by defining
some behavior inside the zpt. But then, invariably, after a few days I
can't remember anymore how things work...

So for me putting everything in the .py controllers is paying off.

best,

Istvan.
 
M

Michele Simionato

Istvan Albert said:
It is one of those things that are not well explained in the
Zope docs ... adn this post too seems like it should belong
to a Zope group.
<snip>

Istvan's advice is not a bad one, especially for somebody coming from
the Python world and wanting a quick startup with Zope. I will just
add the
following piece of advice. You will probably want to have your
templates and scripts in the file
system and not in the Zope database (if your are thinking of
delivering
your application or just if you are more confortable with the file
system).
The trick is to put your templates/scripts in a subdirectory of
"skins"
and add the following to your __init__.py:

from Products.CMFCore import DirectoryView
DirectoryView.registerDirectory('skins/my_scripts_and_templates',
globals())

assuming "skins" is a directory inside your package and
"my_scripts_and_templates" is the subdirectory containing your .py and
..pt
files.

Michele Simionato
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top