예제 #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)