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 1 commit
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.
4 changes: 4 additions & 0 deletions wavepool/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ 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

6 changes: 5 additions & 1 deletion wavepool/templates/wavepool/newspost.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
<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>
</div>
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