コード例 #1
0
def index(request):
  issue = Issue.objects.last()

  # for each article with this issue id
  articles_in_issue = Article.objects.published().filter(issue=issue)
  data = {
    'blog': { },
    'sections': { },
    'issue': issue,
  }
  # Put articles into their respective sections
  for article in articles_in_issue:
    SectionName = str(article.section).lower()
    if SectionName not in data['sections']:
      data['sections'][SectionName] = [article]
    else:
        data['sections'][SectionName].append(article)
  data['sections']['art'] =  Image.objects.published().filter(issue=issue)

  # Randomly choice an article for every section
  for key in data['sections']:
    if data['sections'][key]:
      data['sections'][key]= random.choice(data['sections'][key])
  posts = Post.objects.all()
  recent_blog = list(reversed(sorted(posts, key=lambda i: i.created)))[:2 ]
  data['blog']['post1'] = recent_blog[0]
  data['blog']['post2'] = recent_blog[1]

  data['toplist'] = [{'title' : "article one", 'url' : "google.com", 'author' : "samantha"}, {'title' : "article two", 'url' : "google.com", 'author' : "cameron"}, {'title' : "article three", 'url' : "google.com", 'author' : "joe"}]

  data['ads'] = getAds('home')
  data['MEDIA_URL'] = settings.MEDIA_URL
  template_name = 'index.html'
  return render(request, template_name, data)
コード例 #2
0
ファイル: views.py プロジェクト: claireburst/advocateonline
def sections(request):
    section = request.path
    section = section.replace("/", "")

    # For all issues
    all_issues = query_all_issues_sorted()
    season = {'Winter': 0, 'Spring': 1, 'Commencement': 2, 'Fall': 3}
    featured_articles = list(Article.objects.published().filter(
        section__name=section).order_by('-publishDate')[:5])
    if section == "art":
        images = list(Image.objects.published().filter(
            section__name=section).order_by('-publishDate')[:5])
        if featured_articles:
            featured_articles = sorted(featured_articles + images,
                                       key=lambda x: x.publishDate)[5:]
        else:
            featured_articles = images
    data = {
        "section": section,
        "featured_articles": list(featured_articles)[:5],
        "ads": getAds(section),
        "issues": list(all_issues),
        "MEDIA_URL": settings.MEDIA_URL
    }
    template_name = 'section.html'
    return render(request, template_name, data)
コード例 #3
0
ファイル: views.py プロジェクト: claireburst/advocateonline
def homepage_redesign_jack(request):
    data = {}

    # current_issue
    issue = Issue.objects.last()
    data['issue_name'] = issue
    data['issue_cover_image'] = issue.cover_image
    data['issue_url'] = issue.get_absolute_url()
    # ads
    data['ads'] = getAds('home')

    all_articles = Article.objects.published()
    articles_in_issue = all_articles.filter(issue=issue)
    art_in_issue = Image.objects.published().filter(issue=issue)

    # from the blog
    posts = Post.objects.all()
    recent_blog = list(reversed(sorted(posts, key=lambda i: i.created)))[:2]

    # most_read (from Google Analytics)
    most_read_list = get_analytics(top=5)
    most_read = []
    for item in most_read_list:
        article, _ = item
        most_read.append(article)
    data['most_read'] = most_read

    # editors_picks (randomly generated)
    editors_picks = []
    editors_picks_article_indicies = random.sample(
        range(0,
              len(all_articles) - 1), 5)
    for index in editors_picks_article_indicies:
        editors_picks.append(all_articles[index])
    data['editors_picks'] = editors_picks

    # feature_1 - Any
    data['feature_1'] = articles_in_issue[1]

    # feature_2 - Blog
    data['feature_2'] = articles_in_issue[2]
    # feature_3 - Art
    data['feature_3'] = art_in_issue[0]
    # feature_4 - Any
    data['feature_4'] = articles_in_issue[3]

    # feature_5 - Any
    data['feature_5'] = recent_blog[0]

    # feature_6 - Any
    data['feature_6'] = all_articles[7]
    # feature_7 - Any
    data['feature_7'] = all_articles[15]
    # feature_8 - Any

    template_name = 'homepage_redesign_jack.html'
    return render(request, template_name, data)
コード例 #4
0
def main(request):
    """Main listing."""
    posts = Post.objects.all()
    all_posts_sorted = list(reversed(sorted(posts, key=lambda i: i.created)))
    blog_page = paginate_posts(request, all_posts_sorted)

    data = {'posts': blog_page, 'posts_data': list(blog_page)}
    template_name = 'blog.html'
    data['ads'] = getAds('blog')
    return render(request, template_name, data)
