def pub_view(request, name=None): print name if PubLink.objects.filter(name=name).exists(): p = PubLink.objects.get(name=name) t= TutorialConstructor(p.tutorial.json_data) html_data = t.construct_html() return render(request, 'tb/live.html', {'html_data':html_data}) else: pass
def pub_view(request, name=None): print name if PubLink.objects.filter(name=name).exists(): p = PubLink.objects.get(name=name) t = TutorialConstructor(p.tutorial.json_data) html_data = t.construct_html() return render(request, 'tb/live.html', {'html_data': html_data}) else: pass
def live(request): if request.user.is_authenticated(): payload = {} tutorial = Tutorial.objects.get(user=request.user) json_raw = tutorial.json_data t = TutorialConstructor(content=json_raw) json_data = t.printall() html_data = t.construct_html() payload.update({'html_data':html_data}) return render(request, 'tb/live.html',payload) else: request.session['message'] = 'Please Login to view your tutorial' return render(request, 'tb/live.html',payload )
def live(request): if request.user.is_authenticated(): payload = {} tutorial = Tutorial.objects.get(user=request.user) json_raw = tutorial.json_data t = TutorialConstructor(content=json_raw) json_data = t.printall() html_data = t.construct_html() payload.update({'html_data': html_data}) return render(request, 'tb/live.html', payload) else: request.session['message'] = 'Please Login to view your tutorial' return render(request, 'tb/live.html', payload)
def home_auth(request): if not request.user.is_authenticated(): return redirect(home) payload = {} if 'message' in request.session: message= request.session['message'] request.session['message'] = False payload.update({'message':message}) tutorial = Tutorial.objects.get(user=request.user) publink = PubLink.objects.get(tutorial=tutorial) json_raw = tutorial.json_data t = TutorialConstructor(content=json_raw) json_data = t.printall() html_data = t.construct_html() number = len(json_raw['requirements']) +1 step_count = len(json_raw['steps']) + 1 initial_title, initial_header = json_raw['title'], json_raw['header'] steps = ["{}. {}".format(i+1, x['title']) for i, x in enumerate(json_raw['steps'])] imagesteps = [] substeps = [] codesteps = [] for i, step in enumerate(json_raw['steps']): for v, sub in enumerate(step['sub_steps']): substeps.append("{}. {} | {}. {}".format(i+1, step['title'], v+1, sub)) for i, step in enumerate(json_raw['steps']): for v, sub in enumerate(step['code_assets']): codesteps.append("{}. {} | {}. {}".format(i+1, step['title'], v+1, sub['code_description'])) for i, step in enumerate(json_raw['steps']): for v, sub in enumerate(step['images']): imagesteps.append("{}. {} | {}. {}".format(i+1, step['title'], v+1, sub['image_description'])) addsubstepForm = AddSubStep(steps = steps) deletesubstepForm = DeleteSubStep(steps = substeps) deletecodeForm = DeleteCode(steps = codesteps) deleteimageForm = DeleteImage(steps = imagesteps) addtitleForm = AddTitle(initial = {'title':initial_title} ) addheaderForm = AddHeader(initial = {'header':initial_header}) addrequirementForm = AddRequirement(number = number, initial = {'index':number}) addstepForm = AddStep(step_count = step_count, initial = {'index':step_count}) addcodeexampleForm = AddCode(steps = steps) addimageForm = AddImage(steps = steps) deleterequirementForm= DeleteRequirement(choices = map(lambda x: x['requirement'], json_raw['requirements'])) deletestepForm = DeleteStep(choices = map(lambda x: x['title'], json_raw['steps'])) #divide payload.update({'html_data':html_data, 'json_data':json_data, 'tutorial_name':tutorial.name,'addtitleForm':addtitleForm, 'addheaderForm': addheaderForm}) payload.update({'addrequirementForm':addrequirementForm}) payload.update({'deleterequirementForm':deleterequirementForm}) payload.update({'addstepForm':addstepForm}) payload.update({'deletestepForm':deletestepForm}) payload.update({'addsubstepForm':addsubstepForm}) payload.update({'deletesubstepForm':deletesubstepForm}) payload.update({'addcodeexampleForm':addcodeexampleForm}) payload.update({'deletecodeForm':deletecodeForm}) payload.update({'addimageForm':addimageForm}) payload.update({'deleteimageForm':deleteimageForm}) payload.update({'publinkName':publink.name}) return render(request, 'tb/home_auth.html',payload )
def home_auth(request): if not request.user.is_authenticated(): return redirect(home) payload = {} if 'message' in request.session: message = request.session['message'] request.session['message'] = False payload.update({'message': message}) tutorial = Tutorial.objects.get(user=request.user) publink = PubLink.objects.get(tutorial=tutorial) json_raw = tutorial.json_data t = TutorialConstructor(content=json_raw) json_data = t.printall() html_data = t.construct_html() number = len(json_raw['requirements']) + 1 step_count = len(json_raw['steps']) + 1 initial_title, initial_header = json_raw['title'], json_raw['header'] steps = [ "{}. {}".format(i + 1, x['title']) for i, x in enumerate(json_raw['steps']) ] imagesteps = [] substeps = [] codesteps = [] for i, step in enumerate(json_raw['steps']): for v, sub in enumerate(step['sub_steps']): substeps.append("{}. {} | {}. {}".format(i + 1, step['title'], v + 1, sub)) for i, step in enumerate(json_raw['steps']): for v, sub in enumerate(step['code_assets']): codesteps.append("{}. {} | {}. {}".format(i + 1, step['title'], v + 1, sub['code_description'])) for i, step in enumerate(json_raw['steps']): for v, sub in enumerate(step['images']): imagesteps.append("{}. {} | {}. {}".format( i + 1, step['title'], v + 1, sub['image_description'])) addsubstepForm = AddSubStep(steps=steps) deletesubstepForm = DeleteSubStep(steps=substeps) deletecodeForm = DeleteCode(steps=codesteps) deleteimageForm = DeleteImage(steps=imagesteps) addtitleForm = AddTitle(initial={'title': initial_title}) addheaderForm = AddHeader(initial={'header': initial_header}) addrequirementForm = AddRequirement(number=number, initial={'index': number}) addstepForm = AddStep(step_count=step_count, initial={'index': step_count}) addcodeexampleForm = AddCode(steps=steps) addimageForm = AddImage(steps=steps) deleterequirementForm = DeleteRequirement( choices=map(lambda x: x['requirement'], json_raw['requirements'])) deletestepForm = DeleteStep( choices=map(lambda x: x['title'], json_raw['steps'])) #divide payload.update({ 'html_data': html_data, 'json_data': json_data, 'tutorial_name': tutorial.name, 'addtitleForm': addtitleForm, 'addheaderForm': addheaderForm }) payload.update({'addrequirementForm': addrequirementForm}) payload.update({'deleterequirementForm': deleterequirementForm}) payload.update({'addstepForm': addstepForm}) payload.update({'deletestepForm': deletestepForm}) payload.update({'addsubstepForm': addsubstepForm}) payload.update({'deletesubstepForm': deletesubstepForm}) payload.update({'addcodeexampleForm': addcodeexampleForm}) payload.update({'deletecodeForm': deletecodeForm}) payload.update({'addimageForm': addimageForm}) payload.update({'deleteimageForm': deleteimageForm}) payload.update({'publinkName': publink.name}) return render(request, 'tb/home_auth.html', payload)