Beispiel #1
0
    def test_set_get_value(self):
        """It's possible to set and get value from threadstore"""
        self.assertEqual(threadstore.get('knights_say'), None)

        returned_value = threadstore.set('knights_say', 'Ni!')
        self.assertEqual(returned_value, 'Ni!')
        self.assertEqual(threadstore.get('knights_say'), 'Ni!')
Beispiel #2
0
 def test_clear_store(self):
     """clear cleared threadstore"""
     self.assertEqual(threadstore.get('the_fish'), None)
     threadstore.set('the_fish', 'Eric')
     self.assertEqual(threadstore.get('the_fish'), 'Eric')
     threadstore.clear()
     self.assertEqual(threadstore.get('the_fish'), None)
Beispiel #3
0
def SearchUsersForm(*args, **kwargs):
    """
    Factory that uses cache for ranks and roles,
    and makes those ranks and roles typed choice fields that play nice
    with passing values via GET
    """
    ranks_choices = threadstore.get('misago_admin_ranks_choices', 'nada')
    if ranks_choices == 'nada':
        ranks_choices = [('', _("All ranks"))]
        for rank in Rank.objects.order_by('name').iterator():
            ranks_choices.append((rank.pk, rank.name))
        threadstore.set('misago_admin_ranks_choices', ranks_choices)

    roles_choices = threadstore.get('misago_admin_roles_choices', 'nada')
    if roles_choices == 'nada':
        roles_choices = [('', _("All roles"))]
        for role in Role.objects.order_by('name').iterator():
            roles_choices.append((role.pk, role.name))
        threadstore.set('misago_admin_roles_choices', roles_choices)

    extra_fields = {
        'rank': forms.TypedChoiceField(label=_("Has rank"),
                                       coerce=int,
                                       required=False,
                                       choices=ranks_choices),
        'role': forms.TypedChoiceField(label=_("Has role"),
                                       coerce=int,
                                       required=False,
                                       choices=roles_choices)
    }

    FinalForm = type('SearchUsersFormFinal',
                     (SearchUsersFormBase,),
                     extra_fields)
    return FinalForm(*args, **kwargs)
Beispiel #4
0
    def test_middleware_clears_store_on_response_exception(self):
        """Middleware cleared store on response"""

        threadstore.set('any_chesse', 'Nope')
        middleware = ThreadStoreMiddleware()
        response = middleware.process_response(self.request, 'FakeResponse')
        self.assertEqual(response, 'FakeResponse')
        self.assertEqual(threadstore.get('any_chesse'), None)
Beispiel #5
0
def SearchUsersForm(*args, **kwargs):
    """
    Factory that uses cache for ranks and roles,
    and makes those ranks and roles typed choice fields that play nice
    with passing values via GET
    """
    ranks_choices = threadstore.get('misago_admin_ranks_choices', 'nada')
    if ranks_choices == 'nada':
        ranks_choices = [('', _("All ranks"))]
        for rank in Rank.objects.order_by('name').iterator():
            ranks_choices.append((rank.pk, rank.name))
        threadstore.set('misago_admin_ranks_choices', ranks_choices)

    roles_choices = threadstore.get('misago_admin_roles_choices', 'nada')
    if roles_choices == 'nada':
        roles_choices = [('', _("All roles"))]
        for role in Role.objects.order_by('name').iterator():
            roles_choices.append((role.pk, role.name))
        threadstore.set('misago_admin_roles_choices', roles_choices)

    extra_fields = {
        'rank':
        forms.TypedChoiceField(
            label=_("Has rank"),
            coerce=int,
            required=False,
            choices=ranks_choices,
        ),
        'role':
        forms.TypedChoiceField(
            label=_("Has role"),
            coerce=int,
            required=False,
            choices=roles_choices,
        )
    }

    FinalForm = type('SearchUsersFormFinal', (SearchUsersFormBase, ),
                     extra_fields)
    return FinalForm(*args, **kwargs)
Beispiel #6
0
def get_user_acl(user):
    """get ACL for User"""
    acl_key = 'acl_%s' % user.acl_key

    acl_cache = threadstore.get(acl_key)
    if not acl_cache:
        acl_cache = cache.get(acl_key)

    if acl_cache and version.is_valid(acl_cache.get('_acl_version')):
        return acl_cache
    else:
        new_acl = build_acl(user.get_roles())
        new_acl['_acl_version'] = version.get_version()

        threadstore.set(acl_key, new_acl)
        cache.set(acl_key, new_acl)

        return new_acl
Beispiel #7
0
 def get_db_settings(self):
     dbsettings = threadstore.get(CACHE_KEY)
     if not dbsettings:
         dbsettings = DBSettings()
         threadstore.set(CACHE_KEY, dbsettings)
     return dbsettings
Beispiel #8
0
 def get_db_settings(self):
     dbsettings = threadstore.get(CACHE_KEY)
     if not dbsettings:
         dbsettings = DBSettings()
         threadstore.set(CACHE_KEY, dbsettings)
     return dbsettings
Beispiel #9
0
 def get_levels_from_threadstore(self):
     levels = threadstore.get(CACHE_NAME, "nada")
     if levels == "nada":
         levels = self.get_levels_from_cache()
         threadstore.set(CACHE_NAME, levels)
     return levels
Beispiel #10
0
 def get_levels_from_threadstore(self):
     levels = threadstore.get(CACHE_NAME, 'nada')
     if levels == 'nada':
         levels = self.get_levels_from_cache()
         threadstore.set(CACHE_NAME, levels)
     return levels
Beispiel #11
0
 def read_threadstore(self):
     data = threadstore.get(CACHE_KEY, 'nada')
     if data == 'nada':
         data = self.read_cache()
         threadstore.set(CACHE_KEY, data)
     return data
Beispiel #12
0
 def read_threadstore(self):
     data = threadstore.get(CACHE_KEY, 'nada')
     if data == 'nada':
         data = self.read_cache()
         threadstore.set(CACHE_KEY, data)
     return data