コード例 #5
0
def main(request):
    """Main listing."""
    posts = Post.objects.all()
    all_posts_sorted = list(reversed(sorted(posts, key=lambda i: i.created)))
    blog_page = paginate_posts(request, all_posts_sorted)

    data = {
        'posts': blog_page,
        'posts_data': list(blog_page)
    }
    template_name = 'blog.html'
    data['ads'] = getAds('blog')
    return render(request, template_name, data)
コード例 #6
0
ファイル: views.py プロジェクト: yek273/advocateonline
def index(request):
    issue = Issue.objects.last()

    # for each article with this issue id
    articles_in_issue = Article.objects.published().filter(issue=issue)
    data = {
        'blog': {},
        'sections': {},
        'issue': issue,
    }
    # Put articles into their respective sections
    for article in articles_in_issue:
        SectionName = str(article.section).lower()
        if SectionName not in data['sections']:
            data['sections'][SectionName] = [article]
        else:
            data['sections'][SectionName].append(article)
    data['sections']['art'] = Image.objects.published().filter(issue=issue)

    # Randomly choice an article for every section
    for key in data['sections']:
        if data['sections'][key]:
            data['sections'][key] = random.choice(data['sections'][key])
    posts = Post.objects.all()
    recent_blog = list(reversed(sorted(posts, key=lambda i: i.created)))[:2]
    data['blog']['post1'] = recent_blog[0]
    data['blog']['post2'] = recent_blog[1]

    data['toplist'] = [{
        'title': "article one",
        'url': "google.com",
        'author': "samantha"
    }, {
        'title': "article two",
        'url': "google.com",
        'author': "cameron"
    }, {
        'title': "article three",
        'url': "google.com",
        'author': "joe"
    }]

    data['ads'] = getAds('home')

    template_name = 'index.html'
    return render_to_response(template_name,
                              data,
                              context_instance=RequestContext(request))
コード例 #7
0
def sections(request):
  section = request.path
  section = section.replace("/","")

  # For all issues
  all_issues = query_all_issues_sorted()
  season = {'Winter': 0, 'Spring': 1, 'Commencement': 2, 'Fall': 3}
  featured_articles = list(Article.objects.published().filter(section__name =section).order_by('-publishDate')[:5])
  if section == "art":
      images = list(Image.objects.published().filter(section__name =section).order_by('-publishDate')[:5])
      if featured_articles:
        featured_articles = sorted(featured_articles + images, key = lambda x: x.publishDate)[5:]
      else:
        featured_articles = images
  data = {
    "section": section,
    "featured_articles": list(featured_articles)[:5],
    "ads": getAds(section),
    "issues": list(all_issues),
    "MEDIA_URL": settings.MEDIA_URL
  }
  template_name = 'section.html'
  return render(request, template_name, data)
コード例 #8
0
def homepage_redesign_jack(request):
  data = {}

  # current_issue
  CURRENT_ISSUE = "Summer 2018"

  for issue in Issue.objects.all():
    if str(issue) == CURRENT_ISSUE:
      break

  data['issue_name'] = issue
  data['issue_cover_image'] = issue.cover_image
  data['issue_url'] = issue.get_absolute_url()
  # ads
  data['ads'] = getAds('home')

  all_articles = Article.objects.published()
  articles_in_issue = all_articles.filter(issue=issue)
  art_in_issue = Image.objects.published().filter(issue=issue)

  # from the blog
  posts = Post.objects.all()
  recent_blog = list(reversed(sorted(posts, key=lambda i: i.created)))[:2 ]

  # most_read (from Google Analytics)
  most_read_list = get_analytics(top=5)
  most_read = []
  for item in most_read_list:
    article, _ = item
    most_read.append(article)
  data['most_read'] = most_read

  # editors_picks (randomly generated)
  editors_picks = []
  editors_picks_article_indicies = random.sample(range(0, len(all_articles) - 1), 5)
  for index in editors_picks_article_indicies:
    editors_picks.append(all_articles[index])
  data['editors_picks'] = editors_picks

  # feature_1 - Any
  data['feature_1'] = articles_in_issue[1]

  # feature_2 - Blog
  data['feature_2'] = articles_in_issue[2]
  # feature_3 - Art
  data['feature_3'] = art_in_issue[0]
  # feature_4 - Any
  data['feature_4'] = articles_in_issue[3]

  # feature_5 - Any
  data['feature_5'] = recent_blog[0]

  # feature_6 - Any
  data['feature_6'] = all_articles[7]
  # feature_7 - Any
  data['feature_7'] = all_articles[15]
  # feature_8 - Any


  template_name = 'homepage_redesign_jack.html'
  return render(request, template_name, data)