Files
edx-platform/openedx/features/announcements/views.py
Josh McLaughlin 4d4b040517 Add dashboard announcements feature
- Add announcements view using JSX to the dashboard sidebar
- Create a new maintenance interface to edit and manage announcements
- Adds an override to main.html template to include new skip links
- Add plugins required for announcements to TinyMCE

This is motivated by a desire to have system wide messages for students
that show on the dashboard. Enabled with FEATURES['ENABLE_ANNOUNCEMENTS'].
Global staff are allowed to edit from the studio maintenance view.
2019-03-10 19:25:13 -07:00

37 lines
1.1 KiB
Python

"""
Views to show announcements.
"""
from django.conf import settings
from django.http import JsonResponse
from django.views.generic.list import ListView
from .models import Announcement
class AnnouncementsJSONView(ListView):
"""
View returning a page of announcements for the dashboard
"""
model = Announcement
object_list = Announcement.objects.filter(active=True)
paginate_by = settings.FEATURES.get('ANNOUNCEMENTS_PER_PAGE', 5)
def get(self, request, *args, **kwargs):
"""
Return active announcements as json
"""
context = self.get_context_data()
announcements = [{"content": announcement.content} for announcement in context['object_list']]
result = {
"announcements": announcements,
"next": context['page_obj'].has_next(),
"prev": context['page_obj'].has_previous(),
"start_index": context['page_obj'].start_index(),
"end_index": context['page_obj'].end_index(),
"count": context['paginator'].count,
"num_pages": context['paginator'].num_pages,
}
return JsonResponse(result)