def handle(self, *args, **options):
        """Note that subscriber created this way are only for devel purposes"""

        for newinst in args:
            print newinst
            res = newinst.split('|')
            myphonenumber = res[0]
            myphonebook_id = res[1]

            try:
                obj_phonebook = Phonebook.objects.get(id=myphonebook_id)
            except:
                print _('Can\'t find this Phonebook : %(id)s' % {'id': myphonebook_id})
                return False

            try:
                new_contact = Contact.objects.create(
                                    contact=myphonenumber,
                                    phonebook=obj_phonebook)
            except IntegrityError:
                print _("Duplicate contact!")
                return False

            print _("Contact created id:%(id)s" % {'id': new_contact.id})

            try:
                obj_campaign = Campaign.objects.get(phonebook=obj_phonebook)
            except:
                print _('Can\'t find a Campaign with this phonebook')
                return False

            print _("Launch Task : collect_subscriber(%(id)s)" % {'id': str(obj_campaign.id)})
            collect_subscriber.delay(obj_campaign.id)
示例#2
0
    def handle(self, *args, **options):
        """Note that subscriber created this way are only for devel purposes"""

        for newinst in args:
            print newinst
            res = newinst.split('|')
            myphonenumber = res[0]
            myphonebook_id = res[1]

            try:
                obj_phonebook = Phonebook.objects.get(id=myphonebook_id)
            except:
                print _('Can\'t find this Phonebook : %(id)s' %
                        {'id': myphonebook_id})
                return False

            try:
                new_contact = Contact.objects.create(contact=myphonenumber,
                                                     phonebook=obj_phonebook)
            except IntegrityError:
                print _("Duplicate contact!")
                return False

            print _("Contact created id:%(id)s" % {'id': new_contact.id})

            try:
                obj_campaign = Campaign.objects.get(phonebook=obj_phonebook)
            except:
                print _('Can\'t find a Campaign with this phonebook')
                return False

            print _("Launch Task : collect_subscriber(%(id)s)" %
                    {'id': str(obj_campaign.id)})
            collect_subscriber.delay(obj_campaign.id)
