Hi All,

in the next view there are two forms "form" and one loaded using 
LOAD('gestione'....)

If I use the form pointing 
http://<host>/<app>/gestione/notizie_parametri/5/notizie  

everything works fine but not using LOAD('gestione', 
'notizie_parametri.load', args=(request.args(0, cast=int), 
request.args(1)), ajax=True)

I have set the "formname" parameter  but does not seem to be enough.

Could you please tell me where I'm wrong

Regards

Fabrizio

#############################################################################################
into "notizie_edit.html" view.
The post variables are sent to the first form "form"


"notizie_edit.html"
{{extend 'layout_gestione.html'}}
<div class="row">
    <div class="col-md-8">
         <h1>Modifica Notizia</h1>
    </div>
    <div class="col-md-4">
        <h1>Parametri</h1>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        {{=form.custom.begin}}
        <div>{{=form.custom.widget.titolo}}</div>
        <div>{{=form.custom.widget.testo}}</div>
        <div>{{=form.custom.widget.img}}</div>
        {{=immagine}}
        <div>{{=form.custom.widget.autore}}</div>
        {{=form.custom.submit}}
        {{=form.custom.end}}
    </div>
    <div class="col-md-4">
        {{=LOAD('gestione', 'notizie_parametri.load', args=(request.args(0, 
cast=int), request.args(1)), ajax=True)}}
    </div>
</div>

#############################################################################################
"notizie_parametri.load"
{{#extend 'layout_gestione.html'}}
<div>
    <hr>
    {{=time_range.custom.begin}}
    <div>
        <h4>Stato Pubblicazione</h4>
        {{=status}}
    </div>
    <div>
        <h4>Comandi Pubblicazione</h4>
        <br>
        {{=publish}}
        {{=depublish}}
        {{=highlight}}
        &nbsp;|&nbsp;
        {{=delete}}
        {{=archive}}
    </div>
    <div>
        <h4>Pubblicazione Programmata</h4>
        {{=time_range.custom.widget.time_start}}
        {{=time_range.custom.widget.time_end}}
        {{=time_range.custom.submit}}
        {{=time_range.custom.end}}
    </div>
</div>

<script>
var delUrl = {{=URL('gestione', 'notizie_parametri', args=[request.args(0), 
'notizie'])}};
function confirmDelete(delUrl) {
    //if (confirm("Are you sure you want to delete")) {
    if (confirm("Sei sicuro di voler cancellare la notizia?")) {
        document.location = delUrl;
    }
}
</script>




#############################################################################################
This is the controller:
gestione.py
....
def notizie_edit():
    record_id = request.args(0, cast=int)
    table = db[request.args(1)]
    row = db(table.id == record_id).select('img').first()
    form = SQLFORM(table,
                   record=record_id,
                   editable=True,
                   create=False,
                   user_signature=False,
                   )
    if form.process(formname='notizie_edit').accepted:
        redirect(URL('default', 'notizie_articolo', args=record_id))
    immagine = IMG(_src=URL('default', 'download', args=row.img), 
_style='width:150px')
    form.next = URL('gestione', 'notizie')
    return locals()

def notizie_parametri():
    record_id = request.args(0, cast=int)
    table_name = request.args(1)
    table = db[table_name]
    row = db(table.id == record_id).select().first()
    status = stato(row.status)
    time_range = SQLFORM.factory(Field('time_start', 'datetime', 
label=T('Inizio Pubblicazione')),
                                 Field('time_end', 'datetime', 
label=T('Fine Pubblicazione')),
                                 )
    publish = INPUT(_type='submit', _name='pubblicato', _value='Pubblica', 
_class='button btn btn-success btn-xs')
    depublish = INPUT(_type='submit', _name='non_pubblicato', 
_value='Depubblica', _class='button btn btn-default btn-xs')
    highlight = INPUT(_type='submit', _name='in_evidenza', 
_value='Evidenzia', _class='button btn btn-primary btn-xs')
    delete = INPUT(_type='submit', _name='cancella', _value='Cancella', 
_class='button btn btn-danger btn-xs',
                   _onclick="return confirm('Sicuro che vuoi cancellare la 
notizia?')")
    archive = INPUT(_type='submit', _name='archiviato', _value='Archivia', 
_class='button btn btn-info btn-xs')
    time_range.vars.time_start = row.time_start
    time_range.vars.time_end = row.time_end
    if time_range.process(onvalidation=check_time_range, 
formname='parametri').accepted:
        if request.vars.pubblicato:
            row.status = 'pubblicato'
        elif request.vars.non_pubblicato:
            row.status = 'non_pubblicato'
        elif request.vars.in_evidenza:
            row.status = 'in_evidenza'
        elif request.vars.cancella:
            #db(table.id == record_id).delete()
            row.delete_record()
            redirect(URL('gestione', 'notizie'))
        elif request.vars.archiviato:
            row.status = 'archiviato'
        row.update_record()
        session.flash = 'OK, Record Inserito'
        redirect(URL(args=request.args))
        #if time_range.vars.time_start and time_range.vars.time_start > 
request.now:
        #row.time_start = time_range.vars.time_start
        #row.time_end = time_range.vars.time_end
        #row.update_record()
    return dict(status=status,
                time_range=time_range,
                publish=publish,
                depublish=depublish,
                highlight=highlight,
                delete=delete,
                archive=archive,
                )
....
#############################################################################################
This is the model:
gestione.py
....
from plugin_ckeditor import CKEditor
ckeditor = CKEditor(db)
ckeditor.define_tables()

db.define_table('notizie',
                Field('ordine', 'integer', label=T('Ordine di 
apparizione')),
                Field('titolo', 
requires=IS_NOT_EMPTY(error_message=err_mess)),
                Field('testo', 'text', label=T('Testo'),
                      widget=ckeditor.widget,
                      requires=IS_NOT_EMPTY(error_message=err_mess)
                      ),
                Field('autore', 
requires=IS_NOT_EMPTY(error_message=err_mess)),
                Field('img', 'upload', label=T('Immagine (jpeg o png)'), 
autodelete=True,
                      requires=[IS_NOT_EMPTY(error_message=T(err_mess)),
                                IS_IMAGE(extensions=('jpeg', 'png'))]
                      ),
                Field('img_name', 'string', label=T('Nome File')),
                Field('status', 'string', default='non_pubblicato'),
                Field('time_start', 'datetime', label=T('Inizio 
Pubblicazione')),
                Field('time_end', 'datetime', label=T('Fine 
Pubblicazione')),
                Field('last_update', 'datetime',
                      default=datetime.datetime(2000, 12, 31, 0, 0, 0),
                      writable=False, readable=False),
                auth.signature,
                )

def stato(status, row=None):
    if status == 'in_evidenza':
        return BUTTON('In evidenza', _type="submit", _class="btn 
btn-primary btn-xs", _disabled="disabled")
    elif status == 'in_programma':
        return BUTTON('In programma', _type="submit", _class="btn 
btn-warning btn-xs", _disabled="disabled")
    elif status == 'pubblicato':
        return BUTTON('Pubblicato', _type="submit", _class="btn btn-success 
btn-xs", _disabled="disabled")
    elif status == 'archiviato':
        return BUTTON('Archiviato', _type="submit", _class="btn btn-info 
btn-xs", _disabled="disabled")
    elif status == 'non_pubblicato':
        return BUTTON('Non pubblicato', _type="submit", _class="btn 
btn-default btn-xs", _disabled="disabled")

newstable = db.notizie
newstable.is_active.default = False
newstable.ordine.writable = False
newstable.ordine.readable = False
newstable.id.writable = False
newstable.id.readable = False
newstable.img_name.writable = False
newstable.img_name.readable = False
newstable.time_start.writable = False
newstable.time_start.readable = False
newstable.time_end.writable = False
newstable.time_end.readable = False
newstable.is_active.label = T('Pubblicato')
newstable.img.represent = lambda value, row: IMG(_src=URL('default', 
'download', args=value), _style='width:150px')
newstable.time_start.represent = lambda value, row: value or ' '
newstable.time_end.represent = lambda value, row: value or ' '
newstable.titolo.represent = lambda value, row: TAG(value).flatten()[0:50]
newstable.status.requires = IS_IN_SET(['non_pubblicato',
                                       'pubblicato',
                                       'in_programma',
                                       'in_evidenza',
                                       'archiviato',
                                       ])
newstable.status.represent = lambda value, row: stato(value, row)
newstable._before_insert.append(lambda record: how_many_record(record, 
newstable))
newstable._before_delete.append(lambda recordset: 
scale_down_record(recordset, newstable))
....

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to