def update_p_dict(): p_dict = {'tags': [], 'first_name': [], 'last_name': [], 'email': []} try: search_objects = ( Contact.objects().item_frequencies(field='tags'), Contact.objects().item_frequencies(field='name.first_name'), Contact.objects().item_frequencies(field='name.last_name'), Contact.objects().item_frequencies(field='email')) except: return 'database error' object_names = ['tags', 'first_name', 'last_name', 'email'] i = 0 for objects in search_objects: for key, value in objects.iteritems(): p_dict[object_names[i]].append(key) i += 1 session['p_dict'] = p_dict
def tags(tag): contacts = Contact.objects(tags=tag) return render_template('tags.html', contacts=contacts, tag=tag)