def blog_save_location(country, city): try: location = Location.objects.get(country=ucwords(country), city=ucwords(city)) except Location.DoesNotExist: location = Location(country=country, city=city) location.save() # For unittest maybe create duplicate location except Location.MultipleObjectsReturned: location = Location.objects.filter(country=ucwords(country), city=ucwords(city)).order_by('-id')[0] return location
def blog_mood(request, mood): title = ucwords(mood) try: fmood = dict([(m[1], m[0]) for m in MOOD_CHOICES])[title] except KeyError: #render empty page return render(request, 'blog/blog_list_empty.html', {'filter': {'mood': mood}}) return blog_all(request, title, {'mood': fmood}, {'mood': mood}, reverse('blog_mood', args=[mood]), color='purple')
def ucwords_tag(string): return ucwords(string)