def get_photo_info(vars): rec = get_photo_rec(vars.photo_id) rec.photo_url = photos_folder() + rec.photo_path sm = stories_manager.Stories() story_info = sm.get_story(rec.story_id) rec.name = rec.Name or story_info.name return dict(photo_info=rec, story_info=story_info)
def save_story_data(story_info, user_id): story_id = story_info.story_id sm = stories_manager.Stories(user_id) if story_id: result = sm.update_story(story_id, story_info) else: result = sm.add_story(story_info) return result
def save_story(vars): story_info = vars.story_info story_text = story_info.story_text story_id = story_info.story_id sm = stories_manager.Stories() if story_id: sm.update_story(story_id, story_text) else: story_id = sm.add_story(story_text, used_for=STORY4MEMBER) return dict(story_id=story_id)
def get_story_detail(vars): story_id = vars.story_id sm = stories_manager.Stories() used_for = int( vars.used_for ) if vars.used_for and vars.used_for != 'undefined' else STORY4EVENT if story_id == 'new': story = sm.get_empty_story(used_for=used_for) return dict(story=story, members=[], photos=[]) story_id = int(story_id) story = sm.get_story(story_id) member_fields = [ db.TblMembers.id, db.TblMembers.first_name, db.TblMembers.last_name, db.TblMembers.facePhotoURL ] members = [] photos = [] if story.used_for == STORY4EVENT: event = db(db.TblEvents.story_id == story_id).select().first() if event: qp = (db.TblEventPhotos.Event_id == event.id) & ( db.TblPhotos.id == db.TblEventPhotos.Photo_id) photos = db(qp).select(db.TblPhotos.id, db.TblPhotos.photo_path) photo_ids = [photo.id for photo in photos] photo_member_set = photo_lst_member_ids(photo_ids) photos = [p.as_dict() for p in photos] for p in photos: p['photo_path'] = photos_folder() + p['photo_path'] qm = (db.TblEventMembers.Event_id == event.id) & ( db.TblMembers.id == db.TblEventMembers.Member_id) members = db(qm).select(*member_fields) members = [m for m in members] member_set = set([m.id for m in members]) added_members_from_photos = photo_member_set - member_set added_members_lst = [mid for mid in added_members_from_photos] added_members = db( db.TblMembers.id.belongs(added_members_lst)).select( *member_fields) added_members = [m for m in added_members] members += added_members members = [m.as_dict() for m in members] for m in members: m['full_name'] = m['first_name'] + ' ' + m['last_name'] if not m['facePhotoURL']: m['facePhotoURL'] = "dummy_face.png" m['facePhotoURL'] = photos_folder( "profile_photos") + m['facePhotoURL'] #photos = [dict(photo_id=p.id, photo_path=photos_folder()+p.photo_path) for p in photos] return dict(story=story, members=members, photos=photos)
def get_help(vars): topic = vars.topic sm = stories_manager.Stories() story_info = sm.find_story(STORY4HELP, topic) if not story_info: story_info = Storage(display_version='New Story', name="help for " + topic, topic=topic, story_versions=[], story_text='help.not-ready', story_id=None, used_for = STORY4HELP ) return dict(story_info=story_info)
def get_member_details(vars): if not vars.member_id: raise User_Error(T('Member does not exist yet!')) if vars.member_id == "new": rec = new_member_rec() rec.member_info.full_name = "members.new-member" return rec mem_id = int(vars.member_id) if vars.what == 'story': #access member via its life story id rec = db(db.TblMembers.story_id == mem_id).select().first() if rec: mem_id = rec.id else: raise Exception('No member for this story') if vars.shift == 'next': mem_id += 1 elif vars.shift == 'prev': mem_id -= 1 member_stories = get_member_stories(mem_id) member_info = get_member_rec(mem_id) if not member_info: raise User_Error('No one there') sm = stories_manager.Stories() story_info = sm.get_story(member_info.story_id) or Storage( display_version='New Story', topic="member.life-summary", story_versions=[], story_text='', story_id=None) story_info.used_for = STORY4MEMBER family_connections = get_family_connections(member_info.id) slides = get_member_slides(mem_id) if member_info.gender == 'F': spouses = 'husband' + ('s' if len(family_connections.spouses) > 1 else '') else: spouses = 'wife' + ('s' if len(family_connections.spouses) > 1 else '') member_stories = [story_info] + member_stories return dict( member_info=member_info, story_info=story_info, family_connections=family_connections, slides=slides, #todo: duplicate? spouses=spouses, #this is just the key for translation member_stories=member_stories, facePhotoURL=photos_folder('profile_photos') + (member_info.facePhotoURL or "dummy_face.png"))
def test_stories(): sm = stories_manager.Stories() s1 = ''' hellow world ''' s2 = ''' hellow dear world ''' s_id = sm.add_story(s1, 1) s = sm.get_story(s_id) sm.update_story(s_id, s2) s3 = sm.get_story(s_id) s4 = sm.get_story(s_id, story_version=0) return s4
def get_photo_detail(vars): photo_id = int(vars.photo_id) if vars.what == 'story': #This photo is identified by the associated story rec = db(db.TblPhotos.story_id == photo_id).select().first() else: rec = db(db.TblPhotos.id == photo_id).select().first() sm = stories_manager.Stories() story = sm.get_story(rec.story_id) if not story: story = sm.get_empty_story(used_for=STORY4PHOTO) return dict(photo_src=photos_folder() + rec.photo_path, photo_name=rec.Name, height=rec.height, width=rec.width, photo_story=story, photo_id=rec.id)
def save_help(name, topic, content): rec = db((db.TblStories.used_for==STORY4HELP) & (db.TblStories.topic==topic)).select().first() if rec: story_id = rec.id else: story_id = None story_info = Storage( name=name, topic=topic, story_text=content, story_id=story_id, used_for = STORY4HELP ) sm = stories_manager.Stories() if story_id: sm.update_story(story_id, story_info) else: sm.add_story(story_info)
def get_event_info(vars): event_info = db(db.TblEvents.id == vars.event_id).select().first() sm = stories_manager.Stories() story_info = sm.get_story(event_info.story_id) return dict(event_info=event_info, story_info=story_info)
def get_term_info(vars): term_info = db(db.TblTerms.id == vars.term_id).select().first() sm = stories_manager.Stories() story_info = sm.get_story(term_info.story_id) return dict(term_info=term_info, story_info=story_info)
def set_member_story_id(vars): db(db.TblMembers.id == vars.member_id).update(story_id=vars.story_id) sm = stories_manager.Stories() sm.set_used_for(vars.story_id, STORY4MEMBER) return dict()