Пример #1
0
def tryPointTransferOrder(orderid):
    try:
        order = Order.objects.get(id=orderid)
        try:
            to = TransferOrder.objects.get(order=order)
        except TransferOrder.DoesNotExist:
            try:
                acc = Account.objects.get(user=order.user)
            except Account.DoesNotExist:
                acc = Account(user=order.user, total_current=0, total_lifetime=0)
                acc.save()
            t = Transfer()
            t.account = acc
            t.amount = order.cart.get_points()
            acc.total_current += t.amount
            acc.total_lifetime += t.amount
            acc.save()
            t.isPositive = True
            t.isActive = True
            t.subject = 'Bestellung %s' % order.billnumber()
            t.save()
            to = TransferOrder(order=order, transfer=t)
            to.save()
            return True
    except Order.DoesNotExist:
        pass
    return False
Пример #2
0
    def save(self, request=None, **kwargs):
        import logging
        logging.basicConfig(filename=settings.LOG_FILENAME,level=logging.INFO)

        logging.info('-----NEW REGISTRATION--- START')

        c = Customer()
        data = self.cleaned_data
        logging.info(data)
        c.title = FORM_CHOICES[data['form']][1]
        c.first_name = data['firstname']
        c.last_name = data['lastname']
        try:
            c.birthday = data['birthday']
        except:
            logging.info('birthday failed')
            pass
        c.language_code = 'de'

        email = data['email']
        password = data['password']
        uname = data['username']
        user = User.objects.create_user(uname, email, password)
        user.is_active = False
        user.save()
        logging.info('new user saved')
        c.user = user
        c.save()

        acc = Account(user=user, total_current=0, total_lifetime=0)
        acc.save()

        ec = EmailConfirm(user=user)
        tmp = '%s%s' % (user.email,datetime.datetime.now())
        ec.confirmkey = hashlib.md5(hashlib.md5(tmp).hexdigest()).hexdigest()
        ec.save()

        try:
            if data['newsletter']:
                s = Subscriper()
                s.email = email
                s.user = c.user
                tmp = '%s%s' % (s.email,datetime.datetime.now())
                s.confirmkey = hashlib.md5(hashlib.md5(tmp).hexdigest()).hexdigest()
                s.isActivated = True
                s.save()
        except:
            logging.info('maybe no newsletter')
            pass

        ref = Referral()
        ref.promoter = User.objects.get(username=data['refcode'])
        ref.referral = c.user
        ref.save()

        logging.info('send welcomemail to user')
        sendWelcomeMail(user)

        #user = authenticate(username=uname, password=password)
        #login(request, user)
        logging.info('-----NEW REGISTRATION--- END')
        return c