-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75efb20
commit 6477cc2
Showing
70 changed files
with
3,571 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# from django.contrib import admin | ||
|
||
# Register your models here. |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
> from django.urls import path | ||
|
||
> from field_timeline import views | ||
|
||
> urlpatterns = [ | ||
> path('json/', views.TimelineJSONView.as_view(), | ||
> name='timeline_json'), | ||
> ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
> import json | ||
|
||
> from django.http import HttpResponse | ||
> from django.views.generic import View | ||
|
||
> from field_wagtail.models import FieldTimelineEvent | ||
|
||
|
||
> class TimelineJSONView(View): | ||
> """ | ||
> Return events as JSON for async requests | ||
> """ | ||
|
||
> def get_events(self, request): | ||
> """ | ||
> Get events based on http request | ||
> Add them to the current context | ||
> :param request:request with filter args | ||
> :return: queryset of FieldTimelineEvent objects | ||
> """ | ||
|
||
# get event objects | ||
> events = FieldTimelineEvent.objects.all() | ||
# Add filtering | ||
> if 'category' in request.GET: | ||
! if len(request.GET['category']) > 0: | ||
! events.filter(category__category_name=request.GET['category']) | ||
> return events | ||
|
||
> def events_to_slides(self, events): | ||
> """Convert a FieldTimelineEvent object queryset into a list of | ||
> slides using FieldTimelineEvent.get_timeline_data() | ||
> :return: list of dicts for timeline slides | ||
> """ | ||
> slides = list() | ||
> for event in events: | ||
> slides.append(event.get_timeline_data()) | ||
> return slides | ||
|
||
> def get(self, request, *args, **kwargs): | ||
> events = self.get_events(request) | ||
> slides = list() | ||
> if events: | ||
> slides = self.events_to_slides(events) | ||
> timeline = {'events': slides} | ||
> return HttpResponse(json.dumps(timeline), | ||
> content_type='application/json') |
Oops, something went wrong.