def edit(request, talk): c = {} pagetitle = request.path[1:] pagetitle = pagetitle.rsplit('/')[0] pagedata = getlatestdata(pagetitle) if not pagedata: oldcontents = "" elif talk: oldcontents = pagedata.talkcontents else: oldcontents = pagedata.contents blankform = PageForm({'pagecontent': oldcontents}) if request.method == "POST": form = PageForm(request.POST) if form.is_valid(): if form.cleaned_data['redirect']: if not Page.objects.filter(title=form.cleaned_data['pagecontent']).exists(): return render_to_response('edit.html', {'title' : 'Editting '+pagetitle, 'form' : blankform, 'oldcontents': oldcontents}) newrev = Page(title=pagetitle) newestrev = Page.objects.filter(title=pagetitle).count() newrev.redirect = form.cleaned_data['redirect'] if pagedata: talkorno = (form.cleaned_data['pagecontent'], pagedata.contents, pagedata.talkcontents) else: talkorno = (form.cleaned_data['pagecontent'], "", "") if talk: newrev.talkcontents = talkorno[0] newrev.contents = talkorno[1] else: newrev.contents = talkorno[0] newrev.talkcontents = talkorno[2] newrev.revision = newestrev + 1 newrev.save() return render_to_response('base.html', {'title': 'XQZ Programming Wiki'}) c.update({'title' : "Editting "+pagetitle, 'form' : blankform, 'oldcontents': oldcontents}) return render_to_response('edit.html', c, context_instance=RequestContext(request))
import sys, os sys.path.append(os.getcwd() + '/web_app') #sesuai dengan mark directory as sources from app import create_app from models import Page, db, Role, User app = create_app() with app.app_context(): admin_role = Role() admin_role.name = 'admin' db.session.add(admin_role) db.session.commit() root = User() root.email = '*****@*****.**' root.password = '******' root.active = True root.roles.append(admin_role) db.session.add(root) page = Page() page.title = 'Halaman Awal' page.contents = "<h1>Selamat datang!</h1>" page.is_homepage = True db.session.add(page) db.session.commit()
# add to sys path python with take now directory and then add directory web_app import sys,os sys.path.append(os.getcwd() + '/web_app') #a ccording mark directory as sources from app import create_app from models import Page, db, Role, User app = create_app() with app.app_context(): # to add user as admin admin_role = Role() admin_role.name = 'admin' db.session.add(admin_role) db.session.commit() root = User() root.email = '*****@*****.**' root.password = '******' root.active = True root.roles.append(admin_role) db.session.add(root) page = Page() page.title = 'Homepage' page.contents = "<h1>Welcome to my website</h1>" page.is_homepage = True #objek db.session harus terikat pada suatu konteks apliksi flask yang berjalan db.session.add(page) db.session.commit()
import sys, os sys.path.append(os.getcwd() + '/web_app') #sesuai dgn mark directory sources from app import create_app from models import Page, db, Role, User app = create_app() with app.app_context(): admin_role = Role() admin_role.name = 'admin' db.session.add(admin_role) db.session.commit() root = User() root.email = '*****@*****.**' root.password = '******' root.active = True root.roles.append(admin_role) db.session.add(root) page = Page() page.title = 'Halaman Awal' page.contents = '<h1>Selamat Datang!</h1>' page.is_homepage = True db.session.add(page) db.session.commit()