Пример #1
0
    def find(self, path, all=False):
        """
        Serve from STATIC_ROOT, even in DEBUG mode. See also:
            https://docs.djangoproject.com/en/1.8/ref/contrib/staticfiles/#static-file-development-view
        """
        matches = []

        root, path = os.path.split(path)
        for user in self.users:
            if hash_email(user.email) == path:
                # XXX this is a realy dirty hack!
                match = os.path.join(settings.STATIC_ROOT, root, path)
                if not all:
                    return match
                matches.append(match)
        return matches
Пример #2
0
    def list(self, ignore_patterns):
        """
        List avatars for all users.
        """
        for user in self.users:
            for res in (80, 160, 320):
                # create storage, try to get an Gravatar image
                storage = GravatarStorage(user.email, resolution=res)
                try:
                    storage.load()
                except GravatarUnknownError:
                    continue
                yield hash_email(user.email), storage

                # If we are here, the Gravatar image has been saved to a static
                # storage, so we register the email address to correspond with
                # a valid image.

                # XXX we have to check for dry_runs
                try:
                    user.avatar.updated(storage.email)
                except Avatar.DoesNotExist:
                    avatar = Avatar.objects.create(
                        user=user, received_for=storage.email)
 def test_hash_email(self):
     self.assertEqual(
         utils.hash_email('*****@*****.**'),
         '80c66bdd90ae7fd4378cef780422fe428ee7fb526301f7b236113c4ece3be146')