예제 #1
0
    def form_valid(self, form):
        real_email = form.cleaned_data['email']
        username = generate_username()
        password = generate_username()
        email = '*****@*****.**' % username

        user = self.create_dashboard_user(username, email, password)
        self.send_confirmation_email(real_email, user, password)
        logger.info("Created dashboard user #%d for %s",
                    user.id, real_email)

        messages.success(
            self.request,
            "The credentials for a dashboard user have been sent to %s" % real_email)
        return http.HttpResponseRedirect(reverse('gateway'))
예제 #2
0
    def form_valid(self, form):
        real_email = form.cleaned_data['email']
        username = generate_username()
        password = generate_username()
        email = '*****@*****.**' % username

        user = self.create_dashboard_user(username, email, password)
        self.send_confirmation_email(real_email, user, password)
        logger.info("Created dashboard user #%d for %s",
                    user.id, real_email)

        messages.success(
            self.request,
            "The credentials for a dashboard user have been sent to %s" % real_email)
        return http.HttpResponseRedirect(reverse('gateway'))
예제 #3
0
파일: views.py 프로젝트: mnzil/marketplace
    def form_valid(self, form):
        code = form.cleaned_data['shop_name']
        email = form.cleaned_data['email']
        full_name = form.cleaned_data['full_name']
        username = generate_username()
        password = generate_username()

        user = self.create_dashboard_user(
            username, email, password,
            full_name, code)
        self.send_confirmation_email(email, user, password)
        logger.info("Created dashboard user #%d for %s",
                    user.id, email)

        messages.success(
            self.request,
            "The credentials of a dashboard user have been sent to %s" % email)
        return http.HttpResponseRedirect(reverse('gateway'))
예제 #4
0
    def save(self, commit=True):
        user = super(EmailUserCreationForm, self).save(commit=False)
        user.set_password(self.cleaned_data['password1'])

        if 'username' in [f.name for f in User._meta.fields]:
            user.username = generate_username()
        if commit:
            user.save()
            user_profile = CustomerProfile(user=user,birth_date=self.cleaned_data['date_of_birth'])
            user_profile.save()
        return user
예제 #5
0
    def form_valid(self, form):
        real_email = form.cleaned_data['email']
        username = real_email
        password = generate_username()
        email = real_email

        user = self.create_dashboard_user(username, email, password)
        self.send_confirmation_email(real_email, user, password)
        logger.info("Created dashboard user #%d for %s",
            user.id, real_email)

        messages.success(
            self.request,
            u"Данные для доступа к админке магазина отправлены на email %s" % real_email)
        return http.HttpResponseRedirect(reverse('gateway'))
    def import_customers(self):
        self.log.info(
            "start importing customer data from database '%s'",
            self.database
        )

        oscar_user = get_model('auth', 'user')
        oscom_customer = get_model(self.name, 'customer')

        customer_query = oscom_customer.objects.using(
            self.database
        ).select_related(
            'addresses'
        )
        for customer in customer_query.all():

            if not customer.email:
                self.log.error(
                    "cannot import user '%s' without email address",
                    customer
                )
                continue

            self.log.debug("importing customer '%s'", unicode(customer))

            email = customer.email.strip()
            try:
                user = oscar_user.objects.get(email=email)
                if not self.force_update:
                    continue
            except oscar_user.DoesNotExist:
                user = oscar_user()
                user.email = email

            username, __ = email.split('@')
            user.username = generate_username()
            user.first_name = customer.firstname
            user.last_name = customer.lastname

            user.password = self.convert_password_hash(customer.password)

            user.date_joined = customer.info.date_account_created
            if customer.info.date_of_last_logon:
                user.last_login = customer.info.date_of_last_logon
            user.save()

            profile = user.get_profile()
            for osc_field, oscar_field in self.customer_mapping.items():
                osc_value = getattr(customer, osc_field, None)
                if osc_value is not None:
                    setattr(profile, oscar_field, osc_value)

            profile.save()
            self.log.info("customer '%s' imported successfully", unicode(customer))

            oscar_user_address = get_model('address', 'useraddress')
            oscom_order = get_model(self.name, 'order')

            for address in customer.addresses.all():
                self.log.debug('creating new address in addressbook')

                country = self.get_oscar_country(address.country)

                if not address.company or address.company == address.street_address:
                    line1 = address.street_address
                    line2 = address.suburb
                    line3 = None
                else:
                    line1 = address.company
                    line2 = address.street_address
                    line3 = address.suburb

                zone_name = self.get_zone_name(address)

                is_default_address = False
                if address.id == customer.default_address_id:
                    is_default_address = True

                user_address, created = oscar_user_address.objects.get_or_create(
                    user=user,
                    first_name=user.first_name,
                    last_name=user.last_name,
                    line1=line1,
                    line2=line2,
                    line3=line3,
                    line4=address.city,
                    state=zone_name,
                    postcode=address.postcode,
                    country=country,
                    is_default_for_shipping=is_default_address,
                    is_default_for_billing=is_default_address,
                )

                if created or self.force_update:
                    user_address.num_orders = oscom_order.objects.using(
                        self.database
                    ).filter(
                        customer=customer,
                        delivery_company=address.company or '',
                        delivery_street_address=address.street_address,
                        delivery_suburb=address.suburb or '',
                        delivery_city=address.city,
                        delivery_postcode=address.postcode,
                        delivery_country=address.country.name,
                    ).count()
                    user_address.save()

                    self.log.debug(
                        'address used %d times as shipping address',
                        user_address.num_orders
                    )

                self.log.info(
                    'address #%d added for customer %s',
                    user_address.id,
                    unicode(customer),
                )