diff --git a/wavepool/admin.py b/wavepool/admin.py index 8843f79..d2f70dc 100644 --- a/wavepool/admin.py +++ b/wavepool/admin.py @@ -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() + return super(NewsPostForm, self).clean(*args, **kwargs) + class NewsPostAdmin(admin.ModelAdmin): form = NewsPostForm diff --git a/wavepool/models.py b/wavepool/models.py index a466962..d6e933a 100644 --- a/wavepool/models.py +++ b/wavepool/models.py @@ -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: + 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 [ diff --git a/wavepool/views.py b/wavepool/views.py index d3adb14..1a17455 100644 --- a/wavepool/views.py +++ b/wavepool/views.py @@ -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') + + i = 1 + for n in newsposts: + if n.is_cover_story == True: + cover_story = n + if i < 3: + top_stories.append(n) + i = i + 1 + else: + other_stories.append(n) context = { 'cover_story': cover_story,