[web2py] Re: admin IDE for general use
Glad to help you, Lucas! $35 for the server with pg is really cool! -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: admin IDE for general use
oh, and btw, I have the whole server running off of a $35 Raspberry Pi 3b+, with PostGreSQL 9, Web2Py 2.17.2, and Nginx. I tricked the wifi of my institution to let the raspberry access and even though its a local address, students can access their code and view their results from whatever device in the classroom. cool, right? -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: admin IDE for general use
alright, thank you for your help. I've broken it down to its most basic level and its damn working. I'll post the essentials here. remember this is for a class to teach them the basics of programming. yeah, fun students... under the DAL I setup a simple table to store the code: NE = IS_NOT_EMPTY() db.define_table('code', Field('input_datetime', 'datetime', writable=False, readable=False, requires=NE, default=datetime.datetime.now()), Field('modified_datetime', 'datetime', writable=False, readable=False, requires=NE, default=datetime.datetime.now()), Field('user_id', db.auth_user, requires=IS_IN_DB(db, db.auth_user.id, '%(last_name)s, %(first_name)s (%(id)s)'), default=(auth.user.id if auth.is_logged_in() else None), label='User', writable=False, readable=False), Field('title', length="36", requires=NE, comment="title of the project code"), Field('description', length="256", requires=NE, comment="description of the project code"), Field('source_code', 'text'), Field('share_code', 'boolean', default=('T' if auth.has_membership( 'Administrator') else 'F')), format = '%(input_datetime)s') under the controller, I have two functions: @auth.requires_login() def project(): response.title = T("Python Project") pid = mcp.request_to_int(request.args[0], None) if (pid is None): pid = db.code.insert(share_code=(True if auth.has_membership( 'Administrator') else False)) redirect(URL(c="default", f="project", args=[pid])) else: sCode = db(db.code.id==pid).select().first() if (sCode.user_id <> auth.user.id): return dict(form="Error: User can only edit their own code.") frm = SQLFORM(db.code, record=pid, showid=True) """ if auth.has_membership('Administrator'): e = frm.element('input#code_share_code') e.update(_checked="checked") """ return dict(form=frm) @auth.requires_login() def ajaxSaveProject(): #return "%s" % request.vars id = mcp.request_to_int(request.vars.id, None) title = request.vars.title description = request.vars.description source_code = request.vars.source_code.strip() share_code = mcp.request_to_boolean(request.vars.share_code) #return "%s" % locals() try: modified_datetime = datetime.datetime.now() db(db.code.id==id).update(**locals()) except: return False return response.json(locals()) AND, finally, under the view, which is the most important: {{extend 'layout.html'}} {{block head}} div#form { border: 0px solid red; background-color: #fff; } table { width: 100%; } td { margin: 0px; padding: 0px; line-height: 24pt; border: 0px solid gray; } input[type=text] { margin: 1px 0px; padding: 1px 4px; } input[name=title] { max-width: 160px; } input[type=checkbox] { position: relative; margin: 2px; padding: 0px; } button#save { height: 20px; font-size: 10pt; font-weight: bold; line-height: 6px; } var editor; jQuery(function() { jQuery('button#save').click(function(obj) { obj.preventDefault(); console.log('button clicked'); doClickSave(); }); }); function doClickSave() { var data = editor.getValue(); //console.log(data); jQuery.post("{{=URL(c="default", f="ajaxSaveProject")}}", { 'id':jQuery( 'p#pid').html(), 'title':jQuery('input#code_title').val(), 'description': jQuery('input#code_description').val(), 'source_code':data, 'share_code': jQuery('input#code_share_code').prop('checked')}).done(function(t) { console.log(t); jQuery('td#msg').html('saved: '+t.modified_datetime); }); } jQuery(document).ready(function() { console.log('('+jQuery(window).width()+','+jQuery(window).height()+') jQuery.version: '+jQuery.fn.jquery); //console.log(jQuery('nav').height()+' ___ '+jQuery('footer').height()); editor = CodeMirror.fromTextArea(document.getElementById("code_i"), { lineNumbers: true, mode: { name: 'python', version: 2, singleLineStringErrors: false, }, indentUnit: 4, indentWithTabs: false, tabSize: 4, lineWrapping: true }); CodeMirror.commands.save = function() { doClickSave(); }; //console.log(jQuery(window).height()+" ___ "+jQuery('div#form').offset().top+" ___ "+jQuery('div#form').height()+" ___ "+jQuery('footer').height()); editor.setSize(jQuery(window).width() - 36, jQuery(window).height() - ( jQuery('div#form').offset().top + jQuery('div#form').height()) - jQuery( 'footer').height() - 12); }); {{end}} {{=form.custom.begin}} Project Title:{{=form.custom.widget.title }}Share Code?{{=form.custom.widget. share_code}}Save All Description:{{=form.custom. widget.description}} {{=form.custom.dspval.id}} {{=form.custom.dspval. source_code.strip() if (form.custom.dspval.source_code is not None) else "# -*- coding: utf-8 -*-\nimport mcp\n\ndef index():\n\treturn BODY(\"testing 1 2 3\")"}} {{=form.custom.end}} and
[web2py] Re: admin IDE for general use
Have a look at the manual at CM site. You don't have to do any DOM manipulation, CM does all that stuff. There are setValue and getValue CM-functions that you need to put the text into and get it back from the editor at any time. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: admin IDE for general use
well, I know that web2py is reading a py/txt file and uploading that into CodeMirror when the page is loaded to be edited under admin. then when saved it writes it back to the file to update it. I'd like to get the py/txt from a text field in PostgreSQL table. and then when its saved, it will update that text field in the PG table. can that be done with a web2py object or method that emulates the admin/CodeMirror without having to recreate all of the divs and textareas etc that I see when I inspect the admin code editor under safari or Firefox? -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: admin IDE for general use
> I'd like to be able to store and manage their code (text) as a text field > under PostgreSQL ... ... bring them to a default listing of their previous or current code > projects, click on a project or start a new project .. What do you mean under the code project - web2py app or just a python file with 'hello world'? And how does these files will be run - unpacked from PG to somewhere on the disk and just run? What does it mean 'output as standard HTML'? I can help you with client-side, but I don't figure out what your back-end will look like On Wednesday, November 14, 2018 at 7:04:43 PM UTC+3, lucas wrote: > > ok, I see that CodeMirror is the base editor. is there a web2py api of > some sort that would allow us to inject whatever code, from whatever > source, and then save and send that updated code to whatever source? so > that the entire functionality of our web2py editor is still the same and > working even with different set, get, and save methods? Lucas > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: admin IDE for general use
ok, I see that CodeMirror is the base editor. is there a web2py api of some sort that would allow us to inject whatever code, from whatever source, and then save and send that updated code to whatever source? so that the entire functionality of our web2py editor is still the same and working even with different set, get, and save methods? Lucas -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.