Merge branch 'bug-665226-do_not_create_att_if_error_in_write'

This commit is contained in:
Piotr Zalewa 2011-07-11 14:23:57 +01:00
Родитель 677dbc3634 f9ce844f4d
Коммит 1fd2c9cf78
3 изменённых файлов: 18 добавлений и 15 удалений

Просмотреть файл

@ -823,13 +823,12 @@ class PackageRevision(BaseModel):
kwargs = {
'author': author,
'filename': filename
}
'filename': filename}
if ext:
kwargs['ext'] = ext
attachment = self.attachment_create(**kwargs)
attachment = self.attachment_create(assign=False, **kwargs)
# we must write data of some sort, in order to create the file on the disk
# so at the least, write a blank string
@ -837,9 +836,10 @@ class PackageRevision(BaseModel):
content = ''
attachment.data = content
attachment.write()
self.attachment_add(attachment)
return attachment
def attachment_create(self, save=True, **kwargs):
def attachment_create(self, save=True, assign=True, **kwargs):
""" create attachment and add to attachments """
att = Attachment(**kwargs)
att.clean()
@ -848,10 +848,10 @@ class PackageRevision(BaseModel):
raise FilenameExistException(
('Sorry, there is already an attachment in your add-on with '
'the name "%s.%s". Each attachment in your add-on needs to '
'have a unique name.') % (att.filename, att.ext)
)
'have a unique name.') % (att.filename, att.ext))
att.save()
if assign:
self.attachment_add(att, save=save)
return att
@ -1851,9 +1851,12 @@ class Attachment(BaseModel):
try:
with codecs.open(self.get_file_path(), **kwargs) as f:
f.write(data)
except UnicodeDecodeError:
log.error('Attachment write failure: %s' % self.pk)
raise AttachmentWriteException('Attachment failed to save properly')
except UnicodeDecodeError, err:
log.error('Attachment write failure: (%s)\n%s' % (
self.pk, str(err)))
raise AttachmentWriteException(
'Attachment failed to save properly<br/>'
'Unknown unicode in file')
def export_code(self, static_dir):

Просмотреть файл

@ -13,10 +13,11 @@ Request = Class.refactor(Request, {
this.options.addOnFailure();
}
if (xhr.status != 0 && xhr.responseText) {
fd.error.alert(
'{statusText}'.substitute(xhr),
'{responseText}'.substitute(xhr)
);
response = xhr.responseText;
if (this.headers['X-Request'] == 'JSON') {
response = JSON.decode(response);
}
fd.error.alert(xhr.statusText, response);
}
}
},

Просмотреть файл

@ -580,7 +580,6 @@ var Sidebar = new Class({
filename = filename.replace(/^\//, '');
filename = filename.replace(/\/*$/g, ''); /* */
if (!isFolder && !filename.getFileExtension()) {
filename = filename.replace(/\./, '') + '.js'; //we're defaulting to .js files if the user doesnt enter an extension
}