コード例 #1
0
def validate_font(value):
    """Simple extension based validation for uploads."""
    ext = os.path.splitext(value.name)[1]
    if ext.lower() not in (".ttf", ".otf"):
        raise ValidationError(_("Unsupported file format."))
    try:
        get_font_name(value)
    except OSError:
        raise ValidationError(_("Unsupported file format."))
    return value
コード例 #2
0
ファイル: models.py プロジェクト: zypA13510/weblate
 def clean(self):
     # Try to parse file only if it passed validation
     if "font" not in self.field_errors and not self.family:
         self.family, self.style = get_font_name(self.font)