-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpy4web_DEAL.py
More file actions
683 lines (607 loc) · 29.7 KB
/
Copy pathpy4web_DEAL.py
File metadata and controls
683 lines (607 loc) · 29.7 KB
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
# Copyright 2021 Richard Behan-Howell
# Written by Richard Behan-Howell
# All rights reserved
from ..common import db, Field, T, auth
import json
from datetime import datetime
from yatl.helpers import SCRIPT, XML
import re
from py4web import action, request, abort, redirect, URL, Field, DAL, response
import os
from .. import settings
###########################################################
### USAGE
##########################################################
# Put this file in /<project folder>/libs/
# Recomended to use a format field correctly set in reference tables. E.g. format='%(name)s',
# in the controller, use this format, for example a video table.
"""
MODELS.PY:
########################################
db.define_table('group',
Field('name', type='string', unique=True,
label=T('Name')),
Field('f_desc', type='string',
label=T('Description')),
format='%(name)s',
)
db.define_table('t_video',
Field('f_name', type='string',
label=T('Name')),
Field('f_desc', type='string',
label=T('Description')),
Field('group', type='reference group',
label=T('Group')),
Field('f_vimeoid', type='string', label=T('VimeoID')),
format='%(f_name)s',
)
CONTROLLER.PY:
########################################
from .libs.datatables_API import dteditor_data
@action("video", method=["GET", "POST"])
@action.uses(session, db, auth.user, "videos.html")
def video():
page_title = 'Videos'
page_subtitle = 'Videos'
return dict(page_title=page_title, page_subtitle= page_subtitle)
@action('video_data', method=['GET', 'POST'])
@action.uses(session, db, auth.user)
def video_data():
table = db.t_video
return dteditor_data(table, request)
TEMPLATE: questions.html:
You need to lay out the datatables in javascript, E.G.
Download and install Editor
########################################
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4-4.1.1/jq-3.3.1/jszip-2.5.0/dt-1.10.24/af-2.3.5/b-1.7.0/b-colvis-1.7.0/b-html5-1.7.0/b-print-1.7.0/cr-1.5.3/date-1.0.3/fc-3.3.2/fh-3.1.8/kt-2.6.1/r-2.2.7/rg-1.1.2/rr-1.2.7/sc-2.0.3/sb-1.0.1/sp-1.2.2/sl-1.3.3/datatables.min.css"/>
<link rel="stylesheet" type="text/css" href="DataTables/Editor-2.0.1/css/editor.bootstrap4.css"/>
<div class="container-fluid">
<div class="row">
<div class="col-sm w-98 p-2 border">
<h1>questions</h1>
<table id="questions" class="table table-bordered table-sm table-hover" style="width:100%">
<thead>
<tr >
<th data-toggle="tooltip" data-placement="top" title="Name">Name</th>
<th data-toggle="tooltip" data-placement="top" title="Description">Desc</th>
<th data-toggle="tooltip" data-placement="top" title="Group">Group</th>
<th data-toggle="tooltip" data-placement="top" title="Picture">Picture</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<script>
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
///////////////////////////////////////////////////////
//question
///////////////////////////////////////////////////////
var questionEditor = new $.fn.dataTable.Editor
({
ajax: {
url: "/MindTrax/question_data",
data: function (d) {
var selected = questionTable.row({selected: true});
if (selected.any()) {
d.question = selected.data().t_question.id;
}
}
},
table: '#questions',
idSrc: "t_question.id",
fields: [
{
label: "Name:",
name: "t_question.f_name",
},
{
label: "Desc:",
name: "t_question.f_desc",
},
{
label: "group:",
name: "group.name",
type: "select",
},
{
label: "Picture:",
name: "t_question.picture",
type: "upload",
display: function (file_id) {
return file_id ?
'<img src="'+ '/MindTrax/downloadfile/t_question_'+ file_id.toString() + '.png" width="25" height="25">' :
null;
},
},
]
}
);
var questionTable = $('#questions').DataTable
( {
dom: 'BfrtipQ',
ajax: "/MindTrax/question_data",
idSrc: "t_question.id",
columns: [
{ data: 't_question.f_name',
title: "Name",
},
{ data: 't_question.f_desc',
title: "Description",
},
{ data: "group.name" },
{ data: "t_question.picture",
render: function ( file_id ) {
return file_id ?
'<img src="/MindTrax/downloadfile/t_question_' + file_id.toString() + '.png" width="25" height="25">' :
null;
},
defaultContent: "No image",
title: "Image",
},
],
select: {
style: 'single'
},
buttons: [
{ extend: 'create', editor: questionEditor },
{ extend: 'edit', editor: questionEditor },
{ extend: 'remove', editor: questionEditor },
],
} );
});
</script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4-4.1.1/jq-3.3.1/jszip-2.5.0/dt-1.10.24/af-2.3.5/b-1.7.0/b-colvis-1.7.0/b-html5-1.7.0/b-print-1.7.0/cr-1.5.3/date-1.0.3/fc-3.3.2/fh-3.1.8/kt-2.6.1/r-2.2.7/rg-1.1.2/rr-1.2.7/sc-2.0.3/sb-1.0.1/sp-1.2.2/sl-1.3.3/datatables.min.js"></script>
<script type="text/javascript" src="DataTables/Editor-2.0.1/js/dataTables.editor.js"></script>
<script type="text/javascript" src="DataTables/Editor-2.0.1/js/editor.bootstrap4.js"></script>
"""
###################################
#Helper functions
###################################
def format(table, row):
if not row:
return T('Unknown')
elif isinstance(table._format, str):
return table._format % row
elif callable(table._format):
return table._format(row)
else:
return '#' + str(row.id)
def plural(table):
return table._plural or pluralize(table._singular.lower()).capitalize()
def right(s, amount):
if s == None:
return None
elif amount == None:
return None # Or throw a missing argument error
s = str(s)
if amount > len(s):
return s
elif amount == 0:
return ""
else:
return s[-amount:]
###################################
# table_format_reference_list(table):
#
# Pass in a table e.g. db.group
# Assumes that the table has a format field correctly set. E.g. format='%(name)s',
# Generates a JSON list of lookup references from a table. format and id.
# E.G. [{'label': 'Inadequate', 'value': 2}, {'label': 'Confused2', 'value': 3}, {'label': 'Hurt', 'value': 4}]
# ###################################
def table_format_reference_list(table):
#print("table list: "+ table._tablename+ "\r")
#print("table format:" + db[table]._format)
list = []
query = (table.id > 0)
if db(table).isempty():
data = ["empty"]
else:
if db(table.id > 0).count() > 0:
for z in db(query).select():
list.append({'label': format(table, z), 'value': z.id})
print("list:" + str(list))
return list
"""
def record_data(table, z):
if z:
return {
"DT_RowId":"row_" + str(z.id),
table._tablename: {
"id":z.id,
"name":z.name,
"code":z.code,
}
}
else:
return []
"""
###################################
# files_record_data(table, z):
#
# Pass in a table e.g. db.group and row
# Assumes that the table has a format field correctly set. E.g. format='%(name)s',
####################################
def files_record_data(table, z):
if z:
return {
str(z.id): {
"id": str(z.id),
"name": format(table, z),
"filename": z.filename,
"filesize": z.filesize,
"web_path": z.web_path,
"system_path": z.system_path,
}
}
else:
return []
###################################################################################################
## OPTIONS
####################################################################################################
def generic_options(table):
# Takes a Table, finds any reference fields and populates a dictioanry of the [possible names and id for each reference field.
#return: {"grower.name":table_format_reference_list(db.grower),"variety.name":table_format_reference_list(db.variety),"branch.name":table_format_reference_list(db.branch)}
fields = [dict(name=f.name, type=f.type) for f in table if f.readable]
optiondict = {}
for f in fields:
if 'reference' in f.get('type'):
# get the name of the Field. I.e. grower_id
fieldname = f.get('type').split()[0]
# get the name of the reference table. I.e. Grower
reftable = f.get('type').split()[1]
#Get a list of name and id from that table using helper function table_format_reference_list
#print("reftable.format: " + str(db[reftable]._format) + '\r')
for t in db:
if reftable == t._tablename and reftable != 'upload' and reftable != 'auth_user':
print("t._tablename: " + str(t._tablename) + '\r')
print("table: " + str(db[reftable]._tablename) + '\r')
# print("%(name)s" % db[reftable].name)
optiondict.update({f.get('name')+str('.name'): table_format_reference_list(db[reftable])})
# {reftable: {'name': getattr(z, f.get('name')).name if getattr(z, f.get('name')) else 'Null'}})
elif reftable == t._tablename and reftable == 'auth_user':
print("t._tablename: " + str(t._tablename) + '\r')
print("table: " + str(db[reftable]._tablename) + '\r')
optiondict.update({f.get('name') + str('.username'): table_format_reference_list(db[reftable])})
# {reftable: {'name': getattr(z, f.get('name')).name if getattr(z, f.get('name')) else 'Null'}})
print("options tablelist: " + str(optiondict) + '\r')
return optiondict
############################################################################
# generic_record_data
#############################################################################
def generic_record_data(table, z):
fieldlist = []
if z:
fields = [dict(name=f.name, type=f.type) for f in table if f.readable]
record = {}
reflist = []
for f in fields:
#finalise all types of fields
if (f.get('type') == "datetime"):
try:
record.update({f.get('name'): z[f.get('name')].strftime('%Y-%m-%d')})
except:
record.update({f.get('name'): ""})
elif f.get('type') == "boolean":
record.update({f.get('name'): '1' if getattr(z, f.get('name')) else '0'})
elif 'reference' in f.get('type'):
record.update({f.get('name'): getattr(z, f.get('name'))})
reftable = f.get('type').split()[1]
# grower=dict(name=z.grower_id.name if z.grower_id else 'Null'),
f.get('name')
reflist.append(
{f.get('name'): {'name': getattr(z, f.get('name')).name if getattr(z, f.get('name')) else 'Null'}})
else:
record.update({f.get('name'): getattr(z, f.get('name'))})
#print("record: " + str(record) + '\r')
#print("reflist: " + str(reflist) + '\r')
data = {}
data.update({'DT_RowId':'row_' + str(z.id), table._tablename: record})
#Iterate through all reference fields and fill in their "name option.
for ref in reflist:
data.update(ref)
return data
else:
return []
def dteditor_data(table, request, query=None):
"""
datatables.net makes an ajax call to this method to get the data
1. read
Send back JSON about the table with all records and the referenced fields in the format:
2. create
3. edit
4. remove
:return:
"""
print("dteditor_data request method" + str(request.method))
data = []
files = []
files_dict = {}
option = []
if query is None:
query = (table.id > 0)
if request.method == 'GET':
#iterate through any fields here that are reference fields.
options = generic_options(table)
#{"grower.name":table_format_reference_list(db.grower),"variety.name":table_format_reference_list(db.variety),"branch.name":table_format_reference_list(db.branch)}
if db(table).isempty():
data = []
files = []
else:
if db(table.id > 0).count() > 0:
data = [generic_record_data(table,z) for z in db(query).select()]
for z in db(db.upload.table == table).select():
files_dict.update(files_record_data(db.upload,z))
files = {"files": files_dict}
#formulate the response:
return json.dumps(dict(data=data,options=options,files=files), indent=4, sort_keys=False, default=str)
elif request.method == 'POST':
action = request.forms.get("action")
print("action: " +str(action))
if action=="create":
kwargs = {}
#Need to iterate through the table fields looking for data for each, if nothing exists then ignore it, if it does then set it.
fields = [dict(name=f.name, type=f.type) for f in table if f.readable]
for f in fields:
# finalise for all types of fields
# datetime, date, time
if (f.get('type') == "datetime") or (f.get('type') == "date") or (f.get('type') == "time"):
for key in request.forms.keys():
if "data[0]["+table._tablename+"][" + f.get('name') + "]" in key:
print("if " + "data[0]["+table._tablename+"][" + f.get('name') + "]" + " in key")
print("True key:" + key)
try:
dt = datetime.strptime(request.forms.get("data[0]["+table._tablename+"][" + f.get('name') + "]"), '%Y-%m-%d').date()
kwargs.update({f.get('name'): dt})
except:
print("Datetime format error:" + request.forms.get("data[0]["+table._tablename+"][" + f.get('name') + "]"))
pass
elif (f.get('type') == "boolean"):
for key in request.forms.keys():
if "data[0]["+table._tablename+"][" + f.get('name') + "]" in key:
print("if " + "data[0]["+table._tablename+"][" + f.get('name') + "]" + " in key")
print("True key:" + key)
try:
kwargs.update({f.get('name'): True if ( request.forms.get("data[0]["+table._tablename+"][" + f.get('name') + "]") == "1") else False})
except:
pass
elif 'reference' in f.get('type'):
# reftable = f.get('type').split()[1]
for key in request.forms.keys():
if "data[0][" + f.get('name') + "][name]" in key:
print("if " + "data[0][" + f.get('name') + "][name]" + " in key")
print("True key:" + key)
try:
kwargs.update({f.get('name'): int(request.forms.get("data[0][" + f.get('name') + "][name]"))})
except:
pass
#Integers,
elif ((f.get('type') == "blob") or (f.get('type') == "integer") or (f.get('type') == "double")
or (f.get('type') == "bigint") or ('decimal' in f.get('type'))):
# blob, integer, double, decimal(n, m), bigint
for key in request.forms.keys():
if "data[0]["+table._tablename+"][" + f.get('name') + "]" in key:
print("if " + "data[0]["+table._tablename+"][" + f.get('name') + "]" + " in key")
print("True key:" + key)
try:
kwargs.update({f.get('name'): int(request.forms.get("data[0]["+table._tablename+"][" + f.get('name') + "]"))})
except:
pass
else:
#Stinrg, Text, password, json
for key in request.forms.keys():
if "data[0]["+table._tablename+"][" + f.get('name') + "]" in key:
print("if " + "data[0]["+table._tablename+"][" + f.get('name') + "]" + " in key")
print("True key:" + key)
try:
kwargs.update({f.get('name'): request.forms.get("data[0]["+table._tablename+"][" + f.get('name') + "]")})
except:
pass
print("kwargs:" + str(kwargs)+"\r\r")
#grower_id = request.forms.get("data[0][grower_id][name]")
#variety_id = request.forms.get("data[0][variety_id][name]")
#branch_id = request.forms.get("data[0][branch_id][name]")
#commencement_dt = datetime.strptime(request.forms.get("data[0][growercontract][commencement_dt]"), '%Y-%m-%d').date()
#expiry_dt = datetime.strptime(request.forms.get("data[0][growercontract][expiry_dt]"), '%Y-%m-%d').date()
#name = db.grower[grower_id].name + ',' + db.variety[variety_id].name + ',' + db.branch[branch_id].name
#contract_id = request.forms.get("data[0][growercontract][contract_id]")
#contractsigned = True if (request.forms.get("data[0][growercontract][contractsigned]")=="1") else False
#Create new
#Do other specific error checking here.
newid = table.insert(**kwargs)
"""
newid = table.insert(
name = name,
grower_id=grower_id,
variety_id=variety_id,
branch_id=branch_id,
commencement_dt=commencement_dt,
expiry_dt=expiry_dt,
contract_id=contract_id,
contractsigned=contractsigned,
)
"""
print("newid: "+str(newid))
db.commit()
z = db(table.id == int(newid)).select().first()
data = [generic_record_data(table,z)]
return json.dumps(dict(data=data), indent=4, sort_keys=True, default=str)
elif action == "edit":
id = 0
for key in request.forms.keys():
if "data" in key:
try:
a = key.split('[')
#print(str(a))
id = int(a[1].strip("]["))
print("id:"+str(id))
break
except:
return
#id = request.forms.get("growercontract")
kwargs = {}
# Need to iterate through the table fields looking for data for each, if nothing exists then ignore it, if it does then set it.
fields = [dict(name=f.name, type=f.type) for f in table if f.readable]
for f in fields:
# finalise for all types of fields
# datetime, date, time
if (f.get('type') == "datetime") or (f.get('type') == "date") or (f.get('type') == "time"):
for key in request.forms.keys():
if "data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]" in key:
print("if " + "data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]" + " in key")
print("True key:" + key)
try:
dt = datetime.strptime(
request.forms.get("data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]"),
'%Y-%m-%d').date()
kwargs.update({f.get('name'): dt})
except:
print("Datetime format error:" + request.forms.get(
"data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]"))
pass
elif (f.get('type') == "boolean"):
for key in request.forms.keys():
if "data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]" in key:
print("if " + "data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]" + " in key")
print("True key:" + key)
try:
kwargs.update({f.get('name'): True if (request.forms.get(
"data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]") == "1") else False})
except:
pass
elif 'reference' in f.get('type'):
# reftable = f.get('type').split()[1]
for key in request.forms.keys():
if "data["+str(id)+"][" + f.get('name') + "][name]" in key:
print("if " + "data["+str(id)+"][" + f.get('name') + "][name]" + " in key")
print("True key:" + key)
try:
kwargs.update(
{f.get('name'): int(request.forms.get("data["+str(id)+"][" + f.get('name') + "][name]"))})
except:
pass
# Integers,
elif ((f.get('type') == "blob") or (f.get('type') == "integer") or (f.get('type') == "double")
or (f.get('type') == "bigint") or ('decimal' in f.get('type'))):
# blob, integer, double, decimal(n, m), bigint
for key in request.forms.keys():
if "data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]" in key:
print("if " + "data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]" + " in key")
print("True key:" + key)
try:
kwargs.update({f.get('name'): int(
request.forms.get("data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]"))})
except:
pass
else:
# Stinrg, Text, password, json
for key in request.forms.keys():
if "data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]" in key:
print("STRING if " + "data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]" + " in key")
print("True key:" + key)
try:
kwargs.update({f.get('name'): request.forms.get(
"data["+str(id)+"][" + table._tablename + "][" + f.get('name') + "]")})
except:
pass
print("kwargs:" + str(kwargs) + "\r\r")
"""
grower_id = request.forms.get("data["+str(id)+"][grower_id][name]")
variety_id = request.forms.get("data["+str(id)+"][variety_id][name]")
branch_id = request.forms.get("data["+str(id)+"][branch_id][name]")
commencement_dt = datetime.strptime(request.forms.get("data["+str(id)+"][growercontract][commencement_dt]"), '%Y-%m-%d').date()
expiry_dt = datetime.strptime(request.forms.get("data["+str(id)+"][growercontract][expiry_dt]"), '%Y-%m-%d').date()
name = request.forms.get("data["+str(id)+"][growercontract][name]")
contract_id = request.forms.get("data["+str(id)+"][growercontract][contract_id]")
contractsigned = True if (request.forms.get("data["+str(id)+"][growercontract][contractsigned]")=="1") else False
"""
gc_query = (table.id == id)
z = db(gc_query).select().first()
z.update_record(**kwargs)
"""
name=name,
grower_id=grower_id,
variety_id=variety_id,
branch_id=branch_id,
commencement_dt=commencement_dt,
contract_id=contract_id,
expiry_dt=expiry_dt,
contractsigned=contractsigned,
)
"""
db.commit()
z = db(gc_query).select().first()
data = [ generic_record_data(table,z) ]
print("data: "+str(data))
return json.dumps(dict(data=data), indent=4, sort_keys=True, default=str)
elif action == "remove":
id = 0
for key in request.forms.keys():
if "data" in key:
try:
a = key.split('[')
# print(str(a))
id = int(a[1].strip("]["))
print("id:" + str(id))
break
except:
return
# id = request.forms.get("growercontract")
result = db(table.id == id).delete()
print("result:"+str(result))
return json.dumps(dict(data={}))
elif action == "upload":
"""Handle file upload form"""
upload = request.files.get('upload')
print("upload: "+str(upload.filename)+' '+str(upload.name))
# only allow upload of pdf files
#if upload.content_type != 'application/pdf':#'text/plain':
# return "Only PDF files allowed"
newid = db.upload.insert(
name = '',
filename = '',
filesize = -1,
web_path = '',
system_path = '',
table = str(table),
)
db.commit()
print("newid:"+str(newid))
upload.filename = table._tablename + '-' + str(newid) + right(upload.filename, 4)
web_path = str(URL('downloadfile/'+ upload.filename))
save_path = os.path.join(settings.UPLOAD_PATH,upload.filename)
print("webpath:" + str(web_path))#os.path.join('downloadfile', upload.filename))))
print("save_path:" + str(save_path))#os.path.join('downloadfile', upload.filename))))
print("newid:" + str(newid))#os.path.join('downloadfile', upload.filename))))
z = db(db.upload.id == newid).select(db.upload.ALL).first()
print("z.id:" + str(z.id))#os.path.join('downloadfile', upload.filename))))
ret = z.update_record(
name = upload.filename,
filename = upload.filename,
filesize = upload.content_length,
web_path = web_path,
system_path = save_path,
table=str(table),
)
db.commit()
z = db(db.upload.id == newid).select(db.upload.ALL).first()
print("newid:" + str(newid))#os.path.join('downloadfile', upload.filename))))
print("com z.id:" + str(z.id))#os.path.join('downloadfile', upload.filename))))
print("com z.filename:" + str(z.filename))#os.path.join('downloadfile', upload.filename))))
print("com z.webpath:" + str(z.web_path))#os.path.join('downloadfile', upload.filename))))
upload.save(save_path)
#formulate the response:
data = []
files = {"uploadedfiles": {str(z.id): {
"id": str(z.id),
"filename": z.filename,
"filesize": z.filesize,
"web_path": z.web_path,
"system_path": z.system_path,
}
}}
upload = {"id": z.id,"filename":z.filename }
return json.dumps(dict(data=data, files=files, upload=upload), indent=4, sort_keys=True, default=str)
else:
return json.dumps(dict(data={}), indent=4, sort_keys=True, default=str)