def changePage(request, newPage): dajax = Dajax() if (newPage == PAGES_FULL[0]): template = PAGES_LOCATIONS[0] #print fetch_user_puzzles(request) puzzles = fetch_user_puzzles(request.user) render = render_to_string(template, {'puzzles': puzzles, 'empty':len(puzzles)==0}, context_instance=RequestContext(request)) elif (newPage == PAGES_FULL[1]): template = PAGES_LOCATIONS[1] puzzles = fetch_user_puzzles(request.user) render = render_to_string(template, {'puzzles': puzzles, 'empty':len(puzzles)==0}, context_instance=RequestContext(request)) elif (newPage == PAGES_FULL[2]): template = PAGES_LOCATIONS[2] list = PuzzlePiece.objects.filter(needs_help=True) result = [x.puzzle for x in list] render = render_to_string(template, {'list':result}, context_instance=RequestContext(request)) elif (newPage == PAGES_FULL[3]): template = PAGES_LOCATIONS[3] template = PAGES_LOCATIONS[3] dajax = Dajax() list = Photo.objects.filter(user=request.user) pictureGrid = PictureGrid(list).getGridAsString(); render = render_to_string(template, {'form': get_profile_form(request), 'pictureGrid': pictureGrid}, context_instance=RequestContext(request)) elif (newPage == PAGES_FULL[4]): logout(request) dajax.redirect("/accounts/login",delay=0) return dajax.json() dajax.assign('#page-container', 'innerHTML', render) return dajax.json()
def get_start_puzzle_content(request): openPuzzlePieces = fetch_all_open_puzzle_pieces(request.user) render = render_to_string("puzzle/startPuzzleContent.html", {"openPuzzlePieces":openPuzzlePieces}, context_instance=RequestContext(request)) dajax = Dajax() dajax.assign('#start-puzzle-panel', 'innerHTML', render) dajax.script(render_to_string("puzzle/uploadButton.html", {"style":"", "id":"start-puzzle-file-uploader", "label":"Upload a new photo for a new Puzzle", "action":"upload/newPuzzle", "onCompleteCallback":"onComplete: new_puzzle_started,"})); dajax.script("initialize_start_puzzle()") return dajax.json()
def send_form(request, form): dajax = Dajax() form = UserProfileForm(form) if form.is_valid(): user_profile = UserProfile.objects.get(user=request.user.id) user = User.objects.get(id = request.user.id) user.first_name = form.cleaned_data['first_name'] user.last_name = form.cleaned_data['last_name'] user_profile.location = form.cleaned_data['location'] user.save() user_profile.save() dajax.remove_css_class('#my_form input', 'error') else: dajax.remove_css_class('#my_form input', 'error') for error in form.errors: dajax.add_css_class('#id_%s' % error, 'error') return dajax.json()