예제 #1
0
    def handle(self, *args, **options):
        if options['name'] and ' ' in options['name']:
            first_name, last_name = options['name'].split(' ')
        elif options['name']:
            first_name = options['name']
            last_name = ""
        else:
            first_name = options['username']
            last_name = ""

        if options['password']:
            password = options['password']
        else:
            password = getpass()

        person = Person(
            first_name=first_name,
            last_name=last_name,
            email=options['email'],
        )
        person.save()
        user = PS1User.objects.create_superuser(
            options['username'],
            email=options['email'],
            first_name=first_name,
            last_name=last_name,
        )

        self.set_password(user, password)

        person.user = user
        person.save()
예제 #2
0
    def handle(self, *args, **options):
        if options["name"] and " " in options["name"]:
            first_name, last_name = options["name"].split(" ")
        elif options["name"]:
            first_name = options["name"]
            last_name = ""
        else:
            first_name = options["username"]
            last_name = ""

        if options["password"]:
            password = options["password"]
        else:
            password = getpass()

        person = Person(first_name=first_name, last_name=last_name, email=options["email"])
        person.save()
        user = PS1User.objects.create_superuser(
            options["username"], email=options["email"], first_name=first_name, last_name=last_name
        )

        self.set_password(user, password)

        person.user = user
        person.save()
예제 #3
0
class ActivationTest(TestCase):
    def setUp(self):
        self.person = Person(
                    first_name = "Jay",
                    last_name="Hacker",
                    email="*****@*****.**",
                    membership_status="Starving",
                    )
        self.person.save()

    def tearDown(self):
        self.person.delete()

    def get_token(self):
        return Token.objects.get(person = self.person)

    def test_activation_form(self):

        activation_data = {}
        activation_data['ps1_email'] = "*****@*****.**"
        activation_form = activate_account_form(data = activation_data)
        self.assertTrue(activation_form.is_valid())
        activation_form.save(use_https = False, domain = "example.com")
        
        #an email gets sent out. since I don't know how to retrieve it, I am going to cheat
        self.token = Token.objects.get(person = self.person);
        self.assertIsNotNone(self.token)

    def test_register_form(self):
        """
        This tests most of the zoho activation path.
        """
        activation_data = {}
        activation_data['ps1_email'] = "*****@*****.**"
        activation_form = activate_account_form(data = activation_data)
        self.assertTrue(activation_form.is_valid())
        activation_form.save(use_https = False, domain = "example.com")
        
        #an email gets sent out. since I don't know how to retrieve it, I am going to cheat
        self.token = Token.objects.get(person = self.person);
        self.assertIsNotNone(self.token)
        register_data = {}
        register_data['token'] = self.token.token
        register_data['preferred_username'] = '******'
        register_data['first_name'] = 'Jay'
        register_data['last_name'] = 'Hacker'
        register_data['preferred_email'] = '*****@*****.**'
        register_form = account_register_form(data=register_data)
        self.assertTrue(register_form.is_valid())
        user = register_form.save()
        self.assertIsNotNone(user)
        
        with self.assertRaises(Token.DoesNotExist):
            Token.objects.get(person = self.person)
        
        PS1User.objects.delete_user(user)

    def test_activate(self):
        c = Client()

        response = c.get('/signup/activate/')
        self.assertEqual(response.status_code, 200)

        response = c.post('/signup/activate/', {'ps1_email': '*****@*****.**'}, follow=True)
        self.assertEqual(response.status_code, 200)

        # "read" email
        token = self.get_token()
        activation_url = '/signup/activate/confirm/{}'.format(token.token)
        response = c.get(activation_url)
        self.assertEqual(response.status_code, 200)
        
        post_data = {
            'preferred_username': '******',
            'first_name': 'Jay',
            'last_name': 'Hacker',
            'preferred_email': '*****@*****.**',
            'token': token.token,
        }
        response = c.post(activation_url, post_data, follow=True)
        self.assertEqual(response.status_code, 200)

        jay = Person.objects.get(pk=self.person.pk)
        self.assertIsNotNone(jay.user)
        PS1User.objects.delete_user(jay.user)
