def pre_save(self, obj): obj = super(OrgExtCRUDL.Edit, self).pre_save(obj) obj.set_banner_text(self.form.cleaned_data["banner_text"]) field_ids = self.form.cleaned_data["contact_fields"] Field.get_all(self.request.org).filter(pk__in=field_ids).update( is_visible=True) Field.get_all(self.request.org).exclude(pk__in=field_ids).update( is_visible=False) group_ids = self.form.cleaned_data["suspend_groups"] Group.get_all(self.request.org).filter(pk__in=group_ids).update( suspend_from=True) Group.get_all(self.request.org).exclude(pk__in=group_ids).update( suspend_from=False) followup_flow_uuid = self.form.cleaned_data["followup_flow"] if followup_flow_uuid: for flow in obj.get_backend().fetch_flows(obj): if flow.uuid == followup_flow_uuid: obj.set_followup_flow(flow) break else: obj.set_followup_flow(None) return obj
def pre_save(self, obj): obj = super(OrgExtCRUDL.Edit, self).pre_save(obj) obj.set_banner_text(self.form.cleaned_data['banner_text']) field_ids = self.form.cleaned_data['contact_fields'] Field.get_all(self.request.org).filter(pk__in=field_ids).update(is_visible=True) Field.get_all(self.request.org).exclude(pk__in=field_ids).update(is_visible=False) group_ids = self.form.cleaned_data['suspend_groups'] Group.get_all(self.request.org).filter(pk__in=group_ids).update(suspend_from=True) Group.get_all(self.request.org).exclude(pk__in=group_ids).update(suspend_from=False) return obj
def __init__(self, *args, **kwargs): org = kwargs.pop("org") super(OrgEditForm, self).__init__(*args, **kwargs) self.fields["banner_text"].initial = org.get_banner_text() field_choices = [] for field in Field.objects.filter(org=org, is_active=True).order_by("label"): field_choices.append((field.pk, "%s (%s)" % (field.label, field.key))) self.fields["contact_fields"].choices = field_choices self.fields["contact_fields"].initial = [f.pk for f in Field.get_all(org, visible=True)] group_choices = [] for group in Group.get_all(org, dynamic=False).order_by("name"): group_choices.append((group.pk, group.name)) self.fields["suspend_groups"].choices = group_choices self.fields["suspend_groups"].initial = [g.pk for g in Group.get_suspend_from(org)] flow_choices = [("", "----")] for flow in org.get_backend().fetch_flows(org): flow_choices.append((flow.uuid, flow.name)) flow_initial = org.get_followup_flow() self.fields["followup_flow"].choices = flow_choices if flow_initial: self.fields["followup_flow"].initial = flow_initial.uuid
def __init__(self, *args, **kwargs): org = kwargs.pop('org') super(OrgEditForm, self).__init__(*args, **kwargs) self.fields['banner_text'].initial = org.get_banner_text() field_choices = [] for field in Field.objects.filter(org=org, is_active=True).order_by('label'): field_choices.append( (field.pk, "%s (%s)" % (field.label, field.key))) self.fields['contact_fields'].choices = field_choices self.fields['contact_fields'].initial = [ f.pk for f in Field.get_all(org, visible=True) ] group_choices = [] for group in Group.get_all(org, dynamic=False).order_by('name'): group_choices.append((group.pk, group.name)) self.fields['suspend_groups'].choices = group_choices self.fields['suspend_groups'].initial = [ g.pk for g in Group.get_suspend_from(org) ]
def __init__(self, *args, **kwargs): org = kwargs.pop('org') super(OrgExtCRUDL.Edit.OrgExtForm, self).__init__(*args, **kwargs) self.fields['banner_text'].initial = org.get_banner_text() field_choices = [] for field in Field.objects.filter(org=org, is_active=True).order_by('label'): field_choices.append((field.pk, "%s (%s)" % (field.label, field.key))) self.fields['contact_fields'].choices = field_choices self.fields['contact_fields'].initial = [f.pk for f in Field.get_all(org, visible=True)] group_choices = [] for group in Group.get_all(org).order_by('name'): group_choices.append((group.pk, group.name)) self.fields['suspend_groups'].choices = group_choices self.fields['suspend_groups'].initial = [g.pk for g in Group.get_all(org).filter(suspend_from=True)]
def __init__(self, *args, **kwargs): org = kwargs.pop('org') is_create = kwargs.pop('is_create') super(LabelForm, self).__init__(*args, **kwargs) # don't let users change names of existing labels if not is_create: self.fields['name'].widget = forms.TextInput(attrs={'readonly': 'readonly'}) self.fields['groups'].queryset = Group.get_all(org).order_by('name') self.fields['field_test'] = FieldTestField( org=org, label=_("Field criteria"), required=False, help_text=_("Match messages where contact field value is equal to any of these values (comma separated)") )
def __init__(self, *args, **kwargs): org = kwargs.pop('org') is_create = kwargs.pop('is_create') super(LabelForm, self).__init__(*args, **kwargs) # don't let users change names of existing labels if not is_create: self.fields['name'].widget = forms.TextInput( attrs={'readonly': 'readonly'}) self.fields['groups'].queryset = Group.get_all(org).order_by('name') self.fields['field_test'] = FieldTestField( org=org, label=_("Field criteria"), required=False, help_text= _("Match messages where contact field value is equal to any of these values (comma separated)" ))
def get_context_data(self, **kwargs): context = super(BaseHomeView, self).get_context_data(**kwargs) org = self.request.org user = self.request.user partner = user.get_partner(org) labels = Label.get_all(org, user).order_by('name') groups = Group.get_all(org, visible=True).order_by('name') # angular app requires context data in JSON format context['context_data_json'] = json_encode({ 'user': {'id': user.pk, 'partner': partner.as_json() if partner else None}, 'labels': [l.as_json() for l in labels], 'groups': [g.as_json() for g in groups], }) context['banner_text'] = org.get_banner_text() context['folder'] = self.folder.name context['folder_icon'] = self.folder_icon context['open_case_count'] = Case.get_open(org, user).count() context['closed_case_count'] = Case.get_closed(org, user).count() return context
def get_context_data(self, **kwargs): context = super(BaseInboxView, self).get_context_data(**kwargs) org = self.request.org user = self.request.user partner = user.get_partner(org) labels = list(Label.get_all(org, user).order_by('name')) Label.bulk_cache_initialize(labels) groups = Group.get_all(org, visible=True).order_by('name') fields = Field.get_all(org, visible=True).order_by('label') # angular app requires context data in JSON format context['context_data_json'] = json_encode({ 'user': { 'id': user.pk, 'partner': partner.as_json() if partner else None }, 'labels': [l.as_json() for l in labels], 'groups': [g.as_json() for g in groups], 'fields': [f.as_json() for f in fields], }) context['banner_text'] = org.get_banner_text() context['folder'] = self.folder.name context['folder_icon'] = self.folder_icon context['open_case_count'] = Case.get_open(org, user).count() context['closed_case_count'] = Case.get_closed(org, user).count() context['allow_case_without_message'] = getattr( settings, 'SITE_ALLOW_CASE_WITHOUT_MESSAGE', False) context['user_must_reply_with_faq'] = org and not user.is_anonymous( ) and user.must_use_faq() context['site_contact_display'] = getattr(settings, 'SITE_CONTACT_DISPLAY', "name") return context