Created
January 11, 2013 17:54
-
-
Save felipe-prenholato/4512664 to your computer and use it in GitHub Desktop.
rascunhos para uma app em cima do cepbr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_cep(cep): | |
| # cache = django cache | |
| # CepCache = model para cachear os ceps | |
| cached = cache.get(cep) | |
| if not cached: | |
| try: | |
| dbcep = CepCache.objects.get(cep=cep) | |
| except CepCache.DoesNotExist: | |
| from cepbr import Cep | |
| dbcep = CepCache.objects.create(**Cep(cep)) | |
| finally: | |
| cache.set(cep, dbcep.asdict(), 60 * 60 * 48) | |
| return dbcep.asdict() | |
| else: | |
| return cached |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment