What do you mean by archive "file" -- archived records are written to a 
database table? How are you checking for the archived records?

Anthony

On Thursday, June 15, 2017 at 11:06:57 PM UTC-4, 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