def get_category_articles_json(self, number_to_return): # If more articles in a category than your max number, get a random X number of the articles, ordered by postdate # Always get first article for the category (that one will be starting point for non-dynamic part of page always) first_article = self.get_starting_article() category_articles = Article.objects.filter(is_active=1).filter(category=self).order_by('postdate_key') category_articles_1 = category_articles.exclude(id=first_article.id).order_by('?')[(number_to_return - 1):] category_articles = category_articles.exclude(id__in=category_articles_1) category_articles_json = utils.articles_to_json(category_articles) """ category_articles_json = '[' for i in range(0, len(category_articles)): related_articles = category_articles[i].get_related_articles(2) if i != 0: category_articles_json += ',' try: category_articles_json += ('{"title":"' + category_articles[i].title.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "url_slug":"' + category_articles[i].url_slug + '", "post_image":"' \ + category_articles[i].post_image_url + '", "description":"' \ + category_articles[i].description.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "related_title_1":"' + related_articles[0].title.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "related_url_slug_1":"' + related_articles[0].url_slug \ + '", "related_title_2":"' + related_articles[1].title.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "related_url_slug_2":"' + related_articles[1].url_slug + '"}') except: category_articles_json += ('{"title":"' + category_articles[i].title.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "url_slug":"' + category_articles[i].url_slug + '", "post_image":"' \ + category_articles[i].post_image_url + '", "description":"' \ + category_articles[i].description.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "related_title_1":"", "related_url_slug_1":"", "related_title_2":"", "related_url_slug_2":""}') category_articles_json += ']' """ return category_articles_json
def home_article_change(): home_articles = Article.objects.filter(is_active=1).exclude(category__in=[17]).order_by('postdate_key') home_articles_json = utils.articles_to_json(home_articles) """ home_articles_json = '[' for i in range(0, len(home_articles)): related_articles = home_articles[i].get_related_articles(2) if i != 0: home_articles_json += ',' if len(related_articles) >= 2: home_articles_json += ('{"title":"' + home_articles[i].title.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "url_slug":"' + home_articles[i].url_slug + '", "post_image":"' \ + home_articles[i].post_image_url + '", "description":"' \ + home_articles[i].description.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "related_title_1":"' + related_articles[0].title.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "related_url_slug_1":"' + related_articles[0].url_slug \ + '", "related_title_2":"' + related_articles[1].title.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "related_url_slug_2":"' + related_articles[1].url_slug + '"}') if len(related_articles) == 1: home_articles_json += ('{"title":"' + home_articles[i].title.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "url_slug":"' + home_articles[i].url_slug + '", "post_image":"' \ + home_articles[i].post_image_url + '", "description":"' \ + home_articles[i].description.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "related_title_1":"' + related_articles[0].title.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "related_url_slug_1":"' + related_articles[0].url_slug \ + '", "related_title_2":"", "related_url_slug_2":""}') if len(related_articles) == 0: home_articles_json += ('{"title":"' + home_articles[i].title.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "url_slug":"' + home_articles[i].url_slug + '", "post_image":"' \ + home_articles[i].post_image_url + '", "description":"' \ + home_articles[i].description.replace('"', '\\\\"').replace('\'', '\\\'') \ + '", "related_title_1":"", "related_url_slug_1":"", "related_title_2":"", "related_url_slug_2":""}') home_articles_json += ']' """ return {'home_articles_json': home_articles_json}