예제 #4
0
    def handle(self, *args, **options):
        data = json.loads(open(args[0], 'rb').read())
        self.id_map = {}

        Person.objects.all().delete()
        MemberPoint.objects.all().delete()

        for entry in data:
            if entry.has_key('contact_id'):
                with transaction.atomic(), reversion.create_revision():
                    reversion.set_comment("Imported from Zoho CRM")
                    crm_person = Person()
                    self.id_map[entry['contact_id']] = crm_person
                    dob = entry['date_of_birth']
                    if dob:
                        crm_person.birthday = dateutil.parser.parse(dob).date()
                    crm_person.city = entry['mailing_city']
                    crm_person.first_name = entry['first_name']

                    # for some reason the last name field contains the first name and salutation
                    if entry['salutation']:
                        starter_text = entry['salutation'] + " " + entry[
                            'first_name']
                    else:
                        starter_text = entry['first_name']
                    if entry['last_name'].strip().startswith(starter_text):
                        crm_person.last_name = entry['last_name'].strip(
                        )[len(starter_text):].strip()
                    else:
                        crm_person.last_name = entry['last_name'].strip()

                    crm_person.email = entry['primary_email']
                    crm_person.street_address = entry['mailing_street']
                    crm_person.mailing_city = entry['mailing_city']
                    crm_person.mailing_state = entry['mailing_state']
                    crm_person.zip_code = entry['mailing_zip']
                    crm_person.country = entry['mailing_country']

                    start_date = entry['membership_start_date']
                    if start_date:
                        crm_person.membership_start_date = dateutil.parser.parse(
                            start_date).date()

                    crm_person.membership_status = membership_status_map[
                        entry['membership_status']]
                    crm_person.save()

                    # Port
                    try:
                        existing_contact = Contact.objects.get(
                            contact_id=entry['contact_id'])
                        crm_person.user = existing_contact.user
                        crm_person.save()
                    except Contact.DoesNotExist:
                        pass

                    if (entry['payment_type'] == 'Paypal'
                            and entry['primary_email']
                        ) or entry['secondary_email']:
                        paypal = PayPal()
                        paypal.person = crm_person
                        if entry['secondary_email']:
                            paypal.email = entry['secondary_email']
                        else:
                            paypal.email = entry['primary_email']
                        if entry['membership_end_date']:
                            paypal.paid_up_until = dateutl.parser.parse(
                                entry['membership_end_date']).replace(
                                    tzinfo=tz)
                        paypal.save()

                    elif entry['payment_type'] == 'Cash' and entry[
                            'membership_end_date']:
                        cash = Cash()
                        cash.person = crm_person
                        cash.paid_up_until = dateutl.parser.parse(
                            entry['membership_end_date']).replace(tzinfo=tz)
                        cash.save()

                    # member points
                    if entry['member_points']:
                        points = int(float(entry['member_points']))
                        for point in range(1, points):
                            with transaction.atomic(
                            ), reversion.create_revision():
                                reason = "imported from zoho for {} {}".format(
                                    crm_person.first_name,
                                    crm_person.last_name)
                                MemberPoint.objects.create(
                                    reason=reason, owner=crm_person.user)

        for entry in data:

            if self.id_check(entry):
                pass
            elif entry.has_key('note_id'):
                note = Note()
                note.person = self.id_map[entry['parent_contact_id']]
                if entry['title']:
                    note.content = entry['title'].strip(
                    ) + ": " + entry['body']
                else:
                    note.content = entry['body']
                created_at = dateutil.parser.parse(
                    entry['created_at']).replace(tzinfo=tz)
                username = self.get_ps1user(created_at, entry['by'])
                user = PS1User.objects.get_users_by_field(
                    "sAMAccountName", username)[0]
                note.author = user
                note.save()
                note.created_at = created_at
                note.save()

            elif entry.has_key('msg_id'):
                email_record = EmailRecord()
                email_record.recipient = self.id_map[
                    entry['contact_zoho_crm_id']]
                email_record.subject = entry['subject']
                email_record.to_email = entry['to_email']
                email_record.from_email = entry['from_email']
                email_record.message = entry['body']
                email_record.status = "zoho"
                created_at = dateutil.parser.parse(
                    entry['sent_time']).replace(tzinfo=tz)
                email_record.sender = self.get_ps1user(created_at,
                                                       entry['sender'])
                email_record.save()
                email_record.created_at = created_at
                email_record.save()
