Ejemplo n.º 1
0
class ChannelOptionForm(forms.Form):
    """
    Form for managing channel members' permissions.
    Required arguments:
    - `channel` : the channel on which the permission will be used
    - `userprofile` : the user's profile on which the permission will apply
    """
    needs_approval = forms.BooleanField(required=False)

    def __init__(self, channel, user_profile, *args, **kwargs):
        """
        Set initial value for the `needs_approval` field based on the input
        Channel and UserProfile objects.
        
        """
        self.channel = channel
        self.user_profile = user_profile
        super(ChannelOptionForm, self).__init__(*args, **kwargs)
        try:
            self.channel_option = ChannelOption.objects.get(
                channel=channel, user_profile=user_profile)
        except ChannelOption.DoesNotExist:
            self.channel_option = ChannelOption(channel=channel,
                                                user_profile=user_profile,
                                                needs_approval=False)
            self.channel_option.save()
        self.initial['needs_approval'] = self.channel_option.needs_approval
        self.fields['needs_approval'].label = user_profile.user.email

    def save(self, commit=True):
        self.channel_option.needs_approval = self.cleaned_data.get(
            'needs_approval', False)
        if commit:
            self.channel_option.save()
        return self.channel_option
Ejemplo n.º 2
0
 def __init__(self, channel, user_profile, *args, **kwargs):
     """
     Set initial value for the `needs_approval` field based on the input
     Channel and UserProfile objects.
     
     """
     self.channel = channel
     self.user_profile = user_profile
     super(ChannelOptionForm, self).__init__(*args, **kwargs)
     try:
         self.channel_option = ChannelOption.objects.get(
             channel=channel, user_profile=user_profile)
     except ChannelOption.DoesNotExist:
         self.channel_option = ChannelOption(channel=channel,
                                             user_profile=user_profile,
                                             needs_approval=False)
         self.channel_option.save()
     self.initial['needs_approval'] = self.channel_option.needs_approval
     self.fields['needs_approval'].label = user_profile.user.email