예제 #1
0
    def clean_custom_css(self, *args, **kwargs):

        if self.cleaned_data.get('custom_css') or self.files.get('custom_css'):
            css = self.cleaned_data['custom_css'] or self.files['custom_css']
            try:
                validate_css(css.read())
                return css
            except IsADirectoryError:
                self.instance.custom_css = None
                self.instance.save(update_fields=['custom_css'])
        else:
            self.instance.custom_css = None
            self.instance.save(update_fields=['custom_css'])
예제 #2
0
파일: event.py 프로젝트: realaxl/pretalx
 def clean_custom_css(self):
     if self.cleaned_data.get("custom_css") or self.files.get("custom_css"):
         css = self.cleaned_data["custom_css"] or self.files["custom_css"]
         if self.is_administrator:
             return css
         try:
             validate_css(css.read())
             return css
         except IsADirectoryError:
             self.instance.custom_css = None
             self.instance.save(update_fields=["custom_css"])
     else:
         self.instance.custom_css = None
         self.instance.save(update_fields=["custom_css"])
     return None
예제 #3
0
파일: event.py 프로젝트: realaxl/pretalx
 def clean_custom_css_text(self):
     css = self.cleaned_data.get("custom_css_text").strip()
     if not css or self.is_administrator:
         return css
     validate_css(css)
     return css
예제 #4
0
def test_invalid_css(invalid_css):
    with pytest.raises(ValidationError):
        validate_css(invalid_css)
예제 #5
0
def test_valid_css(valid_css):
    assert validate_css(valid_css) == valid_css