示例#1
0
def get_self_application_library_by_listing_type(username, listing_type):
    """
    Get the ApplicationLibrary for this user filtered by listing type

    Key: app_library_type(<listing_type>):<username>
    """
    username = utils.make_keysafe(username)
    listing_type_key = utils.make_keysafe(listing_type)
    key = 'app_library_type(%s):%s' % (username, listing_type_key)
    data = cache.get(key)
    if data is None:
        try:
            data = models.ApplicationLibraryEntry.objects.filter(
                owner__user__username=username).filter(listing__listing_type__title=listing_type).filter(listing__is_enabled=True)
            cache.set(key, data)
            return data
        except ObjectDoesNotExist:
            return None
    else:
        return data
示例#2
0
def get_reviews(username):
    """
    Get Reviews this user can see

    Key: reviews:<username>
    """
    username = utils.make_keysafe(username)
    key = 'reviews:{0!s}'.format(username)
    data = cache.get(key)
    if data is None:
        try:
            data = models.Review.objects.for_user(username).all()
            cache.set(key, data)
            return data
        except ObjectDoesNotExist:
            return None
    else:
        return data
def get_listings(username):
    """
    Get Listings this user can see

    Key: listings:<username>
    """
    username = utils.make_keysafe(username)
    key = 'listings:%s' % username
    data = cache.get(key)
    if data is None:
        try:
            data = models.Listing.objects.for_user(username).all()
            cache.set(key, data)
            return data
        except ObjectDoesNotExist:
            return None
    else:
        return data
def get_self_application_library(username):
    """
    Get the ApplicationLibrary for this user

    Key: app_library:<username>
    """
    username = utils.make_keysafe(username)
    key = "app_library:%s" % username
    data = cache.get(key)
    if data is None:
        try:
            data = models.ApplicationLibraryEntry.objects.filter(owner__user__username=username)
            cache.set(key, data)
            return data
        except ObjectDoesNotExist:
            return None
    else:
        return data
示例#5
0
def get_self_listings(username):
    """
    Get the Listings that belong to this user

    Key: self_listings:<username>
    """
    username = utils.make_keysafe(username)
    key = 'self_listings:{0!s}'.format(username)
    data = cache.get(key)
    if data is None:
        try:
            user = generic_model_access.get_profile(username)
            data = models.Listing.objects.for_user(username).filter(
                owners__in=[user.id]).filter(is_deleted=False)
            cache.set(key, data)
            return data
        except ObjectDoesNotExist:
            return None
    else:
        return data
示例#6
0
def get_profile(username):
    """
    get a user's Profile

    Key: current_profile:<username>
    """
    username = utils.make_keysafe(username)
    key = 'current_profile:%s' % username

    data = cache.get(key)
    if data is None:
        try:
            data = models.Profile.objects.get(user__username=username)
            cache.set(key, data)
            # logger.debug('NOT getting data for key: %s from cache' % key)
            return data
        except ObjectDoesNotExist:
            return None
    else:
        # logger.debug('GOT data for key: %s from cache' % key)
        return data
def get_self_application_library(username):
    """
    Get the ApplicationLibrary for this user

    Key: app_library:<username>
    """
    username = utils.make_keysafe(username)
    key = 'app_library:{0!s}'.format(username)
    data = cache.get(key)
    if data is None:
        try:
            data = models.ApplicationLibraryEntry.objects.filter(
                owner__user__username=username).filter(listing__is_enabled=True) \
                .filter(listing__is_deleted=False)

            cache.set(key, data)
            return data
        except ObjectDoesNotExist:
            return None
    else:
        return data
示例#8
0
def get_self_application_library(username, listing_type=None, folder_name=None):
    """
    Get the ApplicationLibrary for this user

    Cache:
        Key: app_library:<username>

    Args:
        username (str): username
        listing_type (str) optional: filter by listing type
        folder_name(str) optional: filter by folder_name

    return:
        Queryset(ApplicationLibraryEntry): User's Application Library

    """
    username = utils.make_keysafe(username)
    key = 'app_library({0!s}):{1!s}'.format(listing_type, username)
    data = cache.get(key)
    if data is None:
        try:
            data = models.ApplicationLibraryEntry.objects
            data = data.filter(owner__user__username=username)
            data = data.filter(listing__is_enabled=True)
            data = data.filter(listing__is_deleted=False)

            if listing_type:
                data = data.filter(listing__listing_type__title=listing_type)

            if folder_name:
                data = data.filter(folder=folder_name)

            cache.set(key, data)
            return data
        except ObjectDoesNotExist:
            return None
    else:
        return data
示例#9
0
 def test_make_keysafe_backtick(self):
     name = 'Unexpected`Name'
     key_name = utils.make_keysafe(name)
     self.assertEqual('unexpected`name', key_name)
示例#10
0
 def test_make_keysafe_doublequote(self):
     name = 'Robert "Bob" User'
     key_name = utils.make_keysafe(name)
     self.assertEqual('robert"bob"user', key_name)
示例#11
0
 def test_make_keysafe_period(self):
     name = 'Test User Jr.'
     key_name = utils.make_keysafe(name)
     self.assertEqual('testuserjr.', key_name)
示例#12
0
 def test_make_keysafe_unwanted(self):
     name = 'Test @string\'s !'
     key_name = utils.make_keysafe(name)
     self.assertEqual('teststrings', key_name)
示例#13
0
 def test_make_keysafe_backtick(self):
     name = 'Unexpected`Name'
     key_name = utils.make_keysafe(name)
     self.assertEqual('unexpected`name', key_name)
示例#14
0
 def test_make_keysafe_doublequote(self):
     name = 'Robert "Bob" User'
     key_name = utils.make_keysafe(name)
     self.assertEqual('robert"bob"user', key_name)
示例#15
0
 def test_make_keysafe_period(self):
     name = 'Test User Jr.'
     key_name = utils.make_keysafe(name)
     self.assertEqual('testuserjr.', key_name)
示例#16
0
 def test_make_keysafe_unwanted(self):
     name = 'Test @string\'s !'
     key_name = utils.make_keysafe(name)
     self.assertEqual('teststrings', key_name)