From 16c91c1902f065c6d9b12a5c89c04d6aef620291 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Thu, 20 Jan 2011 09:37:31 -0500 Subject: [PATCH] Reduced number of queries for BlogView.get_entries_by_tag. Corrected waldo's AccountMultiView.has_valid_account() method, which had holdovers from the user_form/profile_form distinction. --- contrib/penfield/models.py | 19 ++++++++++--------- contrib/waldo/models.py | 15 +++------------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/contrib/penfield/models.py b/contrib/penfield/models.py index b19d3a1..4191463 100644 --- a/contrib/penfield/models.py +++ b/contrib/penfield/models.py @@ -179,16 +179,17 @@ class BlogView(MultiView, FeedMultiViewMixin): return entries, context def get_entries_by_tag(self, request, tag_slugs, extra_context=None): - tags = [] - for tag_slug in tag_slugs.replace('+', '/').split('/'): - if tag_slug: # ignore blank slugs, handles for multiple consecutive separators (+ or /) - try: - tag = self.blog.entry_tags.get(slug=tag_slug) - except: - raise Http404 - tags.append(tag) - if len(tags) <= 0: + tag_slugs = tag_slugs.replace('+', '/').split('/') + tags = self.blog.entry_tags.filter(slug__in=tag_slugs) + + if not tags: raise Http404 + + # Raise a 404 on an incorrect slug. + found_slugs = [tag.slug for tag in tags] + for slug in tag_slugs: + if slug and slug not in found_slugs: + raise Http404 entries = self.blog.entries.all() for tag in tags: diff --git a/contrib/waldo/models.py b/contrib/waldo/models.py index e3dd079..c537ba9 100644 --- a/contrib/waldo/models.py +++ b/contrib/waldo/models.py @@ -379,18 +379,9 @@ class AccountMultiView(LoginMultiView): return self.manage_account_page.render_to_response(request, extra_context=context) def has_valid_account(self, user): - user_form, profile_form = self.get_account_forms() - forms = [] - forms.append(user_form(data=get_field_data(user, self.user_fields))) - - if profile_form is not None: - profile = self.account_profile._default_manager.get_or_create(user=user)[0] - forms.append(profile_form(data=get_field_data(profile, self.account_profile_fields))) - - for form in forms: - if not form.is_valid(): - return False - return True + form = self.account_form(user, {}) + form.data = form.initial + return form.is_valid() def account_required(self, view): def inner(request, *args, **kwargs): -- 2.20.1