Re: [Dorset] Tools / Methods to Add Content to Web Pages for Non-Techies

2016-11-25 Thread Ralph Corderoy
Hi Terry,

> > If it's JSON, use a Python library to read and write JSON, not do ad
> > hoc parsing with string functions.  That should also ensure correct
> > encoding of characters, e.g. `£', depending what staff enter.
>
> OK.  My problem at the moment is that I simply re-used the code I
> found on the Internet

I thought the page for that was called "Javascript programmer", but that
must just be the pejorative term I've seen.  :-)
https://en.wikipedia.org/wiki/Copy_and_paste_programming

> I really only have a vague idea what JSON is. Some learning needed
> here :-)

Programming language tend to have two data structures:  an array, and a
record or aggregate, e.g. C's struct.  JSON is a readable textual
representation of those borrowed from Javascript.  http://json.org/

> > For the non-JSON, you might still want a text file to hold the
> > "database", e.g. Python's CSV-handling module
>
> OK.  More learning needed :-)

Or switch that to JSON too so you've just got the one format.

> I was thinking of a stand-alone Python program or script that would do
> all the functions that I described.  Clearly, if you're working on a
> website; use a web based solution!  Doh ;-(

Yes, you've got the web server that receives GET and POST HTTP requests
from a browser and replies, typically with the HTTP header and then the
HTML.  The browser renders this and it all repeats on the next user
action.  The "program" is spread across those two entities, each taking
turns to do some work.

Except you've the possibility of multiple browsers so you've a "program"
running for each of them in parallel and need to decide what state for
each program the server holds, if any, and what gets handed on with each
communication.  It could be the form's contents is the entire state
(other than authentication that might be in a HTTP cookie) and the
server just treats the last set received as the set to store.  This
matters if two parties are editing at the same time.  You may have a
human procedure in place to stop this.

> > > 7.  Overwrite the file in the www folder.
> >
> > Maybe.  If you do then write a new version and "move" it over the
> > existing one as that's an atomic filesystem operation.  Otherwise
> > you might hit a problem half-way through writing and trash the file
> > being used.
>
> I'll need to work out exactly what that means.

Regardless of the program, it's the kernel that controls access to
files.  A program can ask it to do

fd = creat("foo", 0666);
write(fd, "hello world!\n", 13);
write(fd, "bye.\n", 5);
close(fd);

If something goes wrong in the midst of that the original content of foo
has been lost because any existing ./foo is truncated to zero bytes by
the creat().

rename(2) is a request to the kernel to rename a reference to an inode,
e.g. file.  You produce foo.new first, if that all goes well then you
rename foo.new to foo.  foo still exists beforehand.  It will either
succeed, or fail leaving the original foo behind.  It's "atomic" and
can't be broken down into steps, some of which may succeed.

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2016-12-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR

Re: [Dorset] Tools / Methods to Add Content to Web Pages for Non-Techies

2016-11-22 Thread PeterM


  

If it's JSON, use a Python library to read and write JSON, not do ad hoc
parsing with string functions.  That should also ensure correct encoding
of characters, e.g. `£', depending what staff enter.

OK.  My problem at the moment is that I simply re-used the code I found on the
Internet, because it did exactly what I wanted it to do.  I really only have a
vague idea what JSON is. Some learning needed here :-)

For a learning experience, If you have firefox, you can export your 
favourites as a .json file and look at their form.


Probably keep aspirin handy while you do it.

Peter



--
Next meeting:  Bournemouth, Tuesday, 2016-12-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR

Re: [Dorset] Tools / Methods to Add Content to Web Pages for Non-Techies

2016-11-21 Thread Terry Coles
On Monday, 21 November 2016 17:56:10 GMT Ralph Corderoy wrote:
> You could ditch the database and use text files for your simple needs.
> Concentrate more on how to serve up a web page with a filled-in form and
> process the result.  Flask is a lot more than accessing a database, and
> it's those other bits you need: HTTP serving, HTML generation.

