323
323
productseries=self.context.productseries)
324
324
return potemplate_subset
326
def _findObjectionToFilePath(self, file_type, path):
327
"""Return textual objection, if any, to setting this file path."""
328
importer = getUtility(ITranslationImporter)
329
if file_type == TranslationFileType.POT:
330
if not importer.isTemplateName(path):
331
return "This filename is not appropriate for a template."
333
if not importer.isTranslationName(path):
334
return "This filename is not appropriate for a translation."
336
if path == self.context.path:
337
# No change, so no objections.
340
# The Rosetta Expert decided to change the path of the file.
341
# Before accepting such change, we should check first whether
342
# there is already another entry with that path in the same
343
# context (sourcepackagename/distroseries or productseries).
344
# A duplicate name will confuse the auto-approval
346
if file_type == TranslationFileType.POT:
347
potemplate_set = getUtility(IPOTemplateSet)
348
existing_file = potemplate_set.getPOTemplateByPathAndOrigin(
349
path, self.context.productseries, self.context.distroseries,
350
self.context.sourcepackagename)
351
already_exists = existing_file is not None
353
pofile_set = getUtility(IPOFileSet)
354
existing_files = pofile_set.getPOFilesByPathAndOrigin(
355
path, self.context.productseries,
356
self.context.distroseries,
357
self.context.sourcepackagename)
358
already_exists = not existing_files.is_empty()
361
# We already have an IPOFile in this path, let's notify
362
# the user about that so they choose another path.
363
return "There is already a file in the given path."
326
367
def _validatePath(self, file_type, path):
327
path_changed = False # Flag for change_action
328
if path == None or path.strip() == "":
329
self.setFieldError('path', 'The file name is missing.')
368
"""Should the entry's path be updated?"""
369
if path is None or path.strip() == "":
370
self.setFieldError('path', "The file name is missing.")
373
objection = self._findObjectionToFilePath(file_type, path)
374
if objection is None:
331
(fname, fext) = splitext(basename(path))
333
self.setFieldError('path',
334
'The file name is incomplete.')
335
if (file_type == TranslationFileType.POT and
336
fext.lower() != '.pot' and fext.lower() != '.xpi'):
337
self.setFieldError('path',
338
'The file name must end with ".pot".')
339
if (file_type == TranslationFileType.PO and
340
fext.lower() != '.po' and fext.lower() != '.xpi'):
341
self.setFieldError('path',
342
'The file name must end with ".po".')
344
if self.context.path != path:
345
# The Rosetta Expert decided to change the path of the file.
346
# Before accepting such change, we should check first whether
347
# there is already another entry with that path in the same
348
# context (sourcepackagename/distroseries or productseries).
349
if file_type == TranslationFileType.POT:
350
potemplate_set = getUtility(IPOTemplateSet)
352
potemplate_set.getPOTemplateByPathAndOrigin(
353
path, self.context.productseries,
354
self.context.distroseries,
355
self.context.sourcepackagename))
356
already_exists = existing_file is not None
358
pofile_set = getUtility(IPOFileSet)
359
existing_files = pofile_set.getPOFilesByPathAndOrigin(
360
path, self.context.productseries,
361
self.context.distroseries,
362
self.context.sourcepackagename)
363
already_exists = not existing_files.is_empty()
366
# We already have an IPOFile in this path, let's notify
367
# the user about that so they choose another path.
368
self.setFieldError('path',
369
'There is already a file in the given path.')
371
# There is no other pofile in the given path for this
372
# context, let's change it as requested by admins.
377
self.setFieldError('path', objection)
377
380
def _validatePOT(self, data):
378
381
name = data.get('name')