def read_story(request, story_id=None, piece_id=None, slug=None): """ Read Story Templates: :"banyan/inner.html" """ template_name = "banyan/inner.html" res = StoryResource() request_bundle = res.build_bundle(request=request) try: storyObj = res.cached_obj_get(request_bundle, **{"bnObjectId": story_id}) bundle = res.build_bundle(obj=storyObj, request=request) story_json = res.serialize(None, res.full_dehydrate(bundle, for_list=False), "application/json") story = json.loads(story_json) except: raise Http404 ''' TO DO: Permission error seperately ''' # if story is None or story.get('read', False) is not True: # return render_to_response( "banyan/permission_error.html", context_instance = RequestContext( request ) ) pieces = story.get('pieces', []) piece = None next_piece = None previous_piece = None if len(pieces): if piece_id is None: next_piece = pieces[0] else: piece_id = int(piece_id) # This is a piece view for index, piece in enumerate(pieces): if piece.get('bnObjectId') == piece_id: if index > 0: previous_piece = pieces[index - 1] if index < len(pieces) - 1: next_piece = pieces[index + 1] break return render_to_response(template_name, { 'story': story, 'previous_piece': previous_piece, 'piece': piece, 'next_piece': next_piece, }, context_instance=RequestContext(request))
def read_story(request, story_id=None, piece_id=None, slug=None): """ Read Story Templates: :"banyan/inner.html" """ template_name = "banyan/inner.html" res = StoryResource() request_bundle = res.build_bundle(request=request) try: storyObj = res.cached_obj_get(request_bundle, **{"bnObjectId":story_id}) bundle = res.build_bundle(obj=storyObj, request=request) story_json = res.serialize(None, res.full_dehydrate(bundle, for_list=False), "application/json") story = json.loads(story_json) except: raise Http404 ''' TO DO: Permission error seperately ''' # if story is None or story.get('read', False) is not True: # return render_to_response( "banyan/permission_error.html", context_instance = RequestContext( request ) ) pieces = story.get('pieces', []) piece = None next_piece = None previous_piece = None if len(pieces): if piece_id is None: next_piece = pieces[0] else: piece_id = int(piece_id) # This is a piece view for index, piece in enumerate(pieces): if piece.get('bnObjectId') == piece_id: if index > 0: previous_piece = pieces[index-1] if index < len(pieces)-1: next_piece = pieces[index + 1] break return render_to_response(template_name, {'story': story, 'previous_piece':previous_piece, 'piece': piece, 'next_piece':next_piece,}, context_instance=RequestContext(request))
def home(request): template_name = "banyan/index.html" res = StoryResource() request_bundle = res.build_bundle(request=request) queryset = res.cached_obj_get_list(request_bundle) bundles = [] for obj in queryset.iterator(): bundle = res.build_bundle(obj=obj, request=request) bundles.append(res.full_dehydrate(bundle, for_list=True)) list_json = res.serialize(None, bundles, "application/json") list_json = json.loads(list_json) paginator = Paginator(list_json, settings.API_DEFAULT_ITEMS_PER_PAGE) page = request.GET.get('page') try: stories = paginator.page(page) except PageNotAnInteger: stories = paginator.page(1) except EmptyPage: stories = paginator.page(paginator.num_pages) return render_to_response(template_name, {'stories': stories}, context_instance=RequestContext(request))
def home(request): template_name = "banyan/index.html" res = StoryResource() request_bundle = res.build_bundle(request=request) queryset = res.cached_obj_get_list(request_bundle) bundles = [] for obj in queryset.iterator(): bundle = res.build_bundle(obj=obj, request=request) bundles.append(res.full_dehydrate(bundle, for_list=True)) list_json = res.serialize(None, bundles, "application/json") list_json = json.loads(list_json) paginator = Paginator(list_json, settings.API_DEFAULT_ITEMS_PER_PAGE) page = request.GET.get('page') try: stories = paginator.page(page) except PageNotAnInteger: stories = paginator.page(1) except EmptyPage: stories = paginator.page(paginator.num_pages) return render_to_response( template_name, {'stories':stories}, context_instance = RequestContext( request ) )
from django.conf.urls import patterns, url, include from .views import save_story, new_story_json, new_chapter_json, draft_view, story_view, story_detail from .annotations.views import annotations from .boxes.views import boxes from tastypie.api import Api from api import StoryResource v1_api = Api(api_name='v1') v1_api.register(StoryResource()) urlpatterns = patterns( '', # maploom url(r'^story/chapter/new$', new_chapter_json, name='new_chapter'), url(r'^story/new$', 'geonode.maps.views.new_map', {'template': 'composer/editor.html'}, name='new_story'), url(r'^story$', new_story_json, name='new_story_json'), url(r'^story/(?P<storyid>[^/]+)/save$', save_story, name='save_story'), url(r'^api/', include(v1_api.urls)), url(r'^story/(?P<story_id>[^/]+)/draft$', draft_view, {'template': 'composer/editor.html'}, name='composer-draft-view'), url(r'^maps/(?P<mapid>[^/]+)/boxes$', boxes, name='boxes'), url(r'^maps/(?P<mapid>[^/]+)/annotations', annotations, name='annotations'), url(r'^story/(?P<story_id>\d+)/?$', story_detail, name='story_detail'), url(r'^story/(?P<storyid>\d+)/view$', story_view, name='story_view'),