Skip to content

Commit

Permalink
Merge pull request #86 from b-m-f/urlparse-for-building-url
Browse files Browse the repository at this point in the history
Updates build_get_articles_url to use urllib.parse.urlencode
  • Loading branch information
b-m-f committed Jun 19, 2019
2 parents 61b14f5 + ba00e8c commit 91fa0ae
Show file tree
Hide file tree
Showing 6 changed files with 1,829 additions and 150 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
@@ -1,3 +1,4 @@
2.0.4: Internal API refactor
2.0.3: Add pagination for author endpoint
2.0.2: Update article context to return complete article
2.0.0: Wordpress api optimisation, flask support and added tag endpoint.
Expand Down
27 changes: 16 additions & 11 deletions canonicalwebteam/blog/common_view_logic.py
Expand Up @@ -21,7 +21,7 @@ def get_index(self, page=1, category="", enable_upcoming=True):
upcoming = []
featured_articles = []
if page == "1":
featured_articles, total_pages = api.get_articles(
featured_articles, _ = api.get_articles(
tags=self.tag_ids,
tags_exclude=self.excluded_tags,
page=page,
Expand All @@ -42,13 +42,14 @@ def get_index(self, page=1, category="", enable_upcoming=True):
categories=[events["id"], webinars["id"]],
)

articles, total_pages = api.get_articles(
articles, metadata = api.get_articles(
tags=self.tag_ids,
tags_exclude=self.excluded_tags,
exclude=[article["id"] for article in featured_articles],
page=page,
categories=[category_id],
)
total_pages = metadata["total_pages"]

context = get_index_context(
page,
Expand Down Expand Up @@ -79,13 +80,14 @@ def get_group(self, group_slug, page=1, category_slug=""):
if category_slug:
category = api.get_category_by_slug(category_slug)

articles, total_pages = api.get_articles(
articles, metadata = api.get_articles(
tags=self.tag_ids,
tags_exclude=self.excluded_tags,
page=page,
groups=[group.get("id", "")],
categories=[category.get("id", "")],
)
total_pages = metadata["total_pages"]

context = get_group_page_context(page, articles, total_pages, group)
context["title"] = self.blog_title
Expand All @@ -96,11 +98,12 @@ def get_group(self, group_slug, page=1, category_slug=""):
def get_topic(self, topic_slug, page=1):
tag = api.get_tag_by_slug(topic_slug)

articles, total_pages = api.get_articles(
articles, metadata = api.get_articles(
tags=self.tag_ids + [tag["id"]],
tags_exclude=self.excluded_tags,
page=page,
)
total_pages = metadata["total_pages"]

context = get_topic_page_context(page, articles, total_pages)
context["title"] = self.blog_title
Expand All @@ -111,12 +114,13 @@ def get_upcoming(self, page=1):
events = api.get_category_by_slug("events")
webinars = api.get_category_by_slug("webinars")

articles, total_pages = api.get_articles(
articles, metadata = api.get_articles(
tags=self.tag_ids,
tags_exclude=self.excluded_tags,
page=page,
categories=[events["id"], webinars["id"]],
)
total_pages = metadata["total_pages"]

context = get_index_context(page, articles, total_pages)
context["title"] = self.blog_title
Expand All @@ -126,7 +130,7 @@ def get_upcoming(self, page=1):
def get_author(self, username, page=1):
author = api.get_user_by_username(username)

articles, metadata = api.get_articles_with_metadata(
articles, metadata = api.get_articles(
tags=self.tag_ids,
tags_exclude=self.excluded_tags,
page=page,
Expand All @@ -143,7 +147,7 @@ def get_author(self, username, page=1):
return context

def get_latest_news(self):
latest_pinned_articles = api.get_articles(
latest_pinned_articles, _ = api.get_articles(
tags=self.tag_ids,
exclude=self.excluded_tags,
page=1,
Expand All @@ -155,7 +159,7 @@ def get_latest_news(self):
if latest_pinned_articles:
per_page = 4

latest_articles = api.get_articles(
latest_articles, _ = api.get_articles(
tags=self.tag_ids,
exclude=self.excluded_tags,
page=1,
Expand Down Expand Up @@ -193,7 +197,7 @@ def get_archives(self, page=1, group="", month="", year="", category=""):
after = datetime(year=year, month=1, day=1)
before = datetime(year=year, month=12, day=31)

articles, metadata = api.get_articles_with_metadata(
articles, metadata = api.get_articles(
tags=self.tag_ids,
tags_exclude=self.excluded_tags,
page=page,
Expand Down Expand Up @@ -228,11 +232,12 @@ def get_feed(self, uri):
def get_tag(self, slug, page=1):
tag = api.get_tag_by_slug(slug)

articles, total_pages = api.get_articles(
articles, metadata = api.get_articles(
tags=self.tag_ids + [tag["id"]],
tags_exclude=self.excluded_tags,
page=page,
)
total_pages = metadata["total_pages"]

context = get_topic_page_context(page, articles, total_pages)
context["title"] = self.blog_title
Expand Down Expand Up @@ -341,7 +346,7 @@ def get_article_context(article, related_tag_ids=[], excluded_tags=[]):
tags = logic.get_embedded_tags(article["_embedded"])
is_in_series = logic.is_in_series(tags)

all_related_articles, total_pages = api.get_articles(
all_related_articles, _ = api.get_articles(
tags=[tag["id"] for tag in tags],
tags_exclude=excluded_tags,
per_page=3,
Expand Down

0 comments on commit 91fa0ae

Please sign in to comment.