Skip to content
This repository was archived by the owner on Jun 16, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified db.sqlite3
Binary file not shown.
2 changes: 1 addition & 1 deletion fixtures/test_fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"pk": 3,
"fields": {
"title": "Study: Skateboarding fosters 21st century, SEL skills",
"body": "<p>With skateboarding making its Olympic debut this year, the study contributes to a shifting perception of skateboarders from loitering youth who don\u2019t respect public property to resilient problem solvers who are eager to apply their skills to areas such as filmmaking, photography, music production and apparel design. </p>\r\n\r\n\u201cSkills and social connections obtained through skateboarding appear to have \u2018exchange value,\u2019\u201d the authors write. \u201cFor example, we learned of skaters receiving mentorship on school-related matters, support on class projects, and assistance on completing homework through skateboarding connections.\u201d</p>\r\n\r\n<p>One skateboard shop where that is taking place is the Garage Board Shop in East Los Angeles, where students from as many as 15 area schools skate in to complete their homework in exchange for time in the skate park behind the retail floor. And some schools are beginning to add after-school skateboarding classes and even competitive teams.</p>\r\n\r\n<p>Students, the authors write, have learned to navigate different attitudes among school leaders toward their sport.</p>\r\n\r\n<p>\u201cIn some instances, skaters had to be strategic when bringing skateboards to school; in others, skating was supported by school personnel,\u201d they write. \u201cSkaters knew which teachers would not mind if they stored their boards in their classrooms, and which teachers would hassle them.\u201d</p>",
"body": "<p>With skateboarding making its Olympic debut this year, the study contributes to a shifting perception of skateboarders from loitering youth who don\u2019t respect public property to resilient problem solvers who are eager to apply their skills to areas such as filmmaking, photography, music production and apparel design. </p>\r\n\r\n<p>\u201cSkills and social connections obtained through skateboarding appear to have \u2018exchange value,\u2019\u201d the authors write. \u201cFor example, we learned of skaters receiving mentorship on school-related matters, support on class projects, and assistance on completing homework through skateboarding connections.\u201d</p>\r\n\r\n<p>One skateboard shop where that is taking place is the Garage Board Shop in East Los Angeles, where students from as many as 15 area schools skate in to complete their homework in exchange for time in the skate park behind the retail floor. And some schools are beginning to add after-school skateboarding classes and even competitive teams.</p>\r\n\r\n<p>Students, the authors write, have learned to navigate different attitudes among school leaders toward their sport.</p>\r\n\r\n<p>\u201cIn some instances, skaters had to be strategic when bringing skateboards to school; in others, skating was supported by school personnel,\u201d they write. \u201cSkaters knew which teachers would not mind if they stored their boards in their classrooms, and which teachers would hassle them.\u201d</p>",
"source": "https://www.educationdive.com/news/study-skateboarding-fosters-21st-century-sel-skills/573068/",
"is_cover_story": false,
"publish_date": "2020-02-28"
Expand Down
9 changes: 8 additions & 1 deletion wavepool/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ def teaser(self):

@property
def source_divesite_name(self):
return 'Industry Dive'
# Implementation based on naive assumption that URL is in a
# <protocol>://www.<hostname>.xyz/asdf-asdf-asdf format
hostname = self.source.split('/')[2].split('.')[1]
return DIVESITE_SOURCE_NAMES[hostname]
Comment on lines +35 to +38
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source_divesite_name was hardcoded before. I have modified this to resolve the hostname from the URL and then return the lookup from DIVESITE_SOURCE_NAMES

Copy link
Author

@codein codein Feb 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i really like and prefer an implementation similar to ref in branch set_coverstory_for_front_page

    def source_divesite_name(self):
        return 'Industry Dive'
        """ Return the real divesite source name for the newspost's source
        """
        source_dive = 'Industry Dive'

        url_parts = self.source.split('/')
        dive_domain = url_parts[2]
        domain_parts = dive_domain.split('.')
        dive_domain = domain_parts[1]
        if dive_domain in DIVESITE_SOURCE_NAMES:
            return DIVESITE_SOURCE_NAMES[dive_domain]
        return source_dive

However i didn't want to just copy it


def tags(self):
return [
'HR', 'Diversity & Inclusion', 'Culture'
]

@property
def edit_url(self):
return reverse('admin:wavepool_newspost_change', args=[self.pk])
Comment on lines +44 to +47
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here i Introduced a edit_url property that is eventually used in newspost.html to surface the edit URL to CMS users

2 changes: 1 addition & 1 deletion wavepool/templates/wavepool/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link href="{% static 'bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'app.css' %}" rel="stylesheet">
<title>Wavepool | Industry Dive</title>
<title>{{ newspost.title }} | Wavepool | Industry Dive</title>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes was made to include the newspost.title in the template as required by test_newspost_page_title_attribute

<link rel="shortcut icon" type="/image/png" href="{% static 'favicon.ico' %}"/>
</head>
<body>
Expand Down
13 changes: 10 additions & 3 deletions wavepool/templates/wavepool/newspost.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@
<div class="col-2"></div>
</div>
<div class="newspost-detail">
<div class="row"><a href=""><button>edit</button></a></div>
{% if is_staff %}
<div class="row">
<a id="edit-link" href="{{ newspost.edit_url }}"><button>edit</button></a>
</div>
{% endif %}
Comment on lines +22 to +26
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional template shows edit_url property only when a logged in user has is_staff flag set. The is_staffflag is set into context in the view.py

<div class="row">
<h1>{{ newspost.title }}<span class="pubdate">{{newspost.publish_date}}</span></h1>
<h1 id="newspost-title">{{ newspost.title }}</h1>
</div>
<div class="row">
<span class="pubdate">{{newspost.publish_date}}</span>
</div>
<div class="row"><a href="{{newspost.source}}" target="_blank">See the live story at {{newspost.source_divesite_name}}</a></div>
<div class="row newspost-body">
<div id="newspost-body" class="row newspost-body">
{{ newspost.body|safe }}
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion wavepool/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ def test_newspost_page_content(self):
"""
newsposts = NewsPost.objects.all()
for newspost in newsposts:

page = self.client.get(newspost.url)
page_html = BeautifulSoup(page.content, 'html.parser')
rendered_title = page_html.find('h1', {'id': 'newspost-title'}).text
rendered_body = page_html.find('div', {'id': 'newspost-body'}).text
newspost_body = BeautifulSoup(newspost.body, 'html.parser').text
self.assertEqual(rendered_title, newspost.title)
self.assertEqual(self._clean_text(rendered_body), self._clean_text(newspost.body))
self.assertEqual(self._clean_text(rendered_body), self._clean_text(newspost_body))

def test_newspost_body_render(self):
""" Verify that newsposts rendered at their URL do not display raw HTML to the screen
Expand Down
4 changes: 3 additions & 1 deletion wavepool/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def front_page(request):
def newspost_detail(request, newspost_id):
template = loader.get_template('wavepool/newspost.html')
newspost = NewsPost.objects.get(pk=newspost_id)
# import pdb; pdb.set_trace()
context = {
'newspost': newspost
'newspost': newspost,
'is_staff': request.user.is_staff
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we set the is_staff flag based on current requesting user

}

return HttpResponse(template.render(context, request))
Expand Down