abstract = True
+class FilenameMixin(object):
+
+ @property
+ def filename(self):
+ """Return a sanitized filename without extension."""
+ fname_re = re.compile(r'[^-_A-Za-z0-9\.]+')
+ fname = fname_re.sub('-', str(self)).strip('-')
+ return fname
+
+
@python_2_unicode_compatible
-class Submission(EmailMixin, models.Model):
+class Submission(FilenameMixin, EmailMixin, models.Model):
# parent
project = models.ForeignKey(Project, on_delete=models.CASCADE)
return self.project.is_editable(user)
- @property
- def filename(self):
- fname_re = re.compile(r'[^-_A-Za-z0-9\.]+')
- str = fname_re.sub('-', self.name)
- return str.strip('-') + '.patch'
-
@property
def combined_check_state(self):
"""Return the combined state for all checks.
@python_2_unicode_compatible
-class Series(models.Model):
+class Series(FilenameMixin, models.Model):
"""An collection of patches."""
# parent
def received_all(self):
return self.total <= self.received_total
- @property
- def filename(self):
- fname_re = re.compile(r'[^-_A-Za-z0-9\.]+')
- fname = fname_re.sub('-', str(self))
- return fname.strip('-') + '.patch'
-
def add_cover_letter(self, cover):
"""Add a cover letter to the series.
response = HttpResponse(content_type="text/x-patch")
response.write(patch.diff)
- response['Content-Disposition'] = 'attachment; filename=' + \
- patch.filename.replace(';', '').replace('\n', '')
+ response['Content-Disposition'] = 'attachment; filename=%s.diff' % (
+ patch.filename)
return response
response.write(series_patch_to_mbox(patch, series_id))
else:
response.write(patch_to_mbox(patch))
- response['Content-Disposition'] = 'attachment; filename=' + \
- patch.filename.replace(';', '').replace('\n', '')
+ response['Content-Disposition'] = 'attachment; filename=%s.patch' % (
+ patch.filename)
return response
response = HttpResponse(content_type='text/plain')
response.write(series_to_mbox(series))
- response['Content-Disposition'] = 'attachment; filename=' + \
- series.filename.replace(';', '').replace('\n', '')
+ response['Content-Disposition'] = 'attachment; filename=%s.patch' % (
+ series.filename)
return response