Ejemplo n.º 1
0
    class Form(ClaimViewMixin.Form):
        country = forms.ChoiceField(
            choices=ALL_COUNTRIES,
            widget=SelectWidget(attrs={"searchable": True}),
            label=_("Country"),
            help_text=_("The country this phone number is used in"),
        )
        number = forms.CharField(
            max_length=18,
            min_length=1,
            label=_("Number"),
            help_text=
            _("The phone number with country code or short code you are connecting. ex: +250788123124 or 15543"
              ),
        )
        token = forms.CharField(
            label=_("API Token"),
            help_text=_(
                "The API token for your integration as provided by Zenvia"))

        def clean_number(self):
            # if this is a long number, try to normalize it
            number = self.data["number"]
            if len(number) >= 8:
                try:
                    cleaned = phonenumbers.parse(number, self.data["country"])
                    return phonenumbers.format_number(
                        cleaned, phonenumbers.PhoneNumberFormat.E164)
                except Exception:  # pragma: needs cover
                    raise forms.ValidationError(
                        _("Invalid phone number, please include the country code. ex: +250788123123"
                          ))
            else:  # pragma: needs cover
                return number
Ejemplo n.º 2
0
    def customize_form_field(self, name, field):
        attrs = field.widget.attrs if field.widget.attrs else {}

        # don't replace the widget if it is already one of us
        if isinstance(field.widget,
                      (forms.widgets.HiddenInput, CheckboxWidget, InputWidget,
                       SelectWidget, SelectMultipleWidget)):
            return field

        if isinstance(field.widget, (forms.widgets.Textarea, )):
            attrs["textarea"] = True
            field.widget = InputWidget(attrs=attrs)
        elif isinstance(
                field.widget,
            (forms.widgets.PasswordInput, )):  # pragma: needs cover
            attrs["password"] = True
            field.widget = InputWidget(attrs=attrs)
        elif isinstance(
                field.widget,
            (forms.widgets.TextInput, forms.widgets.EmailInput,
             forms.widgets.URLInput, forms.widgets.NumberInput),
        ):
            field.widget = InputWidget(attrs=attrs)
        elif isinstance(field.widget, (forms.widgets.Select, )):
            if isinstance(field, (forms.models.ModelMultipleChoiceField, )):
                field.widget = SelectMultipleWidget(
                    attrs)  # pragma: needs cover
            else:
                field.widget = SelectWidget(attrs)

            field.widget.choices = field.choices
        elif isinstance(field.widget, (forms.widgets.CheckboxInput, )):
            field.widget = CheckboxWidget(attrs)

        return field
Ejemplo n.º 3
0
 class Form(ClaimViewMixin.Form):
     country = forms.ChoiceField(
         choices=ALL_COUNTRIES,
         widget=SelectWidget(attrs={"searchable": True}),
         label=_("Country"),
         help_text=_("The country this phone number is used in"),
     )
     number = forms.CharField(
         max_length=14,
         min_length=4,
         label=_("Number"),
         help_text=("The shortcode or phone number you are connecting."),
     )
     url = ExternalURLField(
         label=_("URL"),
         help_text=
         _("The URL for the Junebug channel. ex: https://junebug.praekelt.org/jb/channels/3853bb51-d38a-4bca-b332-8a57c00f2a48/messages.json"
           ),
     )
     username = forms.CharField(
         label=_("Username"),
         help_text=_("The username to be used to authenticate to Junebug"),
         required=False)
     password = forms.CharField(
         label=_("Password"),
         help_text=_("The password to be used to authenticate to Junebug"),
         required=False)
     secret = forms.CharField(
         label=_("Secret"),
         help_text=_("The token Junebug should use to authenticate"),
         required=False)
Ejemplo n.º 4
0
class UpdateCampaignForm(forms.ModelForm):
    group = forms.ModelChoiceField(
        queryset=ContactGroup.user_groups.none(),
        empty_label=None,
        widget=SelectWidget(
            attrs={
                "placeholder": _("Select a group to base the campaign on"),
                "searchable": True
            }),
    )

    def __init__(self, *args, **kwargs):
        self.user = kwargs["user"]
        del kwargs["user"]

        super().__init__(*args, **kwargs)
        self.fields["group"].initial = self.instance.group
        self.fields["group"].queryset = ContactGroup.get_user_groups(
            self.user.get_org(), ready_only=False)

    class Meta:
        model = Campaign
        fields = ("name", "group")

        widgets = {"name": InputWidget()}