示例#3
0
def update_campaign_status_cust(request, pk, status):
    """Campaign Status (e.g. start|stop|pause|abort) can be changed from
    customer interface (via dialer_campaign/campaign list)"""
    obj_campaign = Campaign.objects.get(id=pk)
    obj_campaign.status = status
    obj_campaign.save()

    pagination_path = '/campaign/'
    if request.session.get('pagination_path'):
        pagination_path = request.session.get('pagination_path')

    #Check if no phonebook attached
    if int(status) == CAMPAIGN_STATUS.START and obj_campaign.phonebook.all().count() == 0:
        request.session['error_msg'] = _('error : you have to assign a phonebook to your campaign before starting it')
    else:
        recipient = request.user
        frontend_send_notification(request, status, recipient)

        # Notify user while campaign Start
        if int(status) == CAMPAIGN_STATUS.START and not obj_campaign.has_been_started:
            request.session['info_msg'] = \
                _('the campaign global settings cannot be edited when the campaign is started')

            # change has_been_started flag
            obj_campaign.has_been_started = True
            obj_campaign.save()

            if obj_campaign.content_type.model == 'survey_template':
                # Copy survey
                survey_template = Survey_template.objects.get(user=request.user, pk=obj_campaign.object_id)
                survey_template.copy_survey_template(obj_campaign.id)
            collect_subscriber.delay(obj_campaign.id)

    return HttpResponseRedirect(pagination_path)
    def handle(self, *args, **options):
        """Note that subscriber created this way are only for devel purposes"""
        list_of_phonenumber = ''  # default
        if options.get('list_of_phonenumber'):
            try:
                list_of_phonenumber = options.get('list_of_phonenumber').split(
                    ',')
            except ValueError:
                list_of_phonenumber = ''

        phonebook_id = ''
        if options.get('phonebook_id'):
            try:
                phonebook_id = options.get('phonebook_id')
                phonebook_id = int(phonebook_id)
            except ValueError:
                phonebook_id = ''

        try:
            obj_phonebook = Phonebook.objects.get(id=phonebook_id)
        except:
            print 'Can\'t find this Phonebook : %(id)s' % {'id': phonebook_id}
            return False

        for phonenumber in list_of_phonenumber:
            try:
                new_contact = Contact.objects.create(contact=int(phonenumber),
                                                     phonebook=obj_phonebook)
            except IntegrityError:
                print "Duplicate contact!"
                return False

            print "Contact created id:%(id)s" % {'id': new_contact.id}

        try:
            obj_campaign = Campaign.objects.get(phonebook=obj_phonebook)
        except:
            print 'Can\'t find a Campaign with this phonebook'
            return False

        print "Launch Task : collect_subscriber(%(id)s)" % {
            'id': str(obj_campaign.id)
        }
        collect_subscriber.delay(obj_campaign.id)
    def handle(self, *args, **options):
        """Note that subscriber created this way are only for devel purposes"""
        list_of_phonenumber = ''  # default
        if options.get('list_of_phonenumber'):
            try:
                list_of_phonenumber = options.get('list_of_phonenumber').split(',')
            except ValueError:
                list_of_phonenumber = ''

        phonebook_id = ''
        if options.get('phonebook_id'):
            try:
                phonebook_id = options.get('phonebook_id')
                phonebook_id = int(phonebook_id)
            except ValueError:
                phonebook_id = ''

        try:
            obj_phonebook = Phonebook.objects.get(id=phonebook_id)
        except:
            print 'Can\'t find this Phonebook : %(id)s' % {'id': phonebook_id}
            return False

        for phonenumber in list_of_phonenumber:
            try:
                new_contact = Contact.objects.create(
                    contact=int(phonenumber),
                    phonebook=obj_phonebook)
            except IntegrityError:
                print "Duplicate contact!"
                return False

            print "Contact created id:%(id)s" % {'id': new_contact.id}

        try:
            obj_campaign = Campaign.objects.get(phonebook=obj_phonebook)
        except:
            print 'Can\'t find a Campaign with this phonebook'
            return False

        print "Launch Task : collect_subscriber(%(id)s)" % {'id': str(obj_campaign.id)}
        collect_subscriber.delay(obj_campaign.id)
示例#6
0
def update_campaign_status_cust(request, pk, status):
    """Campaign Status (e.g. start|stop|pause|abort) can be changed from
    customer interface (via dialer_campaign/campaign list)"""
    obj_campaign = Campaign.objects.get(id=pk)
    obj_campaign.status = status
    obj_campaign.save()

    pagination_path = '/campaign/'
    if request.session.get('pagination_path'):
        pagination_path = request.session.get('pagination_path')

    #Check if no phonebook attached
    if int(status) == CAMPAIGN_STATUS.START and obj_campaign.phonebook.all(
    ).count() == 0:
        request.session['error_msg'] = _(
            'error : you have to assign a phonebook to your campaign before starting it'
        )
    else:
        recipient = request.user
        frontend_send_notification(request, status, recipient)

        # Notify user while campaign Start
        if int(
                status
        ) == CAMPAIGN_STATUS.START and not obj_campaign.has_been_started:
            request.session['info_msg'] = \
                _('the campaign global settings cannot be edited when the campaign is started')

            # change has_been_started flag
            obj_campaign.has_been_started = True
            obj_campaign.save()

            if obj_campaign.content_type.model == 'survey_template':
                # Copy survey
                survey_template = Survey_template.objects.get(
                    user=request.user, pk=obj_campaign.object_id)
                survey_template.copy_survey_template(obj_campaign.id)
            collect_subscriber.delay(obj_campaign.id)

    return HttpResponseRedirect(pagination_path)
示例#7
0
 def test_collect_subscriber(self):
     """Test that the ``collect_subscriber``
     task runs with no errors, and returns the correct result."""
     result = collect_subscriber.delay(1)
     self.assertEqual(result.successful(), True)
示例#8
0
 def test_collect_subscriber(self):
     """Test that the ``collect_subscriber``
     task runs with no errors, and returns the correct result."""
     result = collect_subscriber.delay(1)
     self.assertEqual(result.successful(), True)