-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_contacts_status.py
82 lines (63 loc) · 2.28 KB
/
update_contacts_status.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
#!/usr/bin/env python
import sys
import socket
hostname = socket.gethostname()
if hostname == 'Pumukel-GNU-Tablet':
sys.path[0:0] = [
'/usr/local/Plone/redmine.buildout/src/python-redmine',
'/usr/local/Plone/buildout-cache/eggs/ipython-1.2.1-py2.7.egg',
'/usr/local/Plone/buildout-cache/eggs/ipdb-0.8-py2.7.egg',
'/usr/local/Plone/buildout-cache/eggs/requests-2.3.0-py2.7.egg',
]
elif hostname == 'redmine1':
sys.path[0:0] = [
'/data/redmine.buildout/src/python-redmine',
'/data/redmine.buildout/eggs/ipython-1.2.1-py2.6.egg',
'/data/redmine.buildout/eggs/ipdb-0.8-py2.6.egg',
'/data/redmine.buildout/eggs/requests-2.3.0-py2.6.egg',
]
from redmine import Redmine
import ipdb
from pprint import pprint
def import_contacts():
redmine = Redmine(
#'https://www.scm.verwaltung.uni-muenchen.de/internetdienste/',
'https://localhost/internetdienste/',
username='admin',
password='admin',
requests={'verify': False})
# custom_fields = redmine.custom_field.all()
# cf_status_id = None
# for cf in custom_fields:
# if cf.name == "Status":
# cf_status_id = cf.id
_all_contacts = redmine.contact.all()
# ipdb.set_trace()
ck = ''
for contact in _all_contacts:
fields = contact.custom_fields
ck = 'keine_' + contact.last_name.lower()
new_fields = []
for field in fields:
fval = field.value
if field.name == 'Campus-Kennung':
if field.value != '':
fval = field.value.strip().lower()
else:
fval = ck
ck = fval
elif field.name == 'Status':
fval = field.value
if fval == 'Aktiv':
fval = 'aktiver Fiona-Nutzer'
elif fval == 'Deaktiviert':
fval = 'deaktivierter Fiona-Nutzer'
elif fval == 'Ohne Fiona':
fval = 'aktiver Kunde ohne Fiona'
new_fields.append({'id': field.id, 'value': fval})
#ipdb.set_trace()
contact.custom_fields = new_fields
contact.save()
print 'Updated Contact: {ck}'.format(ck=ck)
if __name__ == "__main__":
import_contacts()