Ejemplo n.º 1
0
def apply_to_selected_photos(vars):
    all_tags = calc_all_tags()
    spl = vars.selected_photo_list
    st = vars.selected_topics
    added = []
    deleted = []
    for pid in spl:
        curr_tag_ids = get_tag_ids(pid, "P")
        curr_tags = [all_tags[tag_id] for tag_id in curr_tag_ids]
        keywords = "; ".join(curr_tags)
        db(db.TblPhotos.id == pid).update(KeyWords=keywords)
        for topic in st:
            item = dict(item_id=pid, topic_id=topic.id)
            if topic.sign == "plus" and topic.id not in curr_tag_ids:
                new_id = db.TblItemTopics.insert(
                    item_type="P", item_id=pid,
                    topic_id=topic.id)  #todo: story_id=???
                added.append(item)
            elif topic.sign == "minus" and topic.id in curr_tag_ids:
                q = (db.TblItemTopics.item_type
                     == "P") & (db.TblItemTopics.item_id == pid) & (
                         db.TblItemTopics.topic_id == topic.id)
                deleted.append(item)
                db(q).delete()
    ws_messaging.send_message('PHOTO-TAGS-CHANGED',
                              added=added,
                              deleted=deleted)
    return dict()
Ejemplo n.º 2
0
def upload_photos(vars):
    uploaded_photo_ids = []
    user_id = vars.user_id or auth.current_user()
    comment("start handling uploaded files")
    number_uploaded = 0
    number_duplicates = 0
    failed = []
    user_id = int(vars.user_id) if vars.user_id else auth.current_user()
    for fn in vars:
        if fn.startswith('user'):
            continue
        fil = vars[fn]
        result = save_uploaded_photo(fil.name, fil.BINvalue, user_id)
        if result == 'duplicate':
            number_duplicates += 1
            continue
        if result == 'failed':
            failed.append(fil.name)
            continue
        number_uploaded += 1
        uploaded_photo_ids += [result]
    ws_messaging.send_message(key='PHOTOS_WERE_UPLOADED',
                              group='ALL',
                              uploaded_photo_ids=uploaded_photo_ids)
    return dict(number_uploaded=number_uploaded,
                number_duplicates=number_duplicates,
                failed=failed)
Ejemplo n.º 3
0
def save_tag_merges(vars):
    gst = vars.grouped_selected_topics
    for topic_group in gst:
        topic0 = topic_group[0]
        rec0 = db(db.TblTopics.id == topic0.id).select().first()
        for topic in topic_group[1:]:
            rec = db(db.TblTopics.id == topic.id).select().first()
            if not rec.usage:
                continue
            for c in rec.usage:
                if c not in rec0.usage:
                    rec0.usage += c
                    rec0.update_record(usage=rec0.usage)

            db(db.TblItemTopics.topic_id == rec.id).update(topic_id=rec0.id)
            db(db.TblTopics.id == rec.id).delete()

    gsp = vars.grouped_selected_photographers
    for p_group in gsp:
        p0 = p_group[0]
        rec0 = db(db.TblPhotographers.id == p0.id).select().first()
        for p in p_group[1:]:
            rec = db(db.TblPhotographers.id == p.id).select().first()
            db(db.TblPhotos.photographer_id == rec.id).update(
                photographer_id=rec0.id)
        db(db.TblPhotographers.id == rec.id).delete()

    ws_messaging.send_message(key='TAGS_MERGED', group='ALL')
    return dict()
Ejemplo n.º 4
0
def remove_member(vars):
    member_id = int(vars.member_id)
    deleted = db(db.TblMembers.id == member_id).update(deleted=True) == 1
    if deleted:
        ws_messaging.send_message(key='MEMBER_DELETED',
                                  group='ALL',
                                  member_id=member_id)
    return dict(deleted=deleted)
Ejemplo n.º 5
0
def add_photographer(vars):
    photographer_name = vars.photographer_name
    if not db(db.TblPhotographers.name == photographer_name).isempty():
        raise User_Error("photos.already-exists")
    db.TblPhotographers.insert(name=photographer_name)
    ws_messaging.send_message(key='PHOTOGRAPHER_ADDED',
                              group='ALL',
                              photographer_name=photographer_name)
    return dict()
Ejemplo n.º 6
0
def toggle_membership(vars):
    am = AccessManager()
    role_name = vars.role
    role = eval(role_name)
    active = vars.active != 'true'
    am.modify_membership(vars.id, role, active)
    ws_messaging.send_message(key='ROLE_CHANGED',
                              user=vars.id,
                              role=role_name,
                              active=active)
    return dict(id=vars.id, role=vars.role, active=active)
Ejemplo n.º 7
0
 def on_update_task_status(self, task_id, data):
     #comment('on update task status', log_name='dbg_scheduler')
     comment = inject('comment')
     try:
         ###comment("task {task_id} status changed {data}", task_id=task_id, data=data)
         ws_messaging.send_message(key='task_status_changed',
                                   group='TASK_MONITOR',
                                   task_id=task_id,
                                   data=data)
     except Exception, e:
         log_exception('failed on update task status')
Ejemplo n.º 8
0
def send_message(vars):
    now = datetime.datetime.now()
    db.TblChats.insert(chat_group=int(vars.room_number),
                       author=auth.current_user(),
                       timestamp=now,
                       message=vars.user_message)
    ws_messaging.send_message(key='INCOMING_MESSAGE' + vars.room_number,
                              group='CHATROOM' + vars.room_number,
                              author=auth.current_user(),
                              timestamp=str(now)[:19],
                              sender_name=auth.user_name(),
                              message=vars.user_message.replace('\n', '<br/>'))
    return dict(good=True)
Ejemplo n.º 9
0
def save_member_info(vars):
    user_id = vars.user_id
    member_id = vars.member_id
    member_info = vars.member_info
    if 'facePhotoURL' in member_info:
        del member_info.facePhotoURL  #it is saved separately, not updated in client and can only destroy here
    if member_info:
        new_member = not member_info.id
        #--------------handle dates - old version------------------
        date_fields = []
        for k in member_info:
            if k.startswith("date_of_") and k.endswith('_str'):
                date_fields.append(k)
        for df in date_fields:
            k = df[:-4]
            member_info[df], member_info[k] = date_of_date_str(member_info[df])
        #--------------handle dates - new version------------------
        tbl = db.TblMembers
        for fld in tbl:
            if fld.type == 'date':
                fld_str_name = fld.name + '_string'
                fld_span_name = fld.name + '_span_size'
                fld_scale_name = fld.name + '_scale'
                if fld_str_name not in tbl or fld_span_name not in tbl:
                    continue
                if fld_str_name in member_info:
                    date_scale, date = parse_date(member_info[fld_str_name])
                    member_info[fld.name] = date
                    member_info[fld_scale_name] = date_scale

        #--------------handle dates - end--------------------------
        result = insert_or_update(db.TblMembers, **member_info)
        if isinstance(result, dict):
            return dict(errors=result['errors'])
        member_id = result
        member_rec = get_member_rec(member_id)
        if new_member:
            member_rec.facePhotoURL = photos_folder(
                'profile_photos') + "dummy_face.png"
        member_rec = json_to_storage(member_rec)
        ws_messaging.send_message(key='MEMBER_LISTS_CHANGED',
                                  group='ALL',
                                  member_rec=member_rec,
                                  new_member=new_member)
    result = Storage(info=member_info)
    if member_id:
        result.member_id = member_id
    #todo: read-modify-write below?
    ##get_member_names() #todo: needed if we use caching again
    return result
Ejemplo n.º 10
0
 def restart_task(self, task_id, period=None):
     self.stop_task(task_id)
     now = datetime.datetime.now()
     args = dict(
         status='QUEUED',
         start_time=now,  ### + timedelta(seconds=10),
         next_run_time=now,  ### + timedelta(seconds=10),
         enabled=True,
         stop_time=now + datetime.timedelta(days=1461))
     if period:
         args['period'] = period
     db = self.db
     db(db.scheduler_task.id == task_id).update(**args)
     args['start_time'] = str(args['start_time'])[:19]
     args['next_run_time'] = str(args['next_run_time'])[:19]
     args['stop_time'] = str(args['stop_time'])[:19]
     ws_messaging.send_message(key='task_status_changed',
                               group='TASK_MONITOR',
                               task_id=task_id,
                               data=args)
     return task_id
Ejemplo n.º 11
0
def update_story_words_index(story_id):
    from injections import inject
    now = datetime.datetime.now()
    added_words = []
    deleted_words = []
    db = inject('db')
    old_dic = retrieve_story_words(story_id)
    new_dic = extract_story_words(story_id)
    new_words = {}
    for w in new_dic:
        word_id, new = find_or_insert_word(w)
        if new:
            new_words[word_id] = w
        if w not in old_dic:
            db.TblWordStories.insert(story_id=story_id,
                                     word_id=word_id,
                                     word_count=new_dic[w])
            added_words.append(word_id)
        elif new_dic[w] != old_dic[w]:
            db((db.TblWordStories.word_id == word_id)
               & (db.TblWordStories.story_id == story_id)).update(
                   word_count=new_dic[w])
            #for now we do not broadcast modified word count
    for w in old_dic:
        if w not in new_dic:
            word_id, new = find_or_insert_word(w)  #it will not be inserted...
            deleted_words.append(word_id)
            db((db.TblWordStories.word_id == word_id)
               & (db.TblWordStories.story_id == story_id)).delete()
    ws_messaging.send_message('WORD_INDEX_CHANGED',
                              group='ALL',
                              story_id=story_id,
                              added_words=added_words,
                              deleted_words=deleted_words,
                              new_words=new_words)
    db(db.TblStories.id == story_id).update(indexing_date=now)