2020-12-15 22:33:43 +01:00
|
|
|
from django import forms
|
2021-05-26 17:35:21 +02:00
|
|
|
|
2021-08-05 12:25:25 +02:00
|
|
|
from files.methods import is_mediacms_manager
|
|
|
|
|
2021-05-26 17:35:21 +02:00
|
|
|
from .models import Channel, User
|
2020-12-15 22:33:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SignupForm(forms.Form):
|
|
|
|
name = forms.CharField(max_length=100, label="Name")
|
|
|
|
|
|
|
|
def signup(self, request, user):
|
|
|
|
user.name = self.cleaned_data["name"]
|
|
|
|
user.save()
|
|
|
|
|
|
|
|
|
|
|
|
class UserForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"description",
|
|
|
|
"logo",
|
|
|
|
"notification_on_comments",
|
|
|
|
"is_featured",
|
|
|
|
"advancedUser",
|
|
|
|
"is_manager",
|
|
|
|
"is_editor",
|
2021-05-26 17:35:21 +02:00
|
|
|
# "allow_contact",
|
2020-12-15 22:33:43 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def clean_logo(self):
|
|
|
|
image = self.cleaned_data.get("logo", False)
|
|
|
|
if image:
|
|
|
|
if image.size > 2 * 1024 * 1024:
|
|
|
|
raise forms.ValidationError("Image file too large ( > 2mb )")
|
|
|
|
return image
|
|
|
|
else:
|
|
|
|
raise forms.ValidationError("Please provide a logo")
|
|
|
|
|
|
|
|
def __init__(self, user, *args, **kwargs):
|
|
|
|
super(UserForm, self).__init__(*args, **kwargs)
|
|
|
|
self.fields.pop("is_featured")
|
2021-08-05 12:25:25 +02:00
|
|
|
if not is_mediacms_manager(user):
|
2020-12-15 22:33:43 +01:00
|
|
|
self.fields.pop("advancedUser")
|
|
|
|
self.fields.pop("is_manager")
|
|
|
|
self.fields.pop("is_editor")
|
|
|
|
|
|
|
|
|
|
|
|
class ChannelForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Channel
|
|
|
|
fields = ("banner_logo",)
|
|
|
|
|
|
|
|
def clean_banner_logo(self):
|
|
|
|
image = self.cleaned_data.get("banner_logo", False)
|
|
|
|
if image:
|
|
|
|
if image.size > 2 * 1024 * 1024:
|
|
|
|
raise forms.ValidationError("Image file too large ( > 2mb )")
|
|
|
|
return image
|
|
|
|
else:
|
|
|
|
raise forms.ValidationError("Please provide a banner")
|