From 3f69307610c072b1a2336df2f6e44c23d7329345 Mon Sep 17 00:00:00 2001 From: Ethan Jucovy Date: Sun, 2 Mar 2014 16:39:59 +0000 Subject: [PATCH] export and reimport member portrait metadata and site admin role - re #27, #30 --- opencore/browser/management.py | 11 +++++++++++ opencore/scripts/export_all_members.py | 25 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/opencore/browser/management.py b/opencore/browser/management.py index b56e4b3c..574a2c7b 100644 --- a/opencore/browser/management.py +++ b/opencore/browser/management.py @@ -81,6 +81,17 @@ def __call__(self, *args, **kwargs): if portrait: portrait = open(os.path.join(portraits_dir, portrait), 'rb') mem_obj.setPortrait(portrait) + portrait.filename = member['portrait_filename'] + portrait.getField("creation_date").set( + portrait, DateTime(member['portrait_created_on'])) + portrait.getField("modification_date").set( + portrait, DateTime(member['portrait_modified_on'])) + portrait.Schema()['creators'].set(portrait, (member['portrait_creator'],)) + portrait.creators = (member['portrait_creator'],) + + if member['site_role'] == "admin": + context.manage_setLocalRoles(member['member_id'], ("Manager",)) + mem_obj.reindexObject() i += 1 diff --git a/opencore/scripts/export_all_members.py b/opencore/scripts/export_all_members.py index 95a48a7e..17dacce1 100644 --- a/opencore/scripts/export_all_members.py +++ b/opencore/scripts/export_all_members.py @@ -52,6 +52,11 @@ def getMembersCSV(self, outfile, portrait_dir): 'favorites'] also = ['portrait', + 'portrait_filename', + 'portrait_created_on', + 'portrait_modified_on', + 'portrait_creator', + 'site_role', 'is_confirmed', @@ -78,7 +83,7 @@ def getMembersCSV(self, outfile, portrait_dir): row.append(member.getLogin_time()) else: row.append(member.getProperty(property)) - portrait_url = "" + portrait_url = portrait_filename = portrait_created_on = portrait_modified_on = portrait_creator = "" portrait = member.getPortrait() if portrait: extension = mimetypes.guess_extension(portrait.content_type) or '' @@ -94,10 +99,24 @@ def getMembersCSV(self, outfile, portrait_dir): assert isinstance(portrait.data.data, basestring) portrait_file.write(portrait.data.data) portrait_file.close() + portrait_filename = portrait.filename + portrait_created_on = str(portrait.created()) + portrait_modified_on = str(portrait.modified()) + portrait_creator = portrait.Creator() row.append(portrait_url) + row.append(portrait_filename) + row.append(portrait_created_on) + row.append(portrait_modified_on) + row.append(portrait_creator) print member.getId(), portrait_url - row.append("") - row.append(MemberWorkflowHandler(member).is_unconfirmed() and "unconfirmed" or "confirmed") + + site_role = "" + if 'Manager' in app.openplans.get_local_roles_for_userid(memberId): + site_role = 'admin' + row.append(site_role) + + row.append(MemberWorkflowHandler(member).is_unconfirmed() and "unconfirmed" + or "confirmed") try: memfolder = app.openplans.people[memberId] except KeyError: