<commit_before>#
# Newfies-Dialer License
# http://www.newfies-dialer.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# <NAME> <<EMAIL>>
#

from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.utils.translation import ugettext_lazy as _
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
from dialer_campaign.models import Campaign
from dialer_cdr.models import Callrequest, VoIPCall
from django.db import IntegrityError
from random import choice
from uuid import uuid1
import random

VOIPCALL_DISPOSITION = ['ANSWER','BUSY', 'NOANSWER', 'CANCEL', 'CONGESTION',
                        'CHANUNAVAIL', 'DONTCALL', 'TORTURE', 'INVALIDARGS',
                        'NOROUTE', 'FORBIDDEN']

class Command(BaseCommand):
    # Use : create_callrequest_cdr '1|1324242' '3|124242'
    #                              'campaign_id|no_of_record'
    args = _('"campaign_id|no_of_record" "campaign_id|no_of_record"')
    help = _("Creates no of new call requests and CDRs for a given campaign_id & no of records")

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

        for newinst in args:
            res = newinst.split('|')
            campaign_id = res[0]
            no_of_record = res[1]

            try:
                admin_user = User.objects.get(pk=1)
                try:
                    obj_campaign = Campaign.objects.get(id=campaign_id)
                except:
                    print _('Can\'t find this Campaign : %(id)s' % {'id': campaign_id})
                    return False

                try:
                    length=5
                    chars="1234567890"

                    #'survey'
                    try:
                        content_type_id = ContentType.objects.get(app_label=str('voice_app')).id
                    except:
                        content_type_id = 1

                    for i in range(1, int(no_of_record) + 1):
                        phonenumber = '' . join([choice(chars) for i in range(length)])
                        new_callrequest = Callrequest.objects.create(
                                            request_uuid=uuid1(),
                                            user=admin_user,
                                            phone_number=phonenumber,
                                            campaign=obj_campaign,
                                            aleg_gateway_id=1,
                                            status=choice("12345678"),
                                            call_type=1,
                                            content_type_id=content_type_id,
                                            object_id=1)

                        new_cdr = VoIPCall.objects.create(
                                            request_uuid=uuid1(),
                                            user=admin_user,
                                            callrequest=new_callrequest,
                                            phone_number=phonenumber,
                                            duration=random.randint(1, 100),<commit_msg>updated create_callrequest_cdr command<commit_after>#
# Newfies-Dialer License
# http://www.newfies-dialer.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# <NAME> <<EMAIL>>
#

from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.utils.translation import gettext_lazy as _
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
from dialer_campaign.models import Campaign
from dialer_cdr.models import Callrequest, VoIPCall
from django.db import IntegrityError
from random import choice
from uuid import uuid1
import random

VOIPCALL_DISPOSITION = ['ANSWER','BUSY', 'NOANSWER', 'CANCEL', 'CONGESTION',
                        'CHANUNAVAIL', 'DONTCALL', 'TORTURE', 'INVALIDARGS',
                        'NOROUTE', 'FORBIDDEN']

class Command(BaseCommand):
    # Use : create_callrequest_cdr '1|1324242' '3|124242'
    #                              'campaign_id|no_of_record'
    args = _('"campaign_id|no_of_record" "campaign_id|no_of_record"')
    help = _("Creates no of new call requests and CDRs for a given campaign_id & no of records")

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

        for newinst in args:
            res = newinst.split('|')
            campaign_id = res[0]
            no_of_record = res[1]

            try:
                admin_user = User.objects.get(pk=1)
                try:
                    obj_campaign = Campaign.objects.get(id=campaign_id)
                except:
                    print _('Can\'t find this Campaign : %(id)s' % {'id': campaign_id})
                    return False

                try:
                    length=5
                    chars="1234567890"

                    #'surveyapp' | 'voiceapp'
                    try:
                        content_type_id = ContentType.objects.get(model='voiceapp').id
                    except:
                        content_type_id = 1

                    for i in range(1, int(no_of_record) + 1):
                        phonenumber = '' . join([choice(chars) for i in range(length)])
                        new_callrequest = Callrequest.objects.create(
                                            request_uuid=uuid1(),
                                            user=admin_user,
                                            phone_number=phonenumber,
                                            campaign=obj_campaign,
                                            aleg_gateway_id=1,
                                            status=choice("12345678"),
                                            call_type=1,
                                            content_type_id=content_type_id,
                                            object_id=1)

                        new_cdr = VoIPCall.objects.create(
                                            request_uuid=uuid1(),
                                            user=admin_user,
                                            callrequest=new_callrequest,
                                            phone_number=phonenumber,
                                            duration=random.randint(1, 100),
{'fraction_non_alphanumeric': 0.0801548609119587, 'fraction_numerical': 0.018067106395182105, 'mean_word_length': 1.397731179099347, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 60, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '137877', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1673, 'n_words': 438}