Ejemplo n.º 5
0
    class YoClaimForm(ClaimViewMixin.Form):
        country = forms.ChoiceField(
            choices=ALL_COUNTRIES,
            widget=SelectWidget(attrs={"searchable": True}),
            label=_("Country"),
            help_text=_("The country this phone number is used in"),
        )
        number = forms.CharField(
            max_length=14,
            min_length=1,
            label=_("Number"),
            help_text=_("The phone number or short code you are connecting with country code. " "ex: +250788123124"),
        )
        username = forms.CharField(label=_("Account Number"), help_text=_("Your Yo! account YBS account number"))
        password = forms.CharField(label=_("Gateway Password"), help_text=_("Your Yo! SMS Gateway password"))

        def clean_number(self):
            number = self.data["number"]

            # number is a shortcode, accept as is
            if len(number) > 0 and len(number) < 7:
                return number

            # otherwise, try to parse into an international format
            if number and number[0] != "+":
                number = "+" + number

            try:
                cleaned = phonenumbers.parse(number, None)
                return phonenumbers.format_number(cleaned, phonenumbers.PhoneNumberFormat.E164)
            except Exception:  # pragma: needs cover
                raise forms.ValidationError(
                    _("Invalid phone number, please include the country code. ex: +250788123123")
                )
Ejemplo n.º 6
0
 class TwilioMessagingServiceForm(ClaimViewMixin.Form):
     country = forms.ChoiceField(
         choices=TWILIO_SUPPORTED_COUNTRIES,
         widget=SelectWidget(attrs={"searchable": True}))
     messaging_service_sid = forms.CharField(
         label=_("Messaging Service SID"),
         help_text=_("The Twilio Messaging Service SID"))
Ejemplo n.º 7
0
 class Form(ClaimViewMixin.Form):
     shortcode = forms.CharField(max_length=6, min_length=1, help_text=_("Your short code on Africa's Talking"))
     country = forms.ChoiceField(
         choices=(
             ("BJ", ("Benin")),
             ("BW", ("Botswana")),
             ("CM", ("Cameroon")),
             ("CI", ("Côte d'Ivoire")),
             ("SZ", ("Eswatini")),
             ("ET", ("Ethiopia")),
             ("GH", ("Ghana")),
             ("KE", ("Kenya")),
             ("LS", ("Lesotho")),
             ("MW", ("Malawi")),
             ("ML", ("Mali")),
             ("NA", ("Namibia")),
             ("NG", ("Nigeria")),
             ("RW", ("Rwanda")),
             ("SN", ("Senegal")),
             ("ZA", ("South Africa")),
             ("TZ", ("Tanzania")),
             ("UG", ("Uganda")),
             ("ZM", ("Zambia")),
             ("ZW", ("Zimbabwe")),
             ("BF", ("Burkina Faso")),
         ),
         widget=SelectWidget(attrs={"searchable": True}),
     )
     is_shared = forms.BooleanField(
         initial=False, required=False, help_text=_("Whether this short code is shared with others")
     )
     username = forms.CharField(max_length=32, help_text=_("Your username on Africa's Talking"))
     api_key = forms.CharField(max_length=64, help_text=_("Your api key, should be 64 characters"))
