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 all 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
15 changes: 15 additions & 0 deletions wavepool/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ class NewsPostForm(forms.ModelForm):
model = NewsPost
fields = '__all__'

def clean(self, *args, **kwargs):
""" cleans form data
"""
# user selected "is cover story checkbox":
if self.data.get('is_cover_story') == 'on':
all_newsposts = NewsPost.objects.all()
# for each newspost, if it is the current cover story and NOT this newspost anyways,
# unset it as cover story and save
for n in all_newsposts:
if n.is_cover_story == True:
if n != self.instance:
n.is_cover_story = False
n.save()

This comment was marked as resolved.

return super(NewsPostForm, self).clean(*args, **kwargs)


class NewsPostAdmin(admin.ModelAdmin):
form = NewsPostForm
Expand Down
12 changes: 11 additions & 1 deletion wavepool/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ def teaser(self):

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

This comment was marked as resolved.

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

def tags(self):
return [
Expand Down
17 changes: 14 additions & 3 deletions wavepool/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@ def front_page(request):
archive: the rest of the newsposts, sorted by most recent
"""
template = loader.get_template('wavepool/frontpage.html')
cover_story = NewsPost.objects.all().order_by('?').first()
top_stories = NewsPost.objects.all().order_by('?')[:3]
other_stories = NewsPost.objects.all().order_by('?')
cover_story = None
top_stories = []
other_stories = []
newsposts = NewsPost.objects.all().order_by('publish_date')

This comment was marked as resolved.


i = 1
for n in newsposts:
if n.is_cover_story == True:
cover_story = n
if i < 3:

This comment was marked as resolved.

top_stories.append(n)
i = i + 1
else:
other_stories.append(n)
Comment on lines +22 to +30

This comment was marked as resolved.


context = {
'cover_story': cover_story,
Expand Down