Sorry, Anthony. Yes, I meant the MySQL archive tables (mediatitles_archive
in this case).
I'm looking at the table(s) using the command line MySQL console. This is
what it says:
...a couple of sample records from the mediatitles table (id 511 is an
updated record created after logging in as an alternate user - the akaname
changed)
mysql> select * from mediatitles;
| id | name | akaname
| progress | used_in | cnt| is_active | created_on |
created_by | modified_on | modified_by |
| 510 | I’m On My Way | I’m On My Way
| p16021491 | |cur| | 0 | T | 2017-06-14 14:18:09 | 1
| 2017-06-14 14:18:09 | 1 |
| 511 | (#R43) Mary Had A Little Lamb | #R43 - Mary Had A Little Lamb
Anne 4 | p16021544 | |cur| | 0 | T | 2017-06-14 14:18:09 | 1
| 2017-06-15 10:17:19 | 2 |
...and the mediatitles archive table - empty :(
mysql> select * from mediatitles_archive;
Empty set (0.00 sec)
mysql>
On Thursday, June 15, 2017 at 8:09:36 PM UTC-7, Anthony wrote:
>
> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.