OK.

> You web server should be running your code at the root of your site's
> directory so `change directory' navigation will probably be required.

Your correction noted.
 
> If it's JSON, use a Python library to read and write JSON, not do ad hoc
> parsing with string functions.  That should also ensure correct encoding
> of characters, e.g. `£', depending what staff enter.

OK.  My problem at the moment is that I simply re-used the code I found on the 
Internet, because it did exactly what I wanted it to do.  I really only have a 
vague idea what JSON is. Some learning needed here :-)

> For the non-JSON, you might still want a text file to hold the
> "database", e.g. Python's CSV-handling module, and produce the HTML that
> you're already using from that when you need it using Flask's templates.

OK.  More learning needed :-)

> Present a form with the current values, allowing them to be: edited,
> deleted, perhaps blank entries are purged; added, a blank entry at the
> bottom can be filled in; moved, maybe their ordinal position, 10, 20,
> 30..., can be edited.  A nicer UI comes with using Javascript, but you
> may want to ignore that for the small use it will get.

This where my mind-set  has let me down (that of an applications / systems 
engineer who wrote test programs using spaghetti code 20-30 years ago).

I was thinking of a stand-alone Python program or script that would do all the 
functions that I described.  Clearly, if you're working on a website; use a 
web based solution!  Doh ;-(

> That's the HTML form.

Of course it is; see above :-)

> Process the HTTP POST from the user's browser when they submit the form
> using Flask to gather their new definition.  You need to learn about the
> difference between a GET and POST HTTP request from the browser.

Again, my mindset!  The ability to use forms on a website has been around 
almost since the founding of the world (or the web at least), I just never 
thought of it...

> > 7.  Overwrite the file in the www folder.
> 
> Maybe.  If you do then write a new version and "move" it over the
> existing one as that's an atomic filesystem operation.  Otherwise you
> might hit a problem half-way through writing and trash the file being
> used.

I'll need to work out exactly what that means.

> Or the editing page can show a preview of how it looks so far and the
> public only see the new one on a "finished" commit action by the staff
> member.  Depends if staff need to edit whilst the system's being used.
> 
> > 8.  For the Audio Guide, upload the new MP3 file.
> 
> Forms can upload files.

Yes, and I've done it many times.

> I suggest an account per user rather than shared access.  This makes it
> easier to see who did want.  You can log it.  Or copy the "before"
> version before moving the new one over the top.

Good idea.

Summing up on your advice, we can now update our design to home in the your 
suggested approach, since it is the obvious choice.  Thanks for that.

My problem now is to wade through the Tutorial(s) to get up to speed with 
these techniques.  I'll make a start now, since we're still waiting for some 
hardware, but the priority is the bells, so I may not get far on this for a 
few weeks or months.

I'll report on progress (with more questions I expect) in due course.

-- 



Terry Coles

-- 
Next meeting:  Bournemouth, Tuesday, 2016-12-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR

Re: [Dorset] Tools / Methods to Add Content to Web Pages for Non-Techies

2016-11-21 Thread Ralph Corderoy
I wrote:
> You web server should be running your code at the root of your site's
> directory so `change directory' navigation will probably be required.

...probably NOT be required.

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2016-12-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR

Re: [Dorset] Tools / Methods to Add Content to Web Pages for Non-Techies

2016-11-21 Thread Ralph Corderoy
Hi Terry,

> Hmmm.  That site seems to provide some pretty comprehensive
> information, especially if you are fairly aux faix with database
> development.  Unfortunately, I'm not ;-)

You could ditch the database and use text files for your simple needs.
Concentrate more on how to serve up a web page with a filled-in form and
process the result.  Flask is a lot more than accessing a database, and
it's those other bits you need: HTTP serving, HTML generation.

> 1.  Prompt the user for the admin login and navigate to the www
> folder.

You web server should be running your code at the root of your site's
directory so `change directory' navigation will probably be required.

