Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
c1e78721
Commit
c1e78721
authored
Dec 06, 1999
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the ability to use a ZClass as a brain.
parent
ceda2236
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
63 deletions
+109
-63
lib/python/Shared/DC/ZRDB/DA.py
lib/python/Shared/DC/ZRDB/DA.py
+41
-8
lib/python/Shared/DC/ZRDB/RDB.py
lib/python/Shared/DC/ZRDB/RDB.py
+21
-26
lib/python/Shared/DC/ZRDB/Results.py
lib/python/Shared/DC/ZRDB/Results.py
+25
-28
lib/python/Shared/DC/ZRDB/advanced.dtml
lib/python/Shared/DC/ZRDB/advanced.dtml
+22
-1
No files found.
lib/python/Shared/DC/ZRDB/DA.py
View file @
c1e78721
...
...
@@ -85,8 +85,8 @@
__doc__
=
'''Generic Database adapter
$Id: DA.py,v 1.7
5 1999/11/16 20:19:52 jeffrey
Exp $'''
__version__
=
'$Revision: 1.7
5
$'
[
11
:
-
2
]
$Id: DA.py,v 1.7
6 1999/12/06 15:31:36 jim
Exp $'''
__version__
=
'$Revision: 1.7
6
$'
[
11
:
-
2
]
import
OFS.SimpleItem
,
Aqueduct
,
RDB
import
DocumentTemplate
,
marshal
,
md5
,
base64
,
Acquisition
,
os
...
...
@@ -133,6 +133,7 @@ class DA(
cache_time_
=
0
max_cache_
=
100
class_name_
=
class_file_
=
''
_zclass
=
None
allow_simple_one_argument_traversal
=
None
manage_options
=
(
...
...
@@ -150,7 +151,8 @@ class DA(
'manage_advancedForm'
,
'PrincipiaSearchSource'
)),
(
'Change Database Methods'
,
(
'manage_edit'
,
'manage_advanced'
,
'manage_testForm'
,
'manage_test'
)),
(
'manage_edit'
,
'manage_advanced'
,
'manage_testForm'
,
'manage_test'
,
'manage_product_zclass_info'
)),
(
'Use Database Methods'
,
(
'__call__'
,
''
),
(
'Anonymous'
,
'Manager'
)),
)
...
...
@@ -231,7 +233,7 @@ class DA(
def
manage_advanced
(
self
,
max_rows
,
max_cache
,
cache_time
,
class_name
,
class_file
,
direct
=
None
,
REQUEST
=
None
):
REQUEST
=
None
,
zclass
=
''
):
"""Change advanced properties
The arguments are:
...
...
@@ -267,6 +269,14 @@ class DA(
self
.
class_name_
,
self
.
class_file_
=
class_name
,
class_file
self
.
_v_brain
=
getBrain
(
self
.
class_file_
,
self
.
class_name_
,
1
)
self
.
allow_simple_one_argument_traversal
=
direct
if
zclass
:
for
d
in
self
.
aq_acquire
(
'_getProductRegistryData'
)(
'zclasses'
):
if
(
"%s/%s"
%
(
d
.
get
(
'product'
),
d
.
get
(
'id'
)))
==
zclass
:
self
.
_zclass
=
d
[
'meta_class'
]
break
if
REQUEST
is
not
None
:
m
=
"ZSQL Method advanced settings have been set"
return
self
.
manage_advancedForm
(
self
,
REQUEST
,
manage_tabs_message
=
m
)
...
...
@@ -296,7 +306,8 @@ class DA(
try
:
try
:
src
=
self
(
REQUEST
,
src__
=
1
)
if
find
(
src
,
'
\
0
'
):
src
=
join
(
split
(
src
,
'
\
0
'
),
'
\
n
'
+
'-'
*
60
+
'
\
n
'
)
if
find
(
src
,
'
\
0
'
):
src
=
join
(
split
(
src
,
'
\
0
'
),
'
\
n
'
+
'-'
*
60
+
'
\
n
'
)
result
=
self
(
REQUEST
,
test__
=
1
)
if
result
.
_searchable_result_columns
():
r
=
custom_default_report
(
self
.
id
,
result
)
...
...
@@ -307,7 +318,8 @@ class DA(
r
=
'<strong>Error, <em>%s</em>:</strong> %s'
%
(
t
,
v
)
report
=
DocumentTemplate
.
HTML
(
'<html><BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
\
n
'
'<html>
\
n
'
'<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
\
n
'
'<dtml-var manage_tabs>
\
n
<hr>
\
n
%s
\
n
\
n
'
'<hr><strong>SQL used:</strong><br>
\
n
<pre>
\
n
%s
\
n
</pre>
\
n
<hr>
\
n
'
'</body></html>'
...
...
@@ -408,13 +420,16 @@ class DA(
else
:
brain
=
self
.
_v_brain
=
getBrain
(
self
.
class_file_
,
self
.
class_name_
)
zc
=
self
.
_zclass
if
zc
is
not
None
:
zc
=
zc
.
_zclass_
if
type
(
result
)
is
type
(
''
):
f
=
StringIO
()
f
.
write
(
result
)
f
.
seek
(
0
)
result
=
RDB
.
File
(
f
,
brain
,
p
)
result
=
RDB
.
File
(
f
,
brain
,
p
,
zc
)
else
:
result
=
Results
(
result
,
brain
,
p
)
result
=
Results
(
result
,
brain
,
p
,
zc
)
columns
=
result
.
_searchable_result_columns
()
if
test__
and
columns
!=
self
.
_col
:
self
.
_col
=
columns
return
result
...
...
@@ -442,6 +457,24 @@ class DA(
def
connected
(
self
):
return
getattr
(
getattr
(
self
,
self
.
connection_id
),
'connected'
)()
def
manage_product_zclass_info
(
self
):
r
=
[]
Z
=
self
.
_zclass
Z
=
getattr
(
Z
,
'aq_self'
,
Z
)
for
d
in
self
.
aq_acquire
(
'_getProductRegistryData'
)(
'zclasses'
):
z
=
d
[
'meta_class'
]
if
hasattr
(
z
.
_zclass_
,
'_p_deactivate'
):
# Eek, persistent
continue
x
=
{}
x
.
update
(
d
)
x
[
'selected'
]
=
(
z
is
Z
)
and
'selected'
or
''
del
x
[
'meta_class'
]
r
.
append
(
x
)
return
r
Globals
.
default__class_init__
(
DA
)
...
...
lib/python/Shared/DC/ZRDB/RDB.py
View file @
c1e78721
...
...
@@ -85,8 +85,8 @@
__doc__
=
'''Class for reading RDB files
$Id: RDB.py,v 1.2
3 1999/03/10 00:15:44 kl
m Exp $'''
__version__
=
'$Revision: 1.2
3
$'
[
11
:
-
2
]
$Id: RDB.py,v 1.2
4 1999/12/06 15:31:36 ji
m Exp $'''
__version__
=
'$Revision: 1.2
4
$'
[
11
:
-
2
]
import
regex
,
regsub
from
string
import
split
,
strip
,
lower
,
upper
,
atof
,
atoi
,
atol
,
find
,
join
...
...
@@ -113,9 +113,6 @@ Parsers={'n': atof,
't'
:
parse_text
,
}
record_classes
=
{}
class
SQLAlias
(
ExtensionClass
.
Base
):
def
__init__
(
self
,
name
):
self
.
_n
=
name
def
__of__
(
self
,
parent
):
return
getattr
(
parent
,
self
.
_n
)
...
...
@@ -127,12 +124,13 @@ class DatabaseResults:
"""
_index
=
None
def
__init__
(
self
,
file
,
brains
=
NoBrains
,
parent
=
None
):
def
__init__
(
self
,
file
,
brains
=
NoBrains
,
parent
=
None
,
zbrains
=
None
):
self
.
_file
=
file
readline
=
file
.
readline
line
=
readline
()
self
.
_parent
=
parent
if
zbrains
is
None
:
zbrains
=
NoBrains
comment_pattern
=
regex
.
compile
(
'#'
)
while
line
and
comment_pattern
.
match
(
line
)
>=
0
:
line
=
readline
()
...
...
@@ -201,30 +199,27 @@ class DatabaseResults:
# Create a record class to hold the records.
names=tuple(names)
if record_classes.has_key((names,brains)):
r=record_classes[names,brains]
else:
class r(Record, Implicit, brains):
'
Result
record
class
'
r.__record_schema__=schema
for k in filter(lambda k: k[:2]=='
__
', Record.__dict__.keys()):
setattr(r,k,getattr(Record,k))
record_classes[names,brains]=r
class r(Record, Implicit, brains, zbrains):
'
Result
record
class
'
r.__record_schema__=schema
for k in filter(lambda k: k[:2]=='
__
', Record.__dict__.keys()):
setattr(r,k,getattr(Record,k))
# Add SQL Aliases
d=r.__dict__
for k, v in aliases:
if not hasattr(r,k): d[k]=v
# Add SQL Aliases
d=r.__dict__
for k, v in aliases:
if not hasattr(r,k): d[k]=v
if hasattr(brains, '
__init__
'):
binit=brains.__init__
if hasattr(binit,'
im_func
'): binit=binit.im_func
def __init__(self, data, parent, binit=binit):
Record.__init__(self,data)
binit(self.__of__(parent))
if hasattr(brains, '
__init__
'):
binit=brains.__init__
if hasattr(binit,'
im_func
'): binit=binit.im_func
def __init__(self, data, parent, binit=binit):
Record.__init__(self,data)
binit(self.__of__(parent))
r.__dict__['
__init__
']=__init__
r.__dict__['
__init__
']=__init__
self._class=r
...
...
lib/python/Shared/DC/ZRDB/Results.py
View file @
c1e78721
...
...
@@ -88,8 +88,6 @@ from string import strip, lower, upper, join
from
Acquisition
import
Implicit
from
Record
import
Record
record_classes
=
{}
class
SQLAlias
(
ExtensionClass
.
Base
):
def
__init__
(
self
,
name
):
self
.
_n
=
name
def
__of__
(
self
,
parent
):
return
getattr
(
parent
,
self
.
_n
)
...
...
@@ -101,7 +99,8 @@ class Results:
"""
_index
=
None
def
__init__
(
self
,(
items
,
data
),
brains
=
NoBrains
,
parent
=
None
):
def
__init__
(
self
,(
items
,
data
),
brains
=
NoBrains
,
parent
=
None
,
zbrains
=
None
):
self
.
_data
=
data
self
.
__items__
=
items
...
...
@@ -110,6 +109,7 @@ class Results:
self
.
_schema
=
schema
=
{}
self
.
_data_dictionary
=
dd
=
{}
aliases
=
[]
if
zbrains
is
None
:
zbrains
=
NoBrains
i
=
0
for
item
in
items
:
name
=
item
[
'name'
]
...
...
@@ -131,31 +131,28 @@ class Results:
# Create a record class to hold the records.
names
=
tuple
(
names
)
if
record_classes
.
has_key
((
names
,
brains
)):
r
=
record_classes
[
names
,
brains
]
else
:
class
r
(
Record
,
Implicit
,
brains
):
'Result record class'
r
.
__record_schema__
=
schema
for
k
in
filter
(
lambda
k
:
k
[:
2
]
==
'__'
,
Record
.
__dict__
.
keys
()):
setattr
(
r
,
k
,
getattr
(
Record
,
k
))
record_classes
[
names
,
brains
]
=
r
# Add SQL Aliases
d
=
r
.
__dict__
for
k
,
v
in
aliases
:
if
not
hasattr
(
r
,
k
):
d
[
k
]
=
v
if
hasattr
(
brains
,
'__init__'
):
binit
=
brains
.
__init__
if
hasattr
(
binit
,
'im_func'
):
binit
=
binit
.
im_func
def
__init__
(
self
,
data
,
parent
,
binit
=
binit
):
Record
.
__init__
(
self
,
data
)
if
parent
is
not
None
:
self
=
self
.
__of__
(
parent
)
binit
(
self
)
r
.
__dict__
[
'__init__'
]
=
__init__
class
r
(
Record
,
Implicit
,
brains
,
zbrains
):
'Result record class'
r
.
__record_schema__
=
schema
for
k
in
filter
(
lambda
k
:
k
[:
2
]
==
'__'
,
Record
.
__dict__
.
keys
()):
setattr
(
r
,
k
,
getattr
(
Record
,
k
))
# Add SQL Aliases
d
=
r
.
__dict__
for
k
,
v
in
aliases
:
if
not
hasattr
(
r
,
k
):
d
[
k
]
=
v
if
hasattr
(
brains
,
'__init__'
):
binit
=
brains
.
__init__
if
hasattr
(
binit
,
'im_func'
):
binit
=
binit
.
im_func
def
__init__
(
self
,
data
,
parent
,
binit
=
binit
):
Record
.
__init__
(
self
,
data
)
if
parent
is
not
None
:
self
=
self
.
__of__
(
parent
)
binit
(
self
)
r
.
__dict__
[
'__init__'
]
=
__init__
self
.
_class
=
r
...
...
lib/python/Shared/DC/ZRDB/advanced.dtml
View file @
c1e78721
...
...
@@ -47,7 +47,28 @@ directory of this Zope installation.
value=
"<dtml-var class_name_ html_quote>"
></td></tr>
<tr>
<th
align=
'LEFT'
><em>
Class file
</em></th>
<td
align=
'LEFT'
><input
name=
"class_file"
size=
"30"
value=
"<dtml-var class_file_ html_quote>"
></td></tr>
value=
"&dtml-class_file_;"
></td></tr>
<dtml-if
manage_product_zclass_info
>
<tr><td>
</td></tr>
<tr><td
colspan=
2
><br><br>
You may specify a
<strong>
ZClass
</strong>
for the data records.
</td>
<tr>
<th
align=
'LEFT'
><em>
ZClass
</em></th>
<td
align=
'LEFT'
>
<select
name=
"zclass"
>
<option
value=
""
>
No ZClass
</option>
<dtml-in
manage_product_zclass_info
mapping
>
<dtml-with
"
_(v=
'%s/%s'
%
(
product
,
id
))"
>
<option
value=
"&dtml-v;"
&
dtml-selected
;
>
<dtml-var
product
>
<dtml-var
id
>
(
<dtml-var
meta_type
>
)
</option>
</dtml-with>
</dtml-in>
</select>
</td>
</tr>
</dtml-if
manage_product_zclass_info
>
<tr><td>
</td></tr>
<tr><td></td><td><input
type=
"SUBMIT"
name=
"SUBMIT"
value=
"Change"
></td></tr>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment