Simple problem -- you are manually defining the archive tables, which you 
are not supposed to do. When auth.enable_record_versioning() is called, it 
notices the archive tables already exist, so it aborts and therefore never 
adds the ._before_update callback that does the actual archiving. Just call 
auth.enable_record_versioning(), and it will define the tables 
automatically.

Also, I'm not sure why you have this:

db.mediatitles_archive.editable = False

DAL tables do not have an "editable" attribute for use with the API. Is 
that a custom attribute you are using in your own code somewhere?

Anthony

On Friday, June 16, 2017 at 3:09:08 PM UTC-4, jim kaubisch wrote:
>
> Hi Anthony,
>
> Attached is an app about as minimal as possible that exhibits the problem.
> As before, a standard db.py except:
>
>    - auth.define_tables(username=False, signature=True)
>
>    - db._common_fields.append(auth.signature)
>
>
>    Note: I'm unhappy about modifying the db.py file, but don't understand 
> what happens if I allow the standard
>
>                   auth.define_tables(username=False, signature=False)
>
>             in db.py, then later in my model file re-execute the 
> auth.define_tables with signature=True
>
>
> As before, 
>
>   - updating a record (hardwired to be record 1) results in the correct 
> storing of the updated record in mediatitles
>
>   - but the mediatitles_archive table stays firmly empty :(
>
>
> My guess/hope is this is a case of misunderstand.
>
> Am very grateful for your help with sorting it out.
>
>
> Jim
>
>
>
> On Thursday, June 15, 2017 at 8:06:57 PM UTC-7, jim kaubisch wrote:
>>
>> Hi,
>>
>>
>> I’m stuck. Have looked at all documentation/discussion groups I think, 
>> but the following just doesn’t write records to an archive file
>>
>> I’ve been struggling with this for a while now, so help would be VERY 
>> appreciated. 
>>
>>
>> The environment is MacOS 10.12.5,, Python 2.7, Web2py 2.14.6, MySQL  5.7
>>
>>
>> Thanks
>>
>>
>>
>> the intent here is to enable record versioning, update a record, and 
>> archive the previous record version in an archive file
>>
>>
>> With the following code snippets, the form, if invoked after a record in 
>> a table has been selected, updates the record
>>
>>    - successful in the update i.e. the mediatitles record is correctly 
>> updated
>>
>>    - fails in the archive i.e. the old record is NOT written to the 
>> mediatitles_archive table
>>
>>
>> #
>>
>> # define database
>>
>> #
>>
>> standard db.py except for:
>>
>>
>>    - auth.define_tables(username=False, signature=True)
>>
>>    - db._common_fields.append(auth.signature)
>>
>>
>> … lots of tables defined
>>
>>
>> auth.enable_record_versioning(db,
>>
>>                                               archive_db=None,
>>
>>                                               
>> archive_names='%(tablename)s_archive',
>>
>>                                               
>> current_record='current_record')
>>
>>
>>  #
>>
>>  # ----- build form -----
>>
>>  #
>>
>> in the controller,
>>
>>
>> titles_form = SQLFORM.factory(
>>
>>    Field('name'         , 'string'     , label=T('Unique Full Name'),  
>> requires 
>> =IS_NOT_EMPTY()),
>>
>>    Field('akaname'    , 'string'     , label=T('Display Name'), default 
>> = None),
>>
>>    Field('used_in'      , 'list:string', label=T('Used In'), requires= 
>> IS_IN_SET( [ ('cur' ,'Curriculum'),  ('sup' ,'Supplemental Media'), ('tng' 
>> ,'Training Media'), ('adm' ,'Administrative Media'),  ('dev' 
>> ,'Development') ], multiple=True)),
>>
>>    Field('videos'        ,'list:string', label=T('Video(s)'), requires = 
>> IS_IN_DB(db, 'videos.id', '%(name)s', multiple=True)),
>>
>>    Field('audios'        ,'list:string', label=T('Audio(s)'), requires = 
>> IS_IN_DB(db, 'audios.id', '%(name)s', multiple=True)),
>>
>>    Field('scores'        ,'list:string', label=T('Score(s)'), requires = 
>> IS_IN_DB(db, 'scores.id', '%(name)s', multiple=True)),
>>
>>    Field('tags'           ,'list:string', label=T('Tag(s)')   ,  requires 
>> = IS_IN_DB(db, 'tags.id’   , '%(name)s', multiple=True)),
>>
>>    table_name='titles_form_table')
>>
>> titles_form.add_button('Cancel', URL('list_rows'))
>>
>>
>> #
>>
>> # if record update request
>>
>> #
>>
>> record_id = int(request.vars.record_id)
>>
>> the_record = db(db.mediatitles.id == record_id).select().first()
>>
>>
>> …
>>
>>
>> #
>>
>> # ----- process form -----
>>
>> #
>>
>> if titles_form.process(onsuccess=auth.archive).accepted:
>>
>>     the_record.update_record(name=titles_form.vars.name, 
>>
>>                                                
>> akaname=titles_form.vars.akaname, 
>>
>>                                                
>> used_in=titles_form.vars.used_in)
>>
>>
>> # fix link tables for the many-to-many relationships
>>
>> #  old-new could be an overlapping list of values 
>>
>> # e.g. videos
>>
>> del_list = list(Set(save_video_vals) - Set(titles_form.vars.videos))
>>
>> add_list = list(Set(titles_form.vars.videos) - Set(save_video_vals))
>>
>>
>> for next in add_list:
>>
>>     db.videos_mediatitles.insert(mediatitle_id=record_id, video_id=next)
>>
>> for next in del_list:
>>
>>     db((db.videos_mediatitles.mediatitle_id==record_id) & 
>> (db.videos_mediatitles.video_id==next)).delete()
>>
>> ...
>>
>>
>> redirect(URL('default', 'list_all_rows'))
>>
>>
>>
>>

-- 
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.

Reply via email to