Lines 83-92
def upload(self, request):
|
Link Here
|
---|
|
83 |
self._tmpDir = tempfile.mkdtemp(prefix='ucsschool-distribution-upload-') |
83 |
self._tmpDir = tempfile.mkdtemp(prefix='ucsschool-distribution-upload-') |
84 |
MODULE.info('Created temporary directory: %s' % self._tmpDir) |
84 |
MODULE.info('Created temporary directory: %s' % self._tmpDir) |
85 |
|
85 |
|
86 |
# we got an uploaded file with the following properties: |
86 |
### the following code block is a heuristic to support both: fixed and unfixed Bug #37716 |
87 |
# name, filename, tmpfile |
87 |
filename = file['filename'] |
88 |
destPath = os.path.join(self._tmpDir, file['filename']) |
88 |
try: |
89 |
MODULE.info('Received file "%s", saving it to "%s"' % (file['tmpfile'], destPath)) |
89 |
# The UMC-Webserver decodes filename in latin-1, need to revert |
|
|
90 |
filename = filename.encode('ISO8859-1') |
91 |
except UnicodeEncodeError: |
92 |
# we got non-latin characters, Bug #37716 is fixed and string contains e.g. '→' |
93 |
filename = file['filename'].encode('UTF-8') |
94 |
else: |
95 |
# the string contains at least no non-latin1 characters |
96 |
try: |
97 |
# try if the bytes could be UTF-8 |
98 |
# can't fail if Bug #37716 is fixed |
99 |
filename.decode('UTF-8') |
100 |
except UnicodeDecodeError: |
101 |
filename = file['filename'].encode('UTF-8') # Bug #37716 was fixed |
102 |
MODULE.info('Detected filename %r as %r' % (file['filename'], filename)) |
103 |
### the code block can be removed and replaced by filename = file['filename'].encode('UTF-8') after Bug #37716 |
104 |
destPath = os.path.join(self._tmpDir, filename) |
105 |
MODULE.info('Received file %r, saving it to %r' % (file['tmpfile'], destPath)) |
90 |
shutil.move(file['tmpfile'], destPath) |
106 |
shutil.move(file['tmpfile'], destPath) |
91 |
|
107 |
|
92 |
# done |
108 |
# done |
Lines 117-122
def checkfiles(self, request):
|
Link Here
|
---|
|
117 |
|
133 |
|
118 |
result = [] |
134 |
result = [] |
119 |
for ifile in request.options.get('filenames'): |
135 |
for ifile in request.options.get('filenames'): |
|
|
136 |
ifile = ifile.encode('UTF-8') |
120 |
# check whether file has already been upload in this session |
137 |
# check whether file has already been upload in this session |
121 |
iresult = dict(sessionDuplicate = False, projectDuplicate = False, distributed = False) |
138 |
iresult = dict(sessionDuplicate = False, projectDuplicate = False, distributed = False) |
122 |
iresult['filename'] = ifile |
139 |
iresult['filename'] = ifile |
Lines 191-196
def _save( self, request, doUpdate = True, ldap_user_read = None, ldap_position
|
Link Here
|
---|
|
191 |
for k in ('atJobNumCollect', 'atJobNumDistribute'): |
208 |
for k in ('atJobNumCollect', 'atJobNumDistribute'): |
192 |
iprops.pop(k, None) |
209 |
iprops.pop(k, None) |
193 |
|
210 |
|
|
|
211 |
# transform filenames into bytestrings |
212 |
iprops['files'] = [f.encode('UTF-8') for f in iprops.get('files', [])] |
213 |
|
194 |
# load the project or create a new one |
214 |
# load the project or create a new one |
195 |
project = None |
215 |
project = None |
196 |
orgProject = None |
216 |
orgProject = None |