예제 #5
0
    def handle(self, *args, **options):
        data = json.loads(open(args[0],'rb').read())
        self.id_map = {}

        Person.objects.all().delete()
        MemberPoint.objects.all().delete()

        for entry in data:
            if entry.has_key('contact_id'):
                with transaction.atomic(), reversion.create_revision():
                    reversion.set_comment("Imported from Zoho CRM")
                    crm_person = Person()
                    self.id_map[entry['contact_id']] = crm_person
                    dob = entry['date_of_birth']
                    if dob:
                        crm_person.birthday = dateutil.parser.parse(dob).date()
                    crm_person.city = entry['mailing_city']
                    crm_person.first_name = entry['first_name']

                    # for some reason the last name field contains the first name and salutation
                    if entry['salutation']:
                        starter_text = entry['salutation'] + " " + entry['first_name']
                    else:
                        starter_text = entry['first_name']
                    if entry['last_name'].strip().startswith(starter_text):
                        crm_person.last_name = entry['last_name'].strip()[len(starter_text):].strip()
                    else:
                        crm_person.last_name = entry['last_name'].strip()

                    crm_person.email = entry['primary_email']
                    crm_person.street_address = entry['mailing_street']
                    crm_person.mailing_city = entry['mailing_city']
                    crm_person.mailing_state = entry['mailing_state']
                    crm_person.zip_code = entry['mailing_zip']
                    crm_person.country = entry['mailing_country']

                    start_date = entry['membership_start_date']
                    if start_date:
                        crm_person.membership_start_date = dateutil.parser.parse(start_date).date()

                    crm_person.membership_status = membership_status_map[entry['membership_status']]
                    crm_person.save()

                    # Port
                    try:
                        existing_contact = Contact.objects.get(contact_id=entry['contact_id'])
                        crm_person.user = existing_contact.user
                        crm_person.save()
                    except Contact.DoesNotExist:
                        pass

                    if (entry['payment_type'] == 'Paypal' and entry['primary_email']) or entry['secondary_email']:
                        paypal = PayPal()
                        paypal.person = crm_person
                        if  entry['secondary_email']:
                            paypal.email = entry['secondary_email']
                        else:
                            paypal.email = entry['primary_email']
                        if entry['membership_end_date']:
                            paypal.paid_up_until = dateutl.parser.parse(entry['membership_end_date']).replace(tzinfo=tz)
                        paypal.save()

                    elif entry['payment_type'] == 'Cash' and entry['membership_end_date']:
                        cash = Cash()
                        cash.person = crm_person
                        cash.paid_up_until = dateutl.parser.parse(entry['membership_end_date']).replace(tzinfo=tz)
                        cash.save()


                    # member points
                    if entry['member_points']:
                        points = int(float(entry['member_points']))
                        for point in range(1, points):
                            with transaction.atomic(), reversion.create_revision():
                                reason = "imported from zoho for {} {}".format(crm_person.first_name, crm_person.last_name)
                                MemberPoint.objects.create(reason=reason, owner=crm_person.user)

        for entry in data:

            if self.id_check(entry):
                pass
            elif entry.has_key('note_id'):
                note = Note()
                note.person = self.id_map[entry['parent_contact_id']]
                if entry['title']:
                    note.content = entry['title'].strip() + ": " + entry['body']
                else:
                    note.content = entry['body']
                created_at = dateutil.parser.parse(entry['created_at']).replace(tzinfo=tz)
                username = self.get_ps1user(created_at, entry['by'])
                user = PS1User.objects.get_users_by_field("sAMAccountName", username)[0]
                note.author = user
                note.save()
                note.created_at = created_at
                note.save()

            elif entry.has_key('msg_id'):
                email_record = EmailRecord()
                email_record.recipient = self.id_map[entry['contact_zoho_crm_id']]
                email_record.subject = entry['subject']
                email_record.to_email = entry['to_email']
                email_record.from_email = entry['from_email']
                email_record.message = entry['body']
                email_record.status = "zoho"
                created_at = dateutil.parser.parse(entry['sent_time']).replace(tzinfo=tz)
                email_record.sender = self.get_ps1user(created_at, entry['sender'])
                email_record.save()
                email_record.created_at = created_at
                email_record.save()