def read_feed(cls, request, feed_sid, resume_id, read_user=None):
        feed_oid = get_oid(feed_sid)
        resume_oid = get_oid(resume_id)
        if read_user is None:
            read_user = request.GET.get('user', '')

        if not feed_oid or not resume_oid or read_user not in ('admin',
                                                               'user'):
            return False

        upload_read_meta = {
            'admin': {
                'set__admin_read_status': 'read'
            },
            'user': {
                'set__user_read_status': 'read',
                'inc__click_count': 1,
                'set__user_read_time': datetime.datetime.now()
            },
        }

        FeedResult.objects(feed=feed_oid,
                           resume=resume_oid,
                           user_read_status='read').update(inc__click_count=1)
        FeedResult.objects(
            feed=feed_oid,
            resume=resume_oid,
            user_read_status='unread',
        ).update(**upload_read_meta[read_user])
        return True
Exemple #2
0
    def get_feed_list(self, feed_id):
        feed_id = get_oid(feed_id)

        if not feed_id:
            return []

        page = get_int(self.request.GET.get('start', '0'))
        if page < 0:
            page = 0

        query_cond = self.get_query_cond()
        query_cond.update({'feed': feed_id})

        feed_result_list = FeedResult.objects(
            resume_source__ne='talent_partner',
            **query_cond).only(*self.only_fields).skip(
                self.page_count * page).limit(self.page_count).order_by(
                    *self.get_sort_cond()).select_related()

        feed_result_dict_list = []
        for f in feed_result_list:
            try:
                work_years = f.resume.get_work_years()
                feed_dict = mongo_to_dict(f, [])
                feed_result_dict_list.append(feed_dict)
                feed_dict['resume']['work_years'] = work_years
            except AttributeError:
                # 处理由于删除重复简历,导致的推荐结果缺失问题
                django_log.error('resume not exists %s' % f.resume.id)
                continue

        feed_query_count = FeedResult.objects(**query_cond).count()

        tomorrow = get_tomommow()
        total_count = 13 * FeedResult.objects(feed=feed_id).count()
        total_recommend_count = FeedResult.objects(
            feed=feed_id,
            published=True,
            is_recommended=True,
            display_time__lt=tomorrow,
        ).count()

        newest_recommend_count = FeedResult.objects(
            feed=feed_id,
            user_read_status__ne='read',
            published=True,
        ).count()

        return {
            'start': page,
            'next_start': page + 1 if feed_result_dict_list else -1,
            'data': feed_result_dict_list,
            'total_recommend_count': total_recommend_count,
            'total_count': total_count,
            'newest_recommend_count': newest_recommend_count,
            'feed_query_count': feed_query_count,
        }
Exemple #3
0
    def publish_all(self, request):
        username = request.POST.get('username')
        display_time_str = request.POST.get('pub_time', '')

        user_feeds = UserFeed2.objects(
            username=username,
            is_deleted=False,
        ).select_related()

        if not user_feeds:
            return JsonResponse({
                'status': 'error',
                'msg': u'没有查到用户%s的相关订阅' % username,
            })

        now = datetime.datetime.now()
        display_time = self.convert_display_time(display_time_str)
        total_count = 0

        for user_feed in user_feeds:
            feed_id = user_feed.feed.id
            feed_results = FeedResult.objects(
                feed=feed_id,
                is_recommended=True,
                published=False,
            ).select_related()
            resume_oids = [fr.resume.id for fr in feed_results]

            # 添加cls_score,如果没有这个字段设置为100
            FeedResult.objects(
                feed=feed_id,
                is_recommended=True,
                published=False,
                score__cls_score=None,
            ).update(set__score__cls_score=100)

            # 发布推荐结果
            FeedResult.objects(
                feed=feed_id,
                is_recommended=True,
                published=False,
            ).update(
                set__published=True,
                set__display_time=display_time,
                set__pub_time=now,
            )

            self.add_pub_data(feed_id, resume_oids, display_time)
            self.add_email_data(feed_id, resume_oids)
            FeedCacheUtils.add_feed_id_update_cache(feed_id)

            total_count += len(resume_oids)

        return JsonResponse({
            'status': 'ok',
            'msg': u'已成功发布%s条订阅' % total_count,
        })