> 2.  Read the relevant file into a variable.
>
> 3.  Use the Python Find Function to identify the relevant list, then
> iterate through it to copy the list part only into an array (pretty
> much all of the .json file).

If it's JSON, use a Python library to read and write JSON, not do ad hoc
parsing with string functions.  That should also ensure correct encoding
of characters, e.g. `£', depending what staff enter.

For the non-JSON, you might still want a text file to hold the
"database", e.g. Python's CSV-handling module, and produce the HTML that
you're already using from that when you need it using Flask's templates.

> 4.  Print the array and prompt the user for input, eg 'Modify' etc,
> using the array index to identify the element containing each item in
> the list.

Present a form with the current values, allowing them to be: edited,
deleted, perhaps blank entries are purged; added, a blank entry at the
bottom can be filled in; moved, maybe their ordinal position, 10, 20,
30..., can be edited.  A nicer UI comes with using Javascript, but you
may want to ignore that for the small use it will get.

> 5  Provide a function that will allow the user to edit the contents of
> the array element being modified.

That's the HTML form.

> 6.  Write the modified array back into the string.

Process the HTTP POST from the user's browser when they submit the form
using Flask to gather their new definition.  You need to learn about the
difference between a GET and POST HTTP request from the browser.

> 7.  Overwrite the file in the www folder.

Maybe.  If you do then write a new version and "move" it over the
existing one as that's an atomic filesystem operation.  Otherwise you
might hit a problem half-way through writing and trash the file being
used.

Or the editing page can show a preview of how it looks so far and the
public only see the new one on a "finished" commit action by the staff
member.  Depends if staff need to edit whilst the system's being used.

> 8.  For the Audio Guide, upload the new MP3 file.

Forms can upload files.

I suggest an account per user rather than shared access.  This makes it
easier to see who did want.  You can log it.  Or copy the "before"
version before moving the new one over the top.

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2016-12-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR

Re: [Dorset] Tools / Methods to Add Content to Web Pages for Non-Techies

2016-11-21 Thread Terry Coles
On Sunday, 20 November 2016 18:34:28 GMT Ralph Corderoy wrote:
> Sounds like each of your two existing web sites could do with an "admin"
> entry point where one of the users known to it can edit the data it's
> serving.

Yes that is exactly what I had in mind.

> > If I had a starter (preferably in Python), I'd definitely give it a
> > go.
> 
> http://flask.pocoo.org/ has a reputation for being a small lightweight
> not-too-magical library for writing backends for web sites in Python.
> Looking through its tutorial might give you an idea if that's the route
> you want to take.

Hmmm.  That site seems to provide some pretty comprehensive information, 
especially if 
you are fairly aux faix with database development.  Unfortunately, I'm not ;-)

Our two websites do not use databases.  In the case of the Audio Guide, I've 
based it on 
the Player provided by Neils Harbo at:

http://nielsharbo.dk/?pageId=resources=audioplayer=en[1] 

If you look, you will see that the references to the MP3 files are stored in 
the HTML in the 
form:

 http://www.nielsharbo.dk/test/audioplayer/life.mp3; 
data-oggfallback="http://
www.nielsharbo.dk/test/audioplayer/life.ogg">"Life is..."

In the case of the Children's quiz, the Questions and Answers are held in a 
.json file:

{"quizlist":[
{
"question":"Portuguese is spoken in ___",
"option1":"Brazil",
"option2":"Argentina",
"option3":"Ecuador"
},
{
"question":"What is the capital of Peru?",
"option1":"Lima",
"option2":"Bogota",
"option3":"San Juan"
},
{
"question":"Which country is long and thin?",
"option1":"Chile",
"option2":"Uruguay",
"option3":"Colombia"
}
]
}

(I've lost the link to the site that provided that code, but it was free.)

So (at an extremely high level), I think that what I need to do is:

1.  Prompt the user for the admin login and navigate to the www folder.

2.  Read the relevant file into a variable.

3.  Use the Python Find Function to identify the relevant list, then iterate 
through it to copy 
the list part only into an array (pretty much all of the .json file).

4.  Print the array and prompt the user for input, eg 'Modify' etc, using the 
array index to 
identify the element containing each item in the list.

5  Provide a function that will allow the user to edit the contents of the 
array element 
being modified.

6.  Write the modified array back into the string.

7.  Overwrite the file in the www folder.

8.  For the Audio Guide, upload the new MP3 file.

Clearly, there will be a need for some safeguards so that the user doesn't 
break things, 
but since the data to be changed is all in simple strings, I see no need to 
rewrite what I 
have to put the data into a database.  String handling I've done (in C and some 
other 
languages).  Database queries have always seemed a bit of a black art to simple 
old me :-)

Any comments?

-- 



Terry Coles


[1] http://nielsharbo.dk/?pageId=resources=audioplayer=en
-- 
Next meeting:  Bournemouth, Tuesday, 2016-12-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR

Re: [Dorset] Tools / Methods to Add Content to Web Pages for Non-Techies

2016-11-20 Thread Ralph Corderoy
Hi Terry,

> Has anyone any ideas?

Sounds like each of your two existing web sites could do with an "admin"
entry point where one of the users known to it can edit the data it's
serving.

> If I had a starter (preferably in Python), I'd definitely give it a
> go.

http://flask.pocoo.org/ has a reputation for being a small lightweight
not-too-magical library for writing backends for web sites in Python.
Looking through its tutorial might give you an idea if that's the route
you want to take.

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2016-12-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR

[Dorset] Tools / Methods to Add Content to Web Pages for Non-Techies

2016-11-20 Thread Terry Coles
Hi,

I'm working on the Wimborne Model Town stuff again.  The Bells project is 
currently awaiting hardware deliveries and other dependencies, so I've 
returned to our two Web projects; the Audio Guide and the Children's Quiz.

Both of these facilities have been based on code that I culled from the net 
and both use basic HTML and Javascript techniques to create an online MP3 
player with menus for the former and an online randomised question and answer 
system with scoring for the latter.

Both of these systems currently work and lack only styling and content at this 
stage.  Styling will be decided in the coming months, but content will be an 
ongoing requirement that ideally should be added by the non-techie WMT Staff.  
The content is also likely to change as the years go by, as are the Staff.

So, the requirement is to provide the WMT Staff with this capability.  Our 
draft design discusses a number of ideas, including (somehow) making use of 
the current Content Management System used for the WMT Webite or using an 
ordinary PC-based Web Development tool as well as various more primitive 
techniques.  We have some special constraints apart from the skill level:

1.  The users will access the system via a local Wireless Network which is not 
connected to the Internet.  The Staff should ideally access the system for 
updates in the same way, but a local monitor and keyboard / mouse combination 
could be used.

2.  It will be running on a Raspberry Pi, so any tools designed to run locally 
must be compiled for the Pi.

3.  Being non-techie, the WMT Staff may well be put off if they are required 
to do such mystical things such as SSH or FTP.  (There will be a User Manual.)

My preference is to write some kind of script which locates the content 
references in the relevant file and then displays them in a kind of menu, with 
the options 'Add Content', 'Delete Content' etc.  However, I'm aware that this 
would have to run fairly seamlessly, preferably from a Windows PC logged into 
the local network.  Also, I've never done anything quite like that before, so 
I'm in new territory for me.  The content references are held in well 
structured lists in each case, so I'm sure that the technique is doable (apart 
from anything else, this is exactly what my software engineering colleagues 
used to do when I was still working).

Has anyone any ideas?  If I had a starter (preferably in Python), I'd 
definitely give it a go.

-- 



Terry Coles

-- 
Next meeting:  Bournemouth, Tuesday, 2016-12-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR