Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Add site selections to the home page. #5

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions securethenews/home/migrations/0004_homepagesite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-08-25 23:12
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields


class Migration(migrations.Migration):

dependencies = [
('scans', '0005_auto_20160803_2254'),
('home', '0003_auto_20160816_2234'),
]

operations = [
migrations.CreateModel(
name='HomePageSite',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
('home_page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='sites', to='home.HomePage')),
('site', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pages', to='scans.Site')),
],
options={
'abstract': False,
'ordering': ['sort_order'],
},
),
]
33 changes: 23 additions & 10 deletions securethenews/home/models.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
from __future__ import absolute_import, unicode_literals

from django.db import models

from wagtail.wagtailcore.models import Page
from modelcluster.fields import ParentalKey
from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanel, InlinePanel

from scans.models import Site

class HomePage(Page):
main_title = models.CharField(max_length=50, default="Every news site should be secure.")
main_title = models.CharField(max_length=50, default='Every news site should be secure.')
sub_title = models.CharField(max_length=50, default="It's critical for both journalists and readers.")
how_header = models.CharField(max_length=50, default="Switching to HTTPS is easier than ever")
why_header = models.CharField(max_length=50, default="Encryption protects your readers")
how_body = RichTextField(default="Blah blah")
why_body = RichTextField(default="Blah blah")
how_header = models.CharField(max_length=50, default='Switching to HTTPS is easier than ever')
why_header = models.CharField(max_length=50, default='Encryption protects your readers')
how_body = RichTextField(default='Blah blah')
why_body = RichTextField(default='Blah blah')


content_panels = Page.content_panels + [
MultiFieldPanel([ FieldPanel('main_title'), FieldPanel('sub_title') ], "Main header"),
MultiFieldPanel([ FieldPanel('how_header'), FieldPanel('how_body') ], "How section"),
MultiFieldPanel([ FieldPanel('why_header'), FieldPanel('why_body') ], "Why section"),
MultiFieldPanel([ FieldPanel('main_title'), FieldPanel('sub_title') ], 'Main header'),
MultiFieldPanel([ FieldPanel('how_header'), FieldPanel('how_body') ], 'How section'),
MultiFieldPanel([ FieldPanel('why_header'), FieldPanel('why_body') ], 'Why section'),
InlinePanel('sites', label='Featured Sites'),
]

def get_context(self, request):
context = super(HomePage, self).get_context(request)
page_sites = self.sites.all().prefetch_related('site')
context['sites'] = [x.site for x in page_sites]
return context

class HomePageSite(Orderable, models.Model):
home_page = ParentalKey(HomePage, on_delete=models.CASCADE, related_name='sites')
site = models.ForeignKey(Site, on_delete=models.CASCADE, related_name='pages')
panels = [ FieldPanel('site') ]
6 changes: 3 additions & 3 deletions securethenews/home/templates/home/home_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ <h5 class="home-subhead">{{ page.sub_title }}</h5>
</div>

<div class="score-teaser">
<span class="graded-news-org">New York Times <span class="grade grade-a">A+</span></span>
<span class="graded-news-org">Wall Street Journal <span class="grade grade-b">B</span></span>
<span class="graded-news-org">Buzzfeed <span class="grade grade-b">B-</span></span>
{% for site in sites %}
<span class="graded-news-org">{{ site.name }} <span class="grade grade-a">{#{ site.grade }#}A+</span></span>
{% endfor %}
</div>

<div class="align-center">
Expand Down
34 changes: 10 additions & 24 deletions securethenews/home/templates/leaderboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,16 @@
</tr>
</thead>
<tbody>
<tr>
<td>New York Times</td>
<td class="grade-a">92%</td>
<td class="grade-b">95%</td>
<td class="grade-a">91%</td>
<td class="grade-a">89%</td>
<td><span class="grade grade-a">A+</span></td>
</tr>
<tr>
<td>Wall Street Journal</td>
<td class="grade-a">92%</td>
<td class="grade-b">95%</td>
<td class="grade-f">42%</td>
<td class="grade-a">89%</td>
<td><span class="grade grade-b">B-</span></td>
</tr>
<tr>
<td>Buzzfeed</td>
<td class="grade-a">92%</td>
<td class="grade-b">95%</td>
<td class="grade-f">0%</td>
<td class="grade-f">10%</td>
<td><span class="grade grade-f">F</span></td>
</tr>
{% for site in sites %}
<tr>
<td>{{ site.name }}</td>
<td class="grade-a">92%</td>
<td class="grade-b">95%</td>
<td class="grade-a">91%</td>
<td class="grade-a">89%</td>
<td><span class="grade grade-a">A+</span></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>