def __init__(self, *args, **kwargs): if hasattr(self, 'user'): kwargs.update({'user': self.user}) super(JobForm, self).__init__(*args, **kwargs) if self.instance.pk: self.fields['description'].widget.mce_attrs['app_instance_id'] = self.instance.pk #self.fields['pricing'].initial = JobPricing.objects.filter(duration=self.instance.requested_duration)[0] if self.user.profile.is_superuser: self.fields['status_detail'].choices = STATUS_DETAIL_CHOICES else: self.fields['description'].widget.mce_attrs['app_instance_id'] = 0 self.fields['group'].initial = Group.objects.get_initial_group_id() self.fields['pricing'].choices = pricing_choices(self.user) if 'payment_method' in self.fields: self.fields['payment_method'].widget = forms.RadioSelect(choices=get_payment_method_choices(self.user)) # adjust fields depending on user status fields_to_pop = [] if not self.user.is_authenticated(): fields_to_pop += [ 'entity', 'allow_anonymous_view', 'user_perms', 'group_perms', 'member_perms', 'post_dt', 'activation_dt', 'expiration_dt', 'syndicate', 'status', 'status_detail' ] else: fields_to_pop += [ 'captcha' ] if not self.user.profile.is_superuser: fields_to_pop += [ 'slug', 'entity', 'group', 'allow_anonymous_view', 'user_perms', 'member_perms', 'group_perms', 'post_dt', 'activation_dt', 'expiration_dt', 'syndicate', 'status', 'status_detail' ] for f in list(set(fields_to_pop)): if f in self.fields: self.fields.pop(f)
def __init__(self, *args, **kwargs): if hasattr(self, "user"): kwargs.update({"user": self.user}) super(JobForm, self).__init__(*args, **kwargs) if self.instance.pk: self.fields["description"].widget.mce_attrs["app_instance_id"] = self.instance.pk # self.fields['pricing'].initial = JobPricing.objects.filter(duration=self.instance.requested_duration)[0] if self.user.profile.is_superuser: self.fields["status_detail"].choices = STATUS_DETAIL_CHOICES else: self.fields["description"].widget.mce_attrs["app_instance_id"] = 0 self.fields["group"].initial = Group.objects.get_initial_group_id() self.fields["pricing"].choices = pricing_choices(self.user) if "payment_method" in self.fields: self.fields["payment_method"].widget = forms.RadioSelect(choices=get_payment_method_choices(self.user)) # adjust fields depending on user status fields_to_pop = [] if not self.user.is_authenticated(): fields_to_pop += [ "entity", "allow_anonymous_view", "user_perms", "group_perms", "member_perms", "post_dt", "activation_dt", "expiration_dt", "syndicate", "status_detail", ] else: fields_to_pop += ["captcha"] if not self.user.profile.is_superuser: fields_to_pop += [ "slug", "entity", "group", "allow_anonymous_view", "user_perms", "member_perms", "group_perms", "post_dt", "activation_dt", "expiration_dt", "syndicate", "status_detail", ] for f in list(set(fields_to_pop)): if f in self.fields: self.fields.pop(f)