Ejemplo n.º 8
0
class CampaignForm(forms.ModelForm):
    group = TembaChoiceField(
        queryset=ContactGroup.user_groups.none(),
        empty_label=None,
        widget=SelectWidget(attrs={
            "placeholder": _("Select group"),
            "searchable": True
        }),
        label=_("Group"),
        help_text=
        _("Only contacts in this group will be included in this campaign's events."
          ),
    )

    def __init__(self, user, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.fields["group"].queryset = ContactGroup.get_user_groups(
            user.get_org(), ready_only=False)

    class Meta:
        model = Campaign
        fields = ("name", "group")
        labels = {"name": _("Name")}
        widgets = {"name": InputWidget()}
Ejemplo n.º 9
0
    class SignalWireForm(ClaimViewMixin.Form):
        country = forms.ChoiceField(
            choices=ALL_COUNTRIES,
            widget=SelectWidget(attrs={"searchable": True}),
            label=_("Country"),
            help_text=_("The country this phone number is used in"),
            initial="US",
        )
        number = forms.CharField(
            max_length=14,
            min_length=1,
            label=_("Number"),
            help_text=_("The phone number or short code you are connecting."),
        )
        domain = forms.CharField(
            max_length=1024, label=_("Domain"), help_text=_("The domain for your account ex: rapid.signalwire.com")
        )
        project_key = forms.CharField(
            max_length=64,
            label=_("Project Key"),
            help_text=_("The key for your project ex: 990c5c10-bf8f-4156-b014-44282e60b3a1"),
        )
        api_token = forms.CharField(
            max_length=64,
            required=False,
            help_text=_("The API token to use to authenticate ex: FPd199eb93e878f8a3tw9ttna313914tnauwy"),
        )

        def clean(self):
            sid = self.cleaned_data["project_key"]
            token = self.cleaned_data["api_token"]
            domain = self.cleaned_data["domain"]
            number = self.cleaned_data["number"]
            country = self.cleaned_data["country"]

            address = number
            if len(number) > 6:
                parsed_number = phonenumbers.parse(number=number, region=country)
                address = phonenumbers.format_number(parsed_number, phonenumbers.PhoneNumberFormat.E164)

            phone_sid = ""
            try:
                response = requests.get(
                    f"https://{domain}/api/laml/2010-04-01/Accounts/{sid}/IncomingPhoneNumbers.json", auth=(sid, token)
                )
                response.raise_for_status()

                response_json = response.json()

                for phone in response_json.get("incoming_phone_numbers", []):
                    if phone.get("phone_number", "") == address:
                        phone_sid = phone.get("sid", "")
                        break
            except Exception:
                raise ValidationError("Unable to connect to SignalWire, please check your domain, key and token")

            if phone_sid == "":
                raise ValidationError(f"Unable to find phone with number {number} on your account")

            return self.cleaned_data
Ejemplo n.º 10
0
class ScheduleTriggerForm(BaseScheduleForm, forms.ModelForm):
    repeat_period = forms.ChoiceField(choices=Schedule.REPEAT_CHOICES, label="Repeat", required=False)
    repeat_days_of_week = forms.CharField(required=False)
    start = forms.ChoiceField(choices=(("stop", "Stop Schedule"), ("later", "Schedule for later")))
    start_datetime_value = forms.IntegerField(required=False)
    flow = forms.ModelChoiceField(
        Flow.objects.filter(pk__lt=0),
        label=_("Flow"),
        required=True,
        widget=SelectWidget(attrs={"placeholder": _("Select a flow")}),
        empty_label=None,
    )

    omnibox = JSONField(
        label=_("Contacts"),
        required=True,
        help_text=_("The groups and contacts the flow will be broadcast to"),
        widget=OmniboxChoice(
            attrs={"placeholder": _("Recipients, enter contacts or groups"), "groups": True, "contacts": True}
        ),
    )

    def __init__(self, user, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.user = user
        flows = Flow.get_triggerable_flows(user.get_org())

        self.fields["flow"].queryset = flows

    def clean_omnibox(self):
        return omnibox_deserialize(self.user.get_org(), self.cleaned_data["omnibox"])

    class Meta:
        model = Trigger
        fields = ("flow", "omnibox", "repeat_period", "repeat_days_of_week", "start", "start_datetime_value")
Ejemplo n.º 11
0
    class MacrokioskClaimForm(ClaimViewMixin.Form):
        country = forms.ChoiceField(
            choices=ALL_COUNTRIES,
            widget=SelectWidget(attrs={"searchable": True}),
            label=_("Country"),
            help_text=_("The country this phone number is used in"),
        )
        number = forms.CharField(
            max_length=14,
            min_length=1,
            label=_("Number"),
            help_text=_(
                "The phone number or short code you are connecting with country code. "
                "ex: +250788123124"),
        )
        sender_id = forms.CharField(
            label=_("Sender ID"),
            help_text=_(
                "The sender ID provided by Macrokiosk to use their API"))

        username = forms.CharField(
            label=_("Username"),
            help_text=_(
                "The username provided by Macrokiosk to use their API"))
        password = forms.CharField(
            label=_("Password"),
            help_text=_(
                "The password provided by Macrokiosk to use their API"))
        service_id = forms.CharField(
            label=_("Service ID"),
            help_text=_(
                "The Service ID provided by Macrokiosk to use their API"))
Ejemplo n.º 12
0
class RegisterTriggerForm(BaseTriggerForm):
    """
    Wizard form that creates keyword trigger which starts contacts in a newly created flow which adds them to a group
    """
    class AddNewGroupChoiceField(forms.ModelChoiceField):
        def clean(self, value):
            if value.startswith("[_NEW_]"):  # pragma: needs cover
                value = value[7:]

                # we must get groups for this org only
                group = ContactGroup.get_user_group_by_name(
                    self.user.get_org(), value)
                if not group:
                    group = ContactGroup.create_static(self.user.get_org(),
                                                       self.user,
                                                       name=value)
                return group

            return super().clean(value)

    keyword = forms.CharField(
        max_length=16,
        required=True,
        help_text=_("The first word of the message text"),
        widget=InputWidget())

    action_join_group = AddNewGroupChoiceField(
        ContactGroup.user_groups.filter(pk__lt=0),
        required=True,
        label=_("Group to Join"),
        help_text=_(
            "The group the contact will join when they send the above keyword"
        ),
        widget=SelectWidget(),
    )

    response = forms.CharField(
        widget=CompletionTextarea(
            attrs={"placeholder": _("Hi @contact.name!")}),
        required=False,
        label=_("Response"),
        help_text=
        _("The message to send in response after they join the group (optional)"
          ),
    )

    def __init__(self, user, *args, **kwargs):
        flows = Flow.get_triggerable_flows(user.get_org())

        super().__init__(user, flows, *args, **kwargs)

        self.fields["flow"].required = False
        group_field = self.fields["action_join_group"]
        group_field.queryset = ContactGroup.user_groups.filter(
            org=self.user.get_org(), is_active=True).order_by("name")
        group_field.user = user

    class Meta(BaseTriggerForm.Meta):
        fields = ("keyword", "action_join_group", "response", "flow")
Ejemplo n.º 13
0
class RegisterTriggerForm(BaseTriggerForm):
    """
    Wizard form that creates keyword trigger which starts contacts in a newly created flow which adds them to a group
    """

    class AddNewGroupChoiceField(TembaChoiceField):
        def clean(self, value):
            if value.startswith("[_NEW_]"):  # pragma: needs cover
                value = value[7:]

                # we must get groups for this org only
                group = ContactGroup.get_user_group_by_name(self.user.get_org(), value)
                if not group:
                    group = ContactGroup.create_static(self.user.get_org(), self.user, name=value)
                return group

            return super().clean(value)

    keyword = forms.CharField(
        max_length=16,
        required=True,
        label=_("Join Keyword"),
        help_text=_("The first word of the message"),
        widget=InputWidget(),
    )

    action_join_group = AddNewGroupChoiceField(
        ContactGroup.user_groups.none(),
        required=True,
        label=_("Group to Join"),
        help_text=_("The group the contact will join when they send the above keyword"),
        widget=SelectWidget(),
    )

    response = forms.CharField(
        widget=CompletionTextarea(attrs={"placeholder": _("Hi @contact.name!")}),
        required=False,
        label=ngettext_lazy("Response", "Responses", 1),
        help_text=_("The message to send in response after they join the group (optional)"),
    )

    def __init__(self, user, *args, **kwargs):
        super().__init__(user, Trigger.TYPE_KEYWORD, *args, **kwargs)

        # on this form flow becomes the flow to be triggered from the generated flow and is optional
        self.fields["flow"].required = False

        self.fields["action_join_group"].queryset = ContactGroup.user_groups.filter(
            org=self.org, is_active=True
        ).order_by("name")
        self.fields["action_join_group"].user = user

    def get_conflicts_kwargs(self, cleaned_data):
        kwargs = super().get_conflicts_kwargs(cleaned_data)
        kwargs["keyword"] = cleaned_data.get("keyword") or ""
        return kwargs

    class Meta(BaseTriggerForm.Meta):
        fields = ("keyword", "action_join_group", "response") + BaseTriggerForm.Meta.fields
Ejemplo n.º 14
0
    class Form(ClaimViewMixin.Form):
        country = forms.ChoiceField(choices=ALL_COUNTRIES, widget=SelectWidget(attrs={"searchable": True}))
        phone_number = forms.CharField(help_text=_("The phone number being added"))

        def clean_phone_number(self):
            phone = self.cleaned_data["phone_number"]
            phone = phonenumbers.parse(phone, self.cleaned_data["country"])
            return phonenumbers.format_number(phone, phonenumbers.PhoneNumberFormat.E164)
Ejemplo n.º 15
0
class ExportForm(Form):
    LABEL_CHOICES = ((0, _("Just this label")), (1, _("All messages")))

    SYSTEM_LABEL_CHOICES = ((0, _("Just this folder")), (1, _("All messages")))

    export_all = forms.ChoiceField(
        choices=(), label=_("Selection"), initial=0, widget=SelectWidget(attrs={"widget_only": True})
    )

    start_date = forms.DateField(
        required=False,
        help_text=_("Leave blank for the oldest message"),
        widget=InputWidget(attrs={"datepicker": True, "hide_label": True, "placeholder": _("Start Date")}),
    )

    end_date = forms.DateField(
        required=False,
        help_text=_("Leave blank for the latest message"),
        widget=InputWidget(attrs={"datepicker": True, "hide_label": True, "placeholder": _("End Date")}),
    )

    groups = forms.ModelMultipleChoiceField(
        queryset=ContactGroup.user_groups.none(),
        required=False,
        label=_("Groups"),
        widget=SelectMultipleWidget(
            attrs={"widget_only": True, "placeholder": _("Optional: Choose groups to show in your export")}
        ),
    )

    def __init__(self, user, label, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.user = user

        self.fields["export_all"].choices = self.LABEL_CHOICES if label else self.SYSTEM_LABEL_CHOICES

        self.fields["groups"].queryset = ContactGroup.user_groups.filter(org=self.user.get_org(), is_active=True)
        self.fields["groups"].help_text = _(
            "Export only messages from these contact groups. " "(Leave blank to export all messages)."
        )

    def clean(self):
        cleaned_data = super().clean()
        start_date = cleaned_data.get("start_date")
        end_date = cleaned_data.get("end_date")

        if start_date and start_date > date.today():  # pragma: needs cover
            raise forms.ValidationError(_("Start date can't be in the future."))

        if end_date and start_date and end_date < start_date:  # pragma: needs cover
            raise forms.ValidationError(_("End date can't be before start date"))

        return cleaned_data
Ejemplo n.º 16
0
class ScheduleFormMixin(forms.Form):
    start_datetime = forms.DateTimeField(
        label=_("Start Time"),
        widget=InputWidget(attrs={
            "datetimepicker": True,
            "placeholder": _("Select a date and time")
        }),
    )
    repeat_period = forms.ChoiceField(choices=Schedule.REPEAT_CHOICES,
                                      label=_("Repeat"),
                                      widget=SelectWidget())
    repeat_days_of_week = forms.MultipleChoiceField(
        choices=Schedule.REPEAT_DAYS_CHOICES,
        label=_("Repeat On Days"),
        help_text=_("The days of the week to repeat on for weekly schedules"),
        required=False,
        widget=SelectMultipleWidget(attrs=({
            "placeholder": _("Select days")
        })),
    )

    def set_user(self, user):
        """
        Because this mixin is mixed with other forms it can't have a __init__ constructor that takes non standard Django
        forms args and kwargs, so we have to customize based on user after the form has been created.
        """
        tz = user.get_org().timezone
        self.fields["start_datetime"].help_text = _(
            "First time this should happen in the %s timezone.") % tz

    def clean_repeat_days_of_week(self):
        value = self.cleaned_data["repeat_days_of_week"]

        # sort by Monday to Sunday
        value = sorted(value,
                       key=lambda c: Schedule.DAYS_OF_WEEK_OFFSET.index(c))

        return "".join(value)

    def clean(self):
        cleaned_data = super().clean()

        if self.is_valid():
            if cleaned_data[
                    "repeat_period"] == Schedule.REPEAT_WEEKLY and not cleaned_data.get(
                        "repeat_days_of_week"):
                self.add_error("repeat_days_of_week",
                               _("Must specify at least one day of the week."))

        return cleaned_data

    class Meta:
        fields = ("start_datetime", "repeat_period", "repeat_days_of_week")
Ejemplo n.º 17
0
    class Form(ClaimViewMixin.Form):
        country = forms.ChoiceField(choices=COUNTRY_CHOICES, widget=SelectWidget(attrs={"searchable": True}))
        phone_number = forms.CharField(help_text=_("The phone number being added"))

        def clean_phone_number(self):
            if not self.cleaned_data.get("country", None):  # pragma: needs cover
                raise ValidationError(_("That number is not currently supported."))

            phone = self.cleaned_data["phone_number"]
            phone = phonenumbers.parse(phone, self.cleaned_data["country"])

            return phonenumbers.format_number(phone, phonenumbers.PhoneNumberFormat.E164)
Ejemplo n.º 18
0
    class Form(ClaimViewMixin.Form):
        country = forms.ChoiceField(
            choices=ALL_COUNTRIES,
            widget=SelectWidget(attrs={"searchable": True}),
            label=_("Country"),
            help_text=_("The country this phone number is used in"),
        )
        number = forms.CharField(
            max_length=18,
            min_length=1,
            label=_("Number"),
            help_text=
            _("The phone number with country code or short code you are connecting. ex: +250788123124 or 15543"
              ),
        )
        token = forms.CharField(
            label=_("API Token"),
            help_text=_(
                "The API token for your integration as provided by Zenvia"))

        def clean_number(self):
            # if this is a long number, try to normalize it
            number = self.data["number"]
            if len(number) >= 8:
                try:
                    cleaned = phonenumbers.parse(number, self.data["country"])
                    return phonenumbers.format_number(
                        cleaned, phonenumbers.PhoneNumberFormat.E164)
                except Exception:  # pragma: needs cover
                    raise forms.ValidationError(
                        _("Invalid phone number, please include the country code. ex: +250788123123"
                          ))
            else:  # pragma: needs cover
                return number

        def clean_token(self):
            token = self.data["token"]
            headers = {
                "X-API-TOKEN": token,
                "Content-Type": "application/json",
            }

            conf_url = "https://api.zenvia.com/v2/subscriptions"

            resp = requests.get(conf_url, headers=headers)

            if resp.status_code != 200:
                raise forms.ValidationError(
                    _("Invalid token. Please check your Zenvia account settings."
                      ))

            return token
Ejemplo n.º 19
0
 class KannelClaimForm(ClaimViewMixin.Form):
     number = forms.CharField(
         max_length=14,
         min_length=1,
         label=_("Number"),
         help_text=_("The phone number or short code you are connecting"),
     )
     country = forms.ChoiceField(
         choices=ALL_COUNTRIES,
         widget=SelectWidget(attrs={"searchable": True}),
         label=_("Country"),
         help_text=_("The country this phone number is used in"),
     )
     url = ExternalURLField(
         max_length=1024,
         label=_("Send URL"),
         help_text=_(
             "The publicly accessible URL for your Kannel instance for sending. "
             "ex: https://kannel.macklemore.co/cgi-bin/sendsms"),
     )
     username = forms.CharField(
         max_length=64,
         required=False,
         help_text=_(
             "The username to use to authenticate to Kannel, if left blank we "
             "will generate one for you"),
     )
     password = forms.CharField(
         max_length=64,
         required=False,
         help_text=_(
             "The password to use to authenticate to Kannel, if left blank we "
             "will generate one for you"),
     )
     encoding = forms.ChoiceField(
         choices=Channel.ENCODING_CHOICES,
         label=_("Encoding"),
         help_text=_("What encoding to use for outgoing messages"),
     )
     verify_ssl = forms.BooleanField(
         initial=True,
         required=False,
         label=_("Verify SSL"),
         help_text=_("Whether to verify the SSL connection (recommended)"),
     )
     use_national = forms.BooleanField(
         initial=False,
         required=False,
         label=_("Use National Numbers"),
         help_text=_("Use only the national number (no country code) when "
                     "sending (not recommended)"),
     )
Ejemplo n.º 20
0
 class TwimlApiClaimForm(ClaimViewMixin.Form):
     ROLES = (
         (Channel.ROLE_SEND + Channel.ROLE_RECEIVE, _("Messaging")),
         (Channel.ROLE_CALL + Channel.ROLE_ANSWER, _("Voice")),
         (Channel.ROLE_SEND + Channel.ROLE_RECEIVE + Channel.ROLE_CALL +
          Channel.ROLE_ANSWER, _("Both")),
     )
     country = forms.ChoiceField(
         choices=ALL_COUNTRIES,
         widget=SelectWidget(attrs={"searchable": True}),
         label=_("Country"),
         help_text=_("The country this phone number is used in"),
     )
     number = forms.CharField(
         max_length=14,
         min_length=1,
         label=_("Number"),
         help_text=
         _("The phone number without country code or short code you are connecting."
           ),
     )
     url = ExternalURLField(
         max_length=1024,
         label=_("TwiML REST API Host"),
         help_text=
         _("The publicly accessible URL for your TwiML REST API instance ex: https://api.twilio.com"
           ),
     )
     role = forms.ChoiceField(
         choices=ROLES,
         label=_("Role"),
         help_text=_("Choose the role that this channel supports"))
     account_sid = forms.CharField(
         max_length=64,
         required=False,
         help_text=_(
             "The Account SID to use to authenticate to the TwiML REST API"
         ),
         widget=forms.TextInput(attrs={"autocomplete": "off"}),
     )
     account_token = forms.CharField(
         max_length=64,
         required=False,
         help_text=_(
             "The Account Token to use to authenticate to the TwiML REST API"
         ),
         widget=forms.TextInput(attrs={"autocomplete": "off"}),
     )
     max_concurrent_events = forms.IntegerField(
         min_value=1,
         required=False,
         help_text=_("Max active calls at the same time"))
Ejemplo n.º 21
0
 class ShaqodoonForm(ClaimViewMixin.Form):
     country = forms.ChoiceField(
         choices=ALL_COUNTRIES,
         widget=SelectWidget(attrs={"searchable": True}),
         label=_("Country"),
         help_text=_("The country this phone number is used in"),
     )
     number = forms.CharField(
         max_length=14, min_length=1, label=_("Number"), help_text=_("The short code you are connecting with.")
     )
     url = ExternalURLField(label=_("URL"), help_text=_("The url provided to deliver messages"))
     username = forms.CharField(label=_("Username"), help_text=_("The username provided to use their API"))
     password = forms.CharField(label=_("Password"), help_text=_("The password provided to use their API"))
Ejemplo n.º 22
0
    class Form(ClaimViewMixin.Form):
        country = forms.ChoiceField(
            choices=ALL_COUNTRIES,
            widget=SelectWidget(attrs={"searchable": True}),
            label=_("Country"),
            help_text=_("The country this channel will be used in"),
        )

        number = forms.CharField(
            max_length=14, min_length=4, label=_("Number"), help_text=_("The number you are connecting.")
        )
        username = forms.CharField(label=_("Username"), help_text=_("The username for your Bongo Live account"))
        password = forms.CharField(label=_("Password"), help_text=_("The password for your Bongo Live account"))
Ejemplo n.º 23
0
        class Form(NoteForm):
            assignee = forms.ModelChoiceField(
                queryset=User.objects.none(),
                widget=SelectWidget(attrs={"searchable": True, "widget_only": True}),
                required=False,
                empty_label=_("Unassigned"),
            )

            def __init__(self, org, *args, **kwargs):
                super().__init__(*args, **kwargs)

                self.org = org
                self.fields["assignee"].queryset = Ticket.get_allowed_assignees(self.org).order_by("email")
                self.fields["note"].required = False
Ejemplo n.º 24
0
 class Form(ClaimViewMixin.Form):
     country = forms.ChoiceField(
         choices=ALL_COUNTRIES,
         widget=SelectWidget(attrs={"searchable": True}),
         label=_("Country"),
         help_text=_("The country this channel will be used in"),
     )
     shortcode = forms.CharField(label=_("Short Code"), help_text=_("The short code you are connecting"))
     service_id = forms.CharField(label=_("Service ID"), help_text=_("The service ID as provided by ArabiaCell"))
     charging_level = forms.ChoiceField(
         choices=(("0", _("Free")), ("1", _("Billed"))), help_text=_("The charging level for your account")
     )
     username = forms.CharField(label=_("Username"), help_text=_("The username for your API account"))
     password = forms.CharField(label=_("Password"), help_text=_("The password for your API account"))
Ejemplo n.º 25
0
    class Form(ClaimViewMixin.Form):
        country = forms.ChoiceField(
            choices=ALL_COUNTRIES,
            widget=SelectWidget(attrs={"searchable": True}),
            label=_("Country"),
            help_text=_("The country this channel will be used in"),
        )

        number = forms.CharField(
            max_length=14, min_length=4, label=_("Number"), help_text=_("The number you are connecting.")
        )
        username = forms.CharField(label=_("Username"), help_text=_("The username for your Movile/Wavy account"))
        token = forms.CharField(
            label=_("Authentication Token"), help_text=_("The Authentication Token for your Movile/Wavy account")
        )
Ejemplo n.º 26
0
 class Form(ClaimViewMixin.Form):
     country = forms.ChoiceField(
         choices=ALL_COUNTRIES,
         widget=SelectWidget(attrs={"searchable": True}),
         label=_("Country"),
         help_text=_("The country this channel will be used in"),
     )
     service_id = forms.CharField(
         label=_("Service ID"),
         help_text=_("The service ID as provided by Mtarget"))
     username = forms.CharField(
         label=_("Username"),
         help_text=_("The username for your API account"))
     password = forms.CharField(
         label=_("Password"),
         help_text=_("The password for your API account"))
Ejemplo n.º 27
0
    class VerboiceClaimForm(ClaimViewMixin.Form):
        country = forms.ChoiceField(
            choices=ALL_COUNTRIES,
            widget=SelectWidget(attrs={"searchable": True}),
            label=_("Country"),
            help_text=_("The country this phone number is used in"),
        )
        number = forms.CharField(
            max_length=14,
            min_length=1,
            label=_("Number"),
            help_text=_(
                "The phone number with country code or short code you are connecting. "
                "ex: +250788123124 or 15543"),
        )
        username = forms.CharField(
            label=_("Username"),
            help_text=_(
                "The username provided by the provider to use their API"))
        password = forms.CharField(
            label=_("Password"),
            help_text=_(
                "The password provided by the provider to use their API"))
        channel = forms.CharField(
            label=_("Channel Name"),
            help_text=_(
                "The Verboice channel that will be handling your calls"))

        def clean_number(self):
            number = self.data["number"]

            # number is a shortcode, accept as is
            if len(number) > 0 and len(number) < 7:
                return number

            # otherwise, try to parse into an international format
            if number and number[0] != "+":
                number = "+" + number

            try:
                cleaned = phonenumbers.parse(number, None)
                return phonenumbers.format_number(
                    cleaned, phonenumbers.PhoneNumberFormat.E164)
            except Exception:  # pragma: needs cover
                raise forms.ValidationError(
                    _("Invalid phone number, please include the country code. ex: +250788123123"
                      ))
Ejemplo n.º 28
0
class LabelForm(BaseLabelForm):
    folder = forms.ModelChoiceField(
        Label.folder_objects.none(),
        required=False,
        label=_("Folder"),
        widget=SelectWidget(attrs={"placeholder": _("Optional: Parent Folder"), "widget_only": True}),
    )

    messages = forms.CharField(required=False, widget=forms.HiddenInput)

    def __init__(self, *args, **kwargs):
        self.org = kwargs.pop("org")
        self.existing = kwargs.pop("object", None)

        super().__init__(*args, **kwargs)

        self.fields["folder"].queryset = Label.folder_objects.filter(org=self.org, is_active=True)
Ejemplo n.º 29
0
    class JasminForm(ClaimViewMixin.Form):
        country = forms.ChoiceField(
            choices=ALL_COUNTRIES,
            widget=SelectWidget(attrs={"searchable": True}),
            label=_("Country"),
            help_text=_("The country this phone number is used in"),
        )
        number = forms.CharField(
            max_length=14,
            min_length=3,
            label=_("Number"),
            help_text=_("The short code or phone number you are connecting."),
        )
        url = ExternalURLField(
            widget=forms.URLInput(
                attrs={"placeholder": _("Ex: https://jasmin.gateway.io/send")
                       }),
            label=_("URL"),
            help_text=_("The URL for the Jasmin server send path"),
        )
        username = forms.CharField(
            label=_("Username"),
            help_text=_("The username to be used to authenticate to Jasmin"))
        password = forms.CharField(
            label=_("Password"),
            help_text=_("The password to be used to authenticate to Jasmin"))

        def clean_number(self):
            number = self.data["number"]

            # number is a shortcode, accept as is
            if len(number) > 0 and len(number) < 7:
                return number

            # otherwise, try to parse into an international format
            if number and number[0] != "+":
                number = "+" + number

            try:
                cleaned = phonenumbers.parse(number, None)
                return phonenumbers.format_number(
                    cleaned, phonenumbers.PhoneNumberFormat.E164)
            except Exception:  # pragma: needs cover
                raise forms.ValidationError(
                    _("Invalid phone number, please include the country code. ex: +250788123123"
                      ))
Ejemplo n.º 30
0
 class ChikkaForm(ClaimViewMixin.Form):
     country = forms.ChoiceField(
         choices=ALL_COUNTRIES,
         widget=SelectWidget(attrs={"searchable": True}),
         label=_("Country"),
         help_text=_("The country this phone number is used in"),
     )
     number = forms.CharField(
         max_length=14,
         min_length=4,
         label=_("Number"),
         help_text=_("The short code you are connecting."))
     username = forms.CharField(
         label=_("Client Id"),
         help_text=_(
             "The Client Id found on your Chikka API credentials page"))
     password = forms.CharField(
         label=_("Secret Key"),
         help_text=_(
             "The Secret Key found on your Chikka API credentials page"))