It needs cleanup.

import glob
import os
import zipfile
import sys

def find_path(files):
    files2 = [x for x in files if not x.endswith('/')]
    paths2 = set([x[:x.rfind('/')+1] for x in files2])
    ell = min([len(x) for x in paths2])
    path = list(set([x for x in paths2 if len(x)==ell]))[0]
    return path

def head(name,styles):
    title = '<title>{{=response.title or request.application}}</
title>'
    items = '\n'.join(["{{response.files.append(URL
(request.application,'static','p\
lugin_layouts/layouts/%s/%s'))}}" % (name,style) for style in styles])
 
loc="""<style>
.flash
{
    z-index:
2;
    position:
absolute;
    top:
0px;
    right:
20%;
    width:
60%;
    height:
50px;
    opacity:
0.75;
    margin: 0
auto;
    text-align:
center;
    clear:
both;
    border: 1px #000000
solid;
    color:
black;
    font-size:
12pt;
    padding: 100px 10px 10px
10px;
    cursor:
pointer;
    background:
white;

}
div.error
{
    background-color:
red;
    color:
white;
    padding:
3px;
}
</style>"""
    return "\n%s\n%s\n{{include 'web2py_ajax.html'}}\n%s" %
(title,items,loc)

def content():
    return """<div class="flash">{{=response.flash or ''}}</div>
{{include}}"""

for file in glob.glob('layouts/*'):
    name=file[9:]
    print name
    folder='layouts/%s/' % name
    try:
        from BeautifulSoup import BeautifulSoup as BS
        soup = BS(open(folder+'index.html','rb').read())
        styles = [x['href'] for x in soup.findAll('link')]
        soup.find('head').contents=BS(head(name,styles))
        try:
            soup.find('h1').contents=BS('{{=response.title or
request.application}}')
            soup.find('h2').contents=BS("{{=response.subtitle or
'=response.subtitle'}}")
        except:
            pass
        for x in (soup.find('div',id='menu'),
                  soup.find('div',{'class':'menu'}),
                  soup.find('div',id='nav'),
                  soup.find('div',{'class':'nav'})):
            if x:
                x.contents=BS('{{=MENU(response.menu)}}')
                break
        done=False
        for x in (soup.find('div',id='content'),
                  soup.find('div',{'class':'content'}),
                  soup.find('div',id='main'),
                  soup.find('div',{'class':'main'})):
            if x:
                x.contents=BS(content())
                done=True
                break
        if done:
            page = soup.prettify()
            page = re.compile("\s*\{\{=response\.flash or ''\}\}
\s*",re.MULTILINE).sub("{{=response.flash or ''}}",page)
            open('layouts/'+name+'.html','wb').write(page)
            print 'DONE'
        else:
            raise Exception
    except Exception, e:
        print e
        continue



On Nov 5, 11:38 pm, DenesL <[email protected]> wrote:
> Wow!
> A slice with the procedure and code perhaps?  It would encourage more
> layouts.
> Now we are going to need a layout repository too...
>
> On 6 nov, 00:09, mdipierro <[email protected]> wrote:
>
> > I downloaded multiple layouts from the web with a free Artistic
> > License and used a script in BeautifulSoup to replace the header, menu
> > and content with web2py tags. Then I rearranged the files in the
> > proper web2py locations and stuck everything under one app.
>
> > It took about 2hrs. One can do better with more time. About 50% of the
> > layouts would need some manual tweaks. I have another 1000 layouts
> > that I did not process.
>
> > Massimo
>
> > On Nov 5, 11:03 pm, Graham Dumpleton <[email protected]>
> > wrote:
>
> > > For the curious, would you like to explain the procedure you, or
> > > whoever, went about to generate this.
>
> > > Ie., where were original layouts/stylesheets obtained from, what
> > > script or whatever was used to convert/package them into form
> > > understood by web2py.
>
> > > Sorry if the answer is obvious but I am ignorant of what web2py does
> > > internally and so as an outsider would like short dumb persons
> > > explanation.
>
> > > Thanks.
>
> > > Graham
>
> > > On Nov 6, 3:56 pm, mdipierro <[email protected]> wrote:
>
> > > >http://web2py.com/layouts/plugin_layouts/index?apply=EfflorescenceOrange
>
> > > > - Try it online first.
> > > > - Then download the plugin (it is 30MB and it includes 408 layouts
> > > > already customized for web2py, sort of, + images and css).
> > > > - Apply the plugin on top of an existing app using admin (requires
> > > > 1.71.2 or higher)
>
> > > > From a distribution point of view it would be better to distribute one
> > > > layout at the time, but from the user point of view, it is cool to
> > > > have all of them together.
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to