def validate(self, attrs):
        """
        Validate sms campaign form
        """
        request = self.context['request']

        if request.method == 'POST':
            name_count = SMSCampaign.objects.filter(name=attrs.get('name'),
                                                    user=request.user).count()
            if name_count != 0:
                raise serializers.ValidationError("The SMS Campaign name duplicated!")

        if not user_dialer_setting(request.user):
            raise serializers.ValidationError("Your settings are not configured properly, Please contact the administrator.")

        if check_sms_dialer_setting(request, check_for="smscampaign"):
            raise serializers.ValidationError("Too many sms campaigns. Max allowed %s"
                                              % dialer_setting_limit(request, limit_for="smscampaign"))

        frequency = attrs.get('frequency')
        if frequency:
            if check_sms_dialer_setting(request, check_for="smsfrequency", field_value=int(frequency)):
                raise serializers.ValidationError("Frequency limit of %s exceeded."
                                                  % dialer_setting_limit(request, limit_for="smsfrequency"))

        maxretry = attrs.get('maxretry')
        if maxretry:
            if check_sms_dialer_setting(request, check_for="smsretry", field_value=int(maxretry)):
                raise serializers.ValidationError("Retries limit of %s exceeded."
                                                  % dialer_setting_limit(request, limit_for="smsretry"))

        return attrs
Ejemplo n.º 2
0
def sms_campaign_add(request):
    """Add a new sms campaign for the logged in user

    **Attributes**:

        * ``form`` - SMSCampaignForm
        * ``template`` - mod_sms/change.html

    **Logic Description**:

        * Before adding a sms campaign, check dialer setting limit if
          applicable to the user.
        * Add the new sms campaign which will belong to the logged in user
          via SMSCampaignForm & get redirected to sms campaign list
    """
    # If dialer setting is not attached with user, redirect to sms campaign list
    if not user_dialer_setting(request.user):
        request.session['error_msg'] = \
            _("in order to add a sms campaign, you need to have your \
               settings configured properly, please contact the admin."                                                                       )
        return HttpResponseRedirect(redirect_url_to_smscampaign_list)

    # Check dialer setting limit
    if request.user and request.method != 'POST':
        # check Max Number of running campaign
        if check_sms_dialer_setting(request, check_for="smscampaign"):
            msg = _("you have too many sms campaigns. Max allowed %(limit)s")\
                % {'limit': dialer_setting_limit(request, limit_for="smscampaign")}
            request.session['msg'] = msg

            # sms campaign limit reached
            frontend_send_notification(
                request, SMS_NOTIFICATION_NAME.sms_campaign_limit_reached)
            return HttpResponseRedirect(redirect_url_to_smscampaign_list)

    form = SMSCampaignForm(request.user, request.POST or None)
    # Add sms campaign
    if form.is_valid():
        obj = form.save(commit=False)
        obj.user = User.objects.get(username=request.user)
        obj.stoppeddate = obj.expirationdate
        obj.save()
        form.save_m2m()
        request.session["msg"] = _('"%(name)s" is added.') % {
            'name': request.POST['name']
        }
        return HttpResponseRedirect(redirect_url_to_smscampaign_list)

    data = {
        'form': form,
        'action': 'add',
    }
    return render_to_response('mod_sms/change.html',
                              data,
                              context_instance=RequestContext(request))
Ejemplo n.º 3
0
def sms_campaign_add(request):
    """Add a new sms campaign for the logged in user

    **Attributes**:

        * ``form`` - SMSCampaignForm
        * ``template`` - mod_sms/change.html

    **Logic Description**:

        * Before adding a sms campaign, check dialer setting limit if
          applicable to the user.
        * Add the new sms campaign which will belong to the logged in user
          via SMSCampaignForm & get redirected to sms campaign list
    """
    # If dialer setting is not attached with user, redirect to sms campaign list
    if not user_dialer_setting(request.user):
        request.session['error_msg'] = \
            _("in order to add a sms campaign, you need to have your \
               settings configured properly, please contact the admin.")
        return HttpResponseRedirect(redirect_url_to_smscampaign_list)

    # Check dialer setting limit
    if request.user and request.method != 'POST':
        # check Max Number of running campaign
        if check_sms_dialer_setting(request, check_for="smscampaign"):
            msg = _("you have too many sms campaigns. Max allowed %(limit)s")\
                % {'limit': dialer_setting_limit(request, limit_for="smscampaign")}
            request.session['msg'] = msg

            # sms campaign limit reached
            frontend_send_notification(request, SMS_NOTIFICATION_NAME.sms_campaign_limit_reached)
            return HttpResponseRedirect(redirect_url_to_smscampaign_list)

    form = SMSCampaignForm(request.user, request.POST or None)
    # Add sms campaign
    if form.is_valid():
        obj = form.save(commit=False)
        obj.user = User.objects.get(username=request.user)
        obj.stoppeddate = obj.expirationdate
        obj.save()
        form.save_m2m()
        request.session["msg"] = _('"%(name)s" is added.') % {'name': request.POST['name']}
        return HttpResponseRedirect(redirect_url_to_smscampaign_list)

    data = {
        'form': form,
        'action': 'add',
    }
    return render_to_response('mod_sms/change.html', data, context_instance=RequestContext(request))
Ejemplo n.º 4
0
    def add_view(self, request, extra_context=None):
        """
        Override django add_view method for checking the dialer setting limit

        **Logic Description**:

            * Before adding sms campaign, check dialer setting limit if applicable
              to the user, if matched then the user will be redirected to
              the sms campaign list
        """
        # Check dialer setting limit
        # check Max Number of running sms campaigns
        if check_sms_dialer_setting(request, check_for="smscampaign"):
            msg = _("you have too many sms campaigns. Max allowed %(limit)s") \
                % {'limit': dialer_setting_limit(request, limit_for="smscampaign")}
            messages.error(request, msg)

            # campaign limit reached
            #common_send_notification(request, '3')
            return HttpResponseRedirect(reverse("admin:sms_campaign_campaign_changelist"))
        ctx = {}
        return super(SMSCampaignAdmin, self).add_view(request, extra_context=ctx)
Ejemplo n.º 5
0
    def add_view(self, request, extra_context=None):
        """
        Override django add_view method for checking the dialer setting limit

        **Logic Description**:

            * Before adding sms campaign, check dialer setting limit if applicable
              to the user, if matched then the user will be redirected to
              the sms campaign list
        """
        # Check dialer setting limit
        # check Max Number of running sms campaigns
        if check_sms_dialer_setting(request, check_for="smscampaign"):
            msg = _("you have too many sms campaigns. Max allowed %(limit)s") \
                % {'limit': dialer_setting_limit(request, limit_for="smscampaign")}
            messages.error(request, msg)

            # campaign limit reached
            #common_send_notification(request, '3')
            return HttpResponseRedirect(
                reverse("admin:sms_campaign_campaign_changelist"))
        ctx = {}
        return super(SMSCampaignAdmin, self).add_view(request,
                                                      extra_context=ctx)