Exemple #4
0
    def post(self, request):
        publish_all = request.POST.get('publish_all')
        if publish_all:
            return self.publish_all(request)

        feed_sid = request.POST.get('feed_id', '')
        resume_sids = request.POST.getlist('resume_ids[]', [])
        display_time_str = request.POST.get('pub_time', '')

        feed_id = get_oid(feed_sid)

        if not feed_id:
            return JsonResponse({
                'status': 'error',
                'msg': u'没有订阅',
            })

        if not resume_sids:
            return JsonResponse({
                'status': 'error',
                'msg': u'请选择要发布的简历',
            })

        now = datetime.datetime.now()
        display_time = self.convert_display_time(display_time_str)
        resume_oids = [get_oid(resume_id) for resume_id in resume_sids]
        admin = request.user

        # 发布数据
        FeedResult.objects(
            feed=feed_id,
            resume__in=resume_oids,
        ).update(
            set__published=True,
            set__display_time=display_time,
            set__pub_time=now,
            set__publisher=admin.username,
        )

        # 添加cls_score,如果没有这个字段设置为100
        FeedResult.objects(
            feed=feed_id,
            resume__in=resume_oids,
            score__cls_score=None,
        ).update(set__score__cls_score=100, )

        self.add_pub_data(feed_id, resume_oids, display_time)
        self.add_email_data(feed_id, resume_oids)
        FeedCacheUtils.add_feed_id_update_cache(feed_sid)

        return JsonResponse({
            'status': 'ok',
            'msg': u'已成功发布%s条订阅' % len(resume_oids),
        })
    def update_today_cache(cls):
        update_feed_id_list = cache.get(cls.update_cache_key, [])
        today = get_today()
        tomorrow = get_tomommow()

        has_update_feed_list = []

        for feed_id in update_feed_id_list:
            feed_oid = get_oid(feed_id)
            today_cache_key = feed_id + '_today_cache'
            today_cache_value = cache.get(today_cache_key, [])

            feed_results = FeedResult.objects(
                feed=feed_oid,
                display_time__gte=today,
                display_time__lt=tomorrow,
            )
            resume_ids = [str(fr.resume.id) for fr in feed_results]
            if resume_ids:
                today_cache_value = list(
                    set(today_cache_value) | set(resume_ids))
                cache.set(today_cache_key, today_cache_value, timeout=0)
                has_update_feed_list.append(feed_id)

        not_update_feed_list = list(
            set(update_feed_id_list) - set(has_update_feed_list))
        cache.set(cls.update_cache_key, not_update_feed_list, timeout=0)
Exemple #6
0
 def set_display_count(self, feed_result):
     feed_list = feed_result['data']
     feed_result_oid_list = [
         get_oid(fr['id']) for fr in feed_list if get_oid(fr.get('id'))
     ]
     result = FeedResult.objects(id__in=feed_result_oid_list).update(
         inc__display_count=1)
     return result
Exemple #7
0
def get_display_resumes(feed_id, resumes):
    feed_results = FeedResult.objects(
        feed=feed_id,
        resume__in=resumes,
        published=True,
    ).order_by('-job_related').select_related()[:3]

    display_resumes = [fr.resume for fr in feed_results]
    return display_resumes
Exemple #8
0
 def sync_task(self):
     feed_results = FeedResult.objects(
         resume_source='talent_partner',
         sync_partner=False,
     )
     for fr in feed_results:
         self.create_reco_resume_task(fr)
         fr.sync_partner = True
         fr.save()
     return True
Exemple #9
0
 def sync_task(self):
     feed_results = FeedResult.objects(
         resume_source='talent_partner',
         sync_partner=False,
     )
     for fr in feed_results:
         self.create_reco_resume_task(fr)
         fr.sync_partner = True
         fr.save()
     return True
Exemple #10
0
def fix_read_status():
    unread_feed_results = FeedResult.objects(
        display_time__ne=None, ).order_by('-calc_time')

    print 'unread_feed_read_status_count', unread_feed_results.count()

    for fr in unread_feed_results:
        read_status = get_read_status(fr)
        fr.user_read_status = read_status
        fr.save()
        print fr.feed.id, read_status
def add_update_cache(feed):
    tomorrow = get_tomommow()
    today = get_today()
    feed_id = feed.id

    feed_results = FeedResult.objects(
        feed=feed_id,
        display_time__gte=today,
        display_time__lt=tomorrow,
    )
    resume_sids = [str(fr.resume.id) for fr in feed_results]
    FeedCacheUtils.add_update_cache(feed_id, resume_sids)
Exemple #12
0
    def add_feed_result(self, job, user, resume):
        now = datetime.datetime.now()
        feed_oid = get_oid(job.feed_obj_id)
        resume_oid = get_oid(resume.resume_id)
        feed_result = FeedResult.objects.filter(
            feed=feed_oid,
            resume=resume_oid,
        )
        if feed_result:
            return False

        feed_result = FeedResult(
            feed=feed_oid,
            resume=resume_oid,
            is_recommended=True,
            published=True,
            display_time=now,
            feed_source='brick',
        )
        feed_result.save()
        return feed_result
def fix_read_status():
    unread_feed_results = FeedResult.objects(
        display_time__ne=None,
    ).order_by('-calc_time')

    print 'unread_feed_read_status_count', unread_feed_results.count()

    for fr in unread_feed_results:
        read_status = get_read_status(fr)
        fr.user_read_status = read_status
        fr.save()
        print fr.feed.id, read_status
