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

    **Attributes**:

        * ``form`` - SMSCampaignForm
        * ``template`` - frontend/sms_campaign/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)
    # Add sms campaign
    if request.method == 'POST':
        form = SMSCampaignForm(request.user, request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.user = User.objects.get(username=request.user)
            obj.save()
            form.save_m2m()

            request.session["msg"] = _('"%(name)s" is added.') %\
                {'name': request.POST['name']}
            return HttpResponseRedirect(redirect_url_to_smscampaign_list)

    template = 'frontend/sms_campaign/change.html'
    data = {
        'form': form,
        'action': 'add',
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    return render_to_response(
        template, data, context_instance=RequestContext(request))
Ejemplo n.º 2
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)