示例#1
0
 def test_no_tier_user(self):
     """Check price when user doesn't have a tier"""
     product = Product.objects.get(slug='PY-Rocks')
     set_current_user(self.stduser)
     self.assertEqual(product.unit_price, Decimal("19.50"))
     # test that a negative answer is cached in threadlocals
     self.assertEqual(get_thread_variable('TIER_%i' % self.stduser.id), [])
示例#2
0
文件: tests.py 项目: kidaa30/pops
 def test_no_tier_user(self):
     """Check price when user doesn't have a tier"""
     product = Product.objects.get(slug="PY-Rocks")
     set_current_user(self.stduser)
     self.assertEqual(product.unit_price, Decimal("19.50"))
     # test that a negative answer is cached in threadlocals
     self.assertEqual(get_thread_variable("TIER_%i" % self.stduser.id), [])
示例#3
0
 def save(self, *args, **kwargs):
     data = threadlocals.get_thread_variable('versioning_data', {})
     if hasattr(self, 'updated_by'):
         self.updated_by = data.get('updated_by', 'SYSTEM')
     if hasattr(self, 'updated_through'):
         self.updated_through = data.get('updated_through', 'SHELL')
     if hasattr(self, 'updating_process'):
         self.updating_process = data.get('updating_process', '')
     if hasattr(self, 'updating_process_meta'):
         self.updating_process_meta = json.dumps(
             data.get('updating_process_meta', {}))
     super(TrackingModel, self).save(*args, **kwargs)
示例#4
0
def _get_taxprocessor(request=None):
    taxprocessor = get_thread_variable("taxer", None)
    if not taxprocessor:
        if request:
            user = request.user
            if user.is_authenticated():
                user = user
            else:
                user = None
        else:
            user = get_current_user()

        taxprocessor = get_tax_processor(user=user)
        set_thread_variable("taxer", taxprocessor)

    return taxprocessor
示例#5
0
def _get_taxprocessor(request=None):
    taxprocessor = get_thread_variable('taxer', None)
    if not taxprocessor:
        if request:
            user = request.user
            if user.is_authenticated():
                user = user
            else:
                user = None
        else:
            user = get_current_user()

        taxprocessor = get_tax_processor(user=user)
        set_thread_variable('taxer', taxprocessor)

    return taxprocessor
示例#6
0
def _get_taxprocessor(request=None):
    if request:
        user = request.user
        if user.is_authenticated:
            user_id = user.id
        else:
            user = None
            user_id = "None"
    else:
        user = get_current_user()
        user_id = user and user.id
    thread_key = "taxer-%s" % user_id
    taxprocessor = get_thread_variable(thread_key, None)
    if not taxprocessor:
        taxprocessor = get_tax_processor(user=user)
        set_thread_variable(thread_key, taxprocessor)
    return taxprocessor
示例#7
0
def _get_taxprocessor(request=None):
    if request:
        user = request.user
        if user.is_authenticated():
            user_id = user.id
        else:
            user = None
            user_id = "None"
    else:
        user = get_current_user()
        user_id = user and user.id
    thread_key = "taxer-%s" % user_id
    taxprocessor = get_thread_variable(thread_key, None)
    if not taxprocessor:
        taxprocessor = get_tax_processor(user=user)    
        set_thread_variable(thread_key, taxprocessor)
    return taxprocessor
示例#8
0
    def by_user(self, user):
        """Get the pricing tiers for a user"""
        key = 'TIER_%i' % user.id
        current = threadlocals.get_thread_variable(key)

        if current is None:
            groups = user.groups.all()
            current = []
            if groups and not user.is_superuser and not user.is_staff:
                filterQ = Q()
                for group in groups:
                    filterQ = filterQ | Q(group=group)
                current = list(self.filter(filterQ))

            threadlocals.set_thread_variable(key, current)

        if not current:
            raise PricingTier.DoesNotExist

        return current
示例#9
0
    def by_user(self, user):
        """Get the pricing tiers for a user"""
        key = 'TIER_%i' % user.id
        current = threadlocals.get_thread_variable(key)

        if current is None:
            groups = user.groups.all()
            current = []
            if groups and not user.is_superuser and not user.is_staff:
                filterQ = Q()
                for group in groups:
                    filterQ = filterQ | Q(group=group)
                current = list(self.filter(filterQ))

            threadlocals.set_thread_variable(key, current)

        if not current:
            raise PricingTier.DoesNotExist

        return current
示例#10
0
    def by_user(self, user):
        """Get the pricing tiers for a user"""
        key = 'TIER_%i' % user.id
        current = threadlocals.get_thread_variable(key)

        if current is None:
            groups = user.groups.all()
            if groups:
                q = self.all()
                for group in groups:
                    q = q.filter(group=group)
                if q.count() > 0:
                    current = list(q)

            if current is None:
                current = "no"

            threadlocals.set_thread_variable(key, current)

        if current == "no":
            raise PricingTier.DoesNotExist

        return current
示例#11
0
文件: models.py 项目: hnejadi/xerobis
    def by_user(self, user):
        """Get the pricing tiers for a user"""
        key = 'TIER_%i' % user.id
        current = threadlocals.get_thread_variable(key)
        
        if current is None:
            groups = user.groups.all()
            if groups:            
                q = self.all()
                for group in groups:
                    q = q.filter(group=group)
                if q.count() > 0:
                    current = list(q)
                    
            if current is None:
                current = "no"
                
            threadlocals.set_thread_variable(key, current)

        if current == "no":
            raise PricingTier.DoesNotExist
        
        return current
示例#12
0
def clear_request_uid(sender, *args, **kwargs):
    """Removes the thread cache for this request"""
    tid = threadlocals.get_thread_variable('request_uid', -1)
    if tid > -1:
        cache_clear_request(tid)
示例#13
0
def cache_get_request_uid():
    from threaded_multihost import threadlocals
    return threadlocals.get_thread_variable('request_uid', -1)
示例#14
0
def cache_get_request_uid():
    from threaded_multihost import threadlocals
    return threadlocals.get_thread_variable('request_uid', -1)