def EditCard (request, gslug, id): # logger.info("---------------") # send the card's data as json s = get_object_or_404(Card, guide__slug=gslug, id=id) cr = CardResource() if not s.is_floating_card: prev_card = s.guide.get_prev_card(s) next_card = s.guide.get_next_card(s) card_bundle= cr.build_bundle(obj=s, request=request) card_json= cr.serialize(request, cr.full_dehydrate(card_bundle), 'application/json') #with newer version, full dehyrate ur_bundle # logger.info(card_json) mr = MediaElementResource() if s.primary_media is not None: primary_media_bundle= mr.build_bundle(obj=s.primary_media, request=request) primary_media_json = mr.serialize(request, mr.full_dehydrate(primary_media_bundle),'application/json' ) #and all the cards in the guide all_cards = get_list_or_404(Card, guide__slug=gslug) c=CardResource() card_list = [] for card in all_cards: # card_list.append({'title':card.title,'resource_uri': c.get_resource_uri(card), 'id':card.id}) if card.primary_media: card_list.append({'title':card.title, 'primary_media': card.primary_media.file.thumb_url,'resource_uri': c.get_resource_uri(card), 'id':card.id}) else: card_list.append({'title':card.title,'resource_uri': c.get_resource_uri(card), 'id':card.id}) all_cards_json = simplejson.dumps(card_list) #should get the guide instead, that has the relevant card info and would be more consistant TODO delete above and impliment the below # guide = get_object_or_404(Guide, slug=gslug) # g = GuideResource() # guide_json = g.serialize(None, g.full_dehydrate(guide), 'application/json') return render_to_response("create/edit_card.html", locals(), context_instance=RequestContext(request))
def resource_uri(self): r = CardResource() # cardresource is imported at the end of this file return r.get_resource_uri(self)