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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
''' -- imports from installed packages -- '''
from django.http import StreamingHttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response, render
from django.template import RequestContext
from django.contrib.auth.models import User
from django.contrib.auth.decorators import user_passes_test
from gnowsys_ndf.settings import LANGUAGES
from gnowsys_ndf.ndf.models import node_collection, triple_collection
from gnowsys_ndf.ndf.views.methods import *
import json
import datetime
@user_passes_test(lambda u: u.is_superuser)
def adminDesignerDashboardClass(request, class_name='GSystemType'):
'''
fetching class's objects
'''
if request.method=="POST":
search = request.POST.get("search","")
classtype = request.POST.get("class","")
nodes = node_collection.find({'name':{'$regex':search,'$options': 'i' },'_type':classtype}).sort('last_update', -1)
else :
nodes = node_collection.find({'_type':class_name}).sort('last_update', -1)
objects_details = []
for each in nodes:
member = []
member_of_list = []
collection_list = []
attribute_type_set = []
relation_type_set = []
for e in each.member_of:
member_of_list.append(node_collection.one({'_id':e}).name+" - "+str(e))
for members in each.member_of:
member.append(node_collection.one({ '_id': members}).name+" - "+str(members))
# for coll in each.collection_set:
# collection_list.append(node_collection.one({ '_id': coll}).name+" - "+str(coll))
if class_name in ("GSystemType"):
for at_set in each.attribute_type_set:
attribute_type_set.append(at_set.name+" - "+str(at_set._id))
for rt_set in each.relation_type_set:
relation_type_set.append(rt_set.name+" - "+str(rt_set._id))
objects_details.append({"Id":each._id,"Title":each.name,"Type":",".join(member),"Author":User.objects.get(id=each.created_by).username,"Creation":each.created_at,'member_of':",".join(member_of_list), "collection_list":",".join(collection_list), "attribute_type_set":",".join(attribute_type_set), "relation_type_set":",".join(relation_type_set)})
else :
objects_details.append({"Id":each._id,"Title":each.name,"Type":",".join(member),"Author":User.objects.get(id=each.created_by).username,"Creation":each.created_at,'member_of':",".join(member_of_list), "collection_list":",".join(collection_list)})
groups = []
group = node_collection.find({'_type':"Group"})
for each in group:
groups.append({'id':each._id,"title":each.name})
systemtypes = []
systemtype = node_collection.find({'_type':"GSystemType"})
for each in systemtype:
systemtypes.append({'id':each._id,"title":each.name})
meta_types = []
meta_type = node_collection.find({'_type':"MetaType"})
for each in meta_type:
meta_types.append({'id':each._id,"title":each.name})
groupid = ""
group_obj= node_collection.find({'$and':[{"_type":u'Group'},{"name":u'home'}]})
if group_obj:
groupid = str(group_obj[0]._id)
template = "ndf/adminDashboard.html"
variable = RequestContext(request, {'class_name':class_name,"nodes":objects_details,"Groups":groups,"systemtypes":systemtypes,"url":"designer","groupid":groupid,'meta_types':meta_types,'group_id':groupid})
return render_to_response(template, variable)
@user_passes_test(lambda u: u.is_superuser)
def adminDesignerDashboardClassCreate(request, class_name='GSystemType', node_id=None):
'''
delete class's objects
'''
global LANGUAGES
new_instance_type = None
LANGUAGES = '' if not LANGUAGES else LANGUAGES
definitionlist = []
contentlist = []
dependencylist = []
options = []
translate=request.GET.get('translate','')
if class_name == "AttributeType":
definitionlist = ['name','altnames','language','subject_type','data_type','applicable_node_type','member_of','verbose_name','null','blank','help_text','max_digits','decimal_places','auto_now','auto_now_add','path','verify_exist','status']
contentlist = ['content_org']
dependencylist = ['prior_node']
options = ['featured','created_at','start_publication','tags','url','last_update','login_required']
elif class_name == "GSystemType":
definitionlist = ['name','altnames','language','status','member_of','meta_type_set','attribute_type_set','relation_type_set','type_of']
contentlist = ['content_org']
dependencylist = ['prior_node']
options = ['featured','created_at','start_publication','tags','url','last_update','login_required']
elif class_name == "RelationType":
definitionlist = ['name','inverse_name','altnames','language','subject_type','object_type','subject_cardinality','object_cardinality','subject_applicable_nodetype','object_applicable_nodetype','is_symmetric','is_reflexive','is_transitive','status','member_of']
contentlist = ['content_org']
dependencylist = ['prior_node']
options = ['featured','created_at','start_publication','tags','url','last_update','login_required']
else :
definitionlist = []
contentlist = []
dependencylist = []
options = []
class_structure = eval(class_name).structure
required_fields = eval(class_name).required_fields
newdict = {}
if node_id:
new_instance_type = node_collection.one({'_type': unicode(class_name), '_id': ObjectId(node_id)})
else:
new_instance_type = eval("node_collection.collection"+"."+class_name)()
if request.method=="POST":
if translate:
new_instance_type = eval("node_collection.collection"+"."+class_name)()
for key,value in class_structure.items():
if value == bool:
if request.POST.get(key,""):
if request.POST.get(key,"") in ('1','2'):
if request.POST.get(key,"") == '1':
new_instance_type[key] = True
else :
new_instance_type[key] = False
elif value == unicode:
if request.POST.get(key,""):
if key == "content_org":
new_instance_type[key] = unicode(request.POST.get(key,""))
# Required to link temporary files with the current user who is modifying this document
usrname = request.user.username
filename = slugify(new_instance_type['name']) + "-" + usrname + "-"
new_instance_type['content'] = org2html(new_instance_type[key], file_prefix=filename)
else :
if translate:
if key in ("name","inverse_name"):
new_instance_type[key] = unicode(request.POST.get(key+"_trans",""))
language= request.POST.get('lan')
new_instance_type.language=language
else:
new_instance_type[key] = unicode(request.POST.get(key,""))
else:
new_instance_type[key] = unicode(request.POST.get(key,""))
elif value == list:
if request.POST.get(key,""):
new_instance_type[key] = request.POST.get(key,"").split(",")
elif type(value) == list:
if request.POST.get(key,""):
if key in ("tags","applicable_node_type"):
new_instance_type[key] = request.POST.get(key,"").split(",")
elif key in ["meta_type_set","attribute_type_set","relation_type_set"]:
listoflist = []
for each in request.POST.get(key,"").split(","):
listoflist.append(node_collection.one({"_id":ObjectId(each)}))
new_instance_type[key] = listoflist
else :
listoflist = []
for each in request.POST.get(key,"").split(","):
listoflist.append(ObjectId(each))
new_instance_type[key] = listoflist
elif value == datetime.datetime:
if key == "last_update":
new_instance_type[key] = datetime.datetime.now()
elif key == "status":
if request.POST.get(key,""):
new_instance_type[key] = unicode(request.POST.get(key,""))
# elif key == "created_by":
# new_instance_type[key] = request.user.id
elif value == int:
if request.POST.get(key,""):
new_instance_type[key] = int(request.POST.get(key,""))
else:
if request.POST.get(key,""):
new_instance_type[key] = request.POST.get(key,"")
user_id = request.user.id
if not new_instance_type.has_key('_id'):
new_instance_type.created_by = user_id
new_instance_type.modified_by = user_id
if user_id not in new_instance_type.contributors:
new_instance_type.contributors.append(user_id)
parent_node=node_collection.one({'_id':ObjectId(node_id)})
if translate and class_name == "RelationType":
new_instance_type.subject_type = parent_node.subject_type
new_instance_type.object_type = parent_node.object_type
if translate and class_name == "AttributeType":
new_instance_type.data_type = parent_node.data_type
new_instance_type.subject_type = parent_node.subject_type
new_instance_type.save()
if translate:
relation_type=node_collection.one({'$and':[{'name':'translation_of'},{'_type':'RelationType'}]})
grelation=node_collection.collection.GRelation()
grelation.relation_type=relation_type
grelation.subject=new_instance_type['_id']
grelation.right_subject=ObjectId(node_id)
grelation.name=u""
grelation.save()
return HttpResponseRedirect("/admin/designer/"+class_name)
# If GET request ---------------------------------------------------------------------------------------
for key,value in class_structure.items():
if value == bool:
# newdict[key] = "bool"
newdict[key] = ["bool", new_instance_type[key]]
elif value == unicode:
if key == "language":
newdict[key] = ["list", new_instance_type[key]]
else:
# newdict[key] = "unicode"
newdict[key] = ["unicode", new_instance_type[key]]
elif value == list:
# newdict[key] = "list"
newdict[key] = ["list", new_instance_type[key]]
elif type(value) == list:
# newdict[key] = "list"
newdict[key] = ["list", new_instance_type[key]]
elif value == datetime.datetime:
# newdict[key] = "datetime"
newdict[key] = ["datetime", new_instance_type[key]]
elif value == int:
# newdict[key] = "int"
newdict[key] = ["int", new_instance_type[key]]
elif key == "status":
# newdict[key] = "status"
newdict[key] = ["status", new_instance_type[key]]
else:
# newdict[key] = value
newdict[key] = [value, new_instance_type[key]]
class_structure = newdict
groupid = ""
group_obj= node_collection.find({'$and':[{"_type":u'Group'},{"name":u'home'}]})
if group_obj:
groupid = str(group_obj[0]._id)
template = "ndf/adminDashboardCreate.html"
variable = None
class_structure_with_values = {}
if node_id:
for key, value in class_structure.items():
class_structure_with_values[key] = [class_structure[key][0], new_instance_type[key]]
variable = RequestContext(request, {'node': new_instance_type,
'class_name': class_name, 'class_structure': class_structure_with_values, 'url': "designer",
'definitionlist': definitionlist, 'contentlist': contentlist, 'dependencylist': dependencylist,
'options': options, 'required_fields': required_fields,"translate":translate,"lan":LANGUAGES,
'groupid': groupid,'group_id':groupid
})
else:
variable = RequestContext(request, {'class_name':class_name, "url":"designer", "class_structure":class_structure, 'definitionlist':definitionlist, 'contentlist':contentlist, 'dependencylist':dependencylist, 'options':options, "required_fields":required_fields,"groupid":groupid,"translate":translate,"lan":LANGUAGES,'group_id':groupid})
return render_to_response(template, variable)
|