def add_update_cache(feed):
    tomorrow = get_tomommow()
    today = get_today()
    feed_id = feed.id

    feed_results = FeedResult.objects(
        feed=feed_id,
        display_time__gte=today,
        display_time__lt=tomorrow,
    )
    resume_sids = [str(fr.resume.id) for fr in feed_results]
    FeedCacheUtils.add_update_cache(feed_id, resume_sids)
    def add_feed_result(cls, feed_id, resume_id, source='pinbot', admin=''):
        now = datetime.datetime.now()
        feed_oid = get_oid(feed_id)
        resume_oid = get_oid(resume_id)

        if not feed_oid or not resume_oid:
            return False

        feed_result = FeedResult.objects.filter(
            feed=feed_oid,
            resume=resume_oid,
        ).first()

        if feed_result:
            feed_result.published = True
            feed_result.is_recommended = True
            feed_result.display_time = now
            feed_result.feed_source = source
            feed_result.pub_time = now
            feed_result.score['cls_score'] = 100
            if feed_result.resume_source:
                feed_result.resume_source = 'accept' + feed_result.resume_source
            if admin:
                feed_result.admin = admin
            feed_result.save()
            return feed_result

        feed_result = FeedResult(
            feed=feed_oid,
            resume=resume_oid,
            is_recommended=True,
            published=True,
            display_time=now,
            pub_time=now,
            admin=admin,
            feed_source=source,
        )
        feed_result.score['cls_score'] = 100
        feed_result.save()
        return feed_result
def main():
    old_feed_results = FeedResult.objects(
        published=True,
        display_time=None,
    ).order_by('-calc_time')

    today = get_today()
    tomorrow = get_tomommow()

    caculate_time = today + datetime.timedelta(hours=14)

    for feed_result in old_feed_results:
        calc_time = feed_result.calc_time
        if calc_time < caculate_time:
            feed_result.display_time = today
        else:
            feed_result.display_time = tomorrow
        feed_result.user_read_status = get_read_status(feed_result)
        feed_result.save()
        print feed_result.id, calc_time, feed_result.user_read_status, feed_result.display_time
Exemple #17
0
def main():
    old_feed_results = FeedResult.objects(
        published=True,
        display_time=None,
    ).order_by('-calc_time')

    today = get_today()
    tomorrow = get_tomommow()

    caculate_time = today + datetime.timedelta(hours=14)

    for feed_result in old_feed_results:
        calc_time = feed_result.calc_time
        if calc_time < caculate_time:
            feed_result.display_time = today
        else:
            feed_result.display_time = tomorrow
        feed_result.user_read_status = get_read_status(feed_result)
        feed_result.save()
        print feed_result.id, calc_time, feed_result.user_read_status, feed_result.display_time
def convert2pub_data(feed):
    username = feed.username
    feed_oid = feed.id

    feed_results = FeedResult.objects(
        feed=feed_oid,
        calc_time__gte=CONVERT_CACU_TIME,
        published=True,
    )

    if not feed_results:
        return False

    FeedCacheUtils.add_feed_id_update_cache(feed_oid)

    pub_admin = '*****@*****.**'
    resumes = [fr.resume.id for fr in feed_results]

    email_feed = EmailFeedData.objects(
        feed=feed_oid,
        is_send=False,
    ).first()

    if email_feed:
        EmailFeedData.objects(
            feed=feed_oid,
            is_send=False,
        ).update(
            set__pub_admin=pub_admin,
            add_to_set__resumes=resumes,
        )
    else:
        email_feed = EmailFeedData(
            email=username,
            pub_admin=pub_admin,
            feed=feed_oid,
            resumes=resumes,
        )
    email_feed.save()
def convert2pub_data(feed):
    username = feed.username
    feed_oid = feed.id

    feed_results = FeedResult.objects(
        feed=feed_oid,
        calc_time__gte=CONVERT_CACU_TIME,
        published=True,
    )

    if not feed_results:
        return False

    FeedCacheUtils.add_feed_id_update_cache(feed_oid)

    pub_admin = '*****@*****.**'
    resumes = [fr.resume.id for fr in feed_results]

    email_feed = EmailFeedData.objects(
        feed=feed_oid,
        is_send=False,
    ).first()

    if email_feed:
        EmailFeedData.objects(
            feed=feed_oid,
            is_send=False,
        ).update(
            set__pub_admin=pub_admin,
            add_to_set__resumes=resumes,
        )
    else:
        email_feed = EmailFeedData(
            email=username,
            pub_admin=pub_admin,
            feed=feed_oid,
            resumes=resumes,
        )
    email_feed.save()