This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
executable file
·87 lines (67 loc) · 2.68 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# IMU utility methods
import csv, types
from StringIO import StringIO
from AccessControl import ModuleSecurityInfo
from DateTime import DateTime
def checkProjectId(folder, pid, mandant):
"""
check the imu combination id/mandant for a research object
if an object with this combination already exists. then upgrade or remove the object
"""
pobjid = ''
opid = ''
if len(pid)<5:
return (pobjid, opid)
pid_part = pid[:5]
ptool = folder.portal_url
portal = ptool.getPortalObject()
ctool = portal.portal_catalog
fpath = ptool.getPortalPath()+'/'+ptool.getRelativeUrl(folder)
catres = ctool( {'portal_type':'Research'
, 'path':fpath
, 'projectnumber':pid_part+'*'
, 'mandant':mandant} )
for c in catres:
cobj = c.getObject()
opid = cobj.projectnumber
if opid==pid: # identisches projekt -> ersetzen
pobjid = cobj.getId()
break
else:
onum = int(opid[5:])
nnum = int(pid[5:])
if onum < 90: # altes projekt im upgradebeich
if nnum < 90: # neues projekt im upgradebeich -> upgrade
pobjid = cobj.getId()
break
else: # neues projekt im archiv bereich -> neu anlegen
pobjid = ''
else: # altes projekt im archiv bereich -> neu anlegen
pobjid = ''
return (pobjid, opid)
def getProjects(fp):
"""
Return dictionary list with project values
"""
fn = ['Mandant', 'Projekt', 'Kurztitel', 'Titel', 'Projektart', 'Beginn', 'Ende', 'Abgabe', 'W\xe4hrung', 'Leitung', 'Zuordnung', 'Kurzinhalt', 'Partner', 'Geldgeber']
fnused = {'Mandant':'mandant', 'Projekt':'projectnumber', 'Kurztitel':'title', 'Titel':'description', 'Projektart':'projecttype', 'Beginn':'start_date', 'Ende':'end_date', 'Leitung':'manager','Kurzinhalt':'bodytext', 'Partner':'partner', 'Geldgeber':'financier'}
class imucsv(csv.Dialect):
delimiter = '\t'
quotechar = '"'
doublequote = False
skipinitialspace = True
lineterminator = '\r\n'
quoting = csv.QUOTE_MINIMAL
csv.register_dialect("imucsv", imucsv)
reader=csv.DictReader(fp,fn,dialect="imucsv")
retval=[]
i=0
for row in reader:
prj_dict={}
for key in row:
if fnused.has_key(key):
prj_dict[fnused[key]]=row[key]
# do not add first record (header):
if i>0: retval.append(prj_dict)
i+=1
return retval