Esempio n. 1
0
def act_list():
    try:
        # 前台传的排序规则
        act_arr = request.form

        page_index = 1
        page_size = 1

        act_filter = {}  # 过滤条件
        by_distance = act_arr.get('distance', None)  # 最近距离
        by_default = act_arr.get('is_default', None)  # 默认
        if by_distance:
            act_filter = {"by_distance": by_distance}
        elif by_default:
            act_filter = {"by_default": by_default}
        else:
            category = act_arr.get('category', None)  # 活动类别
            if category:
                act_filter["category"] = category
            week = act_arr.get('week', None)  # 星期几
            if week:
                act_filter["week"] = week

        act_list = ActivityDB.get_activity_list(act_filter, page_size,
                                                page_index)
        current_app.logger.debug("act_list:" + str(model2dict(act_list)))
        return jsonify({'code': 1, 'events': model2dict(act_list)})
    except Exception, e:
        current_app.logger.error(str(e))
        e_msg = ' act_list service  except '
        return jsonify({'code': 0, 'error': e_msg})
Esempio n. 2
0
def act_init():
    try:
        user_id = request.args.get("user_id", '')
        user = UserDB.user_by_id(user_id)
        if not user:
            return jsonify({'code': 0, 'error': ' user is not exist '})
        # 判断是否有俱乐部
        club = ClubDB.club_by_user(user_id)
        # 初始化活动()
        activity = ActivityDB.init_activity(user_id)
        activity_id = activity.id

        # QQ群组
        cluster_arr = ClusterDB.list_cluster_by_user(user.qq)

        return jsonify({
            'code': 1,
            'id': activity_id,
            'club': model2dict(club),
            'cluster_list': model2dict(cluster_arr)
        })
    except Exception, eo:
        current_app.logger.error(str(eo))
        e_msg = 'act_init service  except '
        return jsonify({'code': 0, 'error': e_msg})
Esempio n. 3
0
def club_list():
    try:
        user_id = get_value_from_dict(request.args,"user_id",'')
        club = ClubDB.club_by_user(user_id)

        clubs = db.session.query(Club).\
            select_from(ClubMember).\
            filter_by(user_id=user_id, status=0).\
            join(Club, ClubMember.club_id == Club.id).all()

        return jsonify({'code': 1, 'club': model2dict(club),'follow_clubs':model2dict(clubs)})

    except Exception, e:
        current_app.logger.error(e.message)
        return jsonify({'code': 0, 'error': e.message})
Esempio n. 4
0
def members_of_club(c_id):
    try:
        club_id = int(c_id)

        club = ClubDB.club_by_id(club_id)
        if club:
           members = ClubMembersDB.members_of_club(club_id)
           creator = UserDB.user_by_id(club.creator_id)
           managers = []
           managers.append(creator)
           return jsonify({"code": 1,"members": model2dict(members),"managers": model2dict(managers)})
        raise Exception(' error club id')
    except Exception,e:
        current_app.logger.error(e.message)
        return jsonify({'code': 0, 'error': e.message})
Esempio n. 5
0
def category_list():
    try:
        # 活动类别列表
        act_categories = ActivityCategoryDB.list_activity_category()
        return jsonify({'code': 1, 'result': model2dict(act_categories)})
    except Exception, e:
        current_app.logger.error(str(e))
        e_msg = 'activity  category_list except '
        return jsonify({'code': 0, 'error': e_msg})
Esempio n. 6
0
def detail(club_id):
    try:
        club = ClubDB.club_by_id(club_id)
        if not club:
            raise Exception('not found this club')

        return jsonify({'code': 1, 'club': model2dict(club)})

    except Exception, e:
        current_app.logger.error(e.message)
        return jsonify({'code': 0, 'error': e.message})
Esempio n. 7
0
def detail(user_id):
    try:
      user = UserDB.user_by_id(user_id)
      if user:
          return jsonify({'code': 1, 'user':model2dict(user)})
      else :
          return jsonify({'code': 0, 'error': ' no user'})
    except Exception,e:
       current_app.logger.error(str(e))
       e_msg = ' get user detail exception '
       return jsonify({'code': 0, 'error': e_msg})
Esempio n. 8
0
def level_list(category):
    '''
    获取活动等级列表
    :return:
    '''
    try:
        # 活动等级列表
        act_level_list = ActivityLevelDB.list_activity_level(category)
        return jsonify({'code': 1, 'result': model2dict(act_level_list)})
    except Exception, e:
        current_app.logger.error(str(e))
        e_msg = 'act_level_list service except '
        return jsonify({'code': 0, 'error': e_msg})
Esempio n. 9
0
def clubs():
    try:
        club = Club(request.args)
        if not club.name or not club.tags:
            raise Exception('params not complete,(name, head_url, tags)')
        if not club.id:
            club.status = 0
        current_app.logger.debug(model2dict(club))
        ClubDB.add_club(club)
        return jsonify({'code': 1})

    except Exception, e:
        current_app.logger.error(e.message)
        return jsonify({'code': 0, 'error': e.message})
Esempio n. 10
0
def events_of_mine():
    '''
    活动列表:参加的、创建的
    :return:
    '''
    try:
        page = request.args.get('page', None)
        user_id = request.args.get('user_id', '')

        act_list = ActivityDB.get_mine_activity_list(user_id, page)

        return jsonify({'code': 1, "events": model2dict(act_list)})
    except Exception, e:
        current_app.logger.error(str(e))
        return jsonify({'code': 0, 'error': ' events_of_mine exception '})
Esempio n. 11
0
def events_of_club():
    '''
    获取俱乐部的所有活动
    :return:
    '''
    try:
        args = request.args
        current_app.logger.debug(str(args))
        page_size = int(args.get("page_size", 20))
        page_index = int(args.get("page_index", 1))
        club_id = int(args.get("club_id", 0))

        act_list = ActivityDB.get_club_activity_list(club_id, page_size,
                                                     page_index)

        return jsonify({'code': 1, "events": model2dict(act_list)})
    except Exception, e:
        current_app.logger.error(str(e))
        return jsonify({'code': 0, 'error': ' events_of_club exception '})
Esempio n. 12
0
def events_members(e_id):
    """

    """
    try:
        arr = request.args
        current_app.logger.debug(str(arr))
        event = ActivityDB.activity_by_id(int(e_id))
        user_id = int(arr.get("user_id", 0))
        managers = []
        creator = UserDB.user_by_id(event.creator_id)
        managers.append(creator)
        # 完善成员列表
        #members = ActivityMemberDB.activity_members_by_act(e_id)
        members = UserDB.activity_user_list(int(e_id))
        return jsonify({
            'code': 1,
            "managers": model2dict(managers),
            "members": members
        })
    except Exception, e:
        current_app.logger.error(e)
        jsonify({'code': 0, 'error': ' events_members exception '})
Esempio n. 13
0
def detail(e_id):
    '''
    查询活动详情
    :return:
    '''
    try:

        user_id = int(request.args.get("user_id", ''))
        current_app.logger.debug("user_id :" + str(user_id))
        # 查询活动
        activity = ActivityDB.activity_by_id(e_id)
        act_dic = model2dict(activity)
        print 'act_dic : ' + str(act_dic)

        if not activity:
            raise Exception(' no this activity ')

        if "venue_id" in act_dic and act_dic["venue_id"]:
            venue = VenueDB.venue_by_id(activity.venue_id)
            activity.venue = venue
        if "club_id" in act_dic and act_dic["club_id"]:
            club = ClubDB.club_by_id(activity.club_id)
            activity.club = club
        members = ActivityMemberDB.activity_members_by_act(e_id)
        activity.members = members

        join_count = 0
        is_creator = False
        has_joined = False

        # 判断是否创建者
        if activity.creator_id == user_id:
            is_creator = True
        # 判断是否参加活动
        for member in members:
            if member.user_id == user_id:
                has_joined = True
                join_count = member.num
        '''
        sql = 'select a.id as id,a.start_time as start_time,a.end_time as end_time ,' \
              'a.venue_id as venue_id,a.member_count_limit as member_count_limit,a.member_count as member_count,' \
              'a.`status` as `status`,c.`name` as club_name,c.head_url as club_head_url ' \
              'from activities a LEFT JOIN clubs c on a.club_id = c.id where a.id = ' + e_id
        activity = db.session.execute(sql).first()
        if activity:
            act_dict = {
                'id': activity[0],
                'start_time': activity[1],
                'end_time': activity[2],
                'venue_id': activity[3],
                'member_count': activity[4],
                'current_num': activity[5],
                'status': activity[6],
                'club': {
                    'name': activity[7],
                    'head_url': activity[8]
                }
            }
            return jsonify({'code': 1, 'result': {"event": act_dict}})
        else:
            return jsonify({'code': 0, 'error': "no event from db"})
        '''
        return jsonify({
            "code": 1,
            "event": model2dict(activity),
            "is_creator": is_creator,
            "has_joined": has_joined,
            "join_count": join_count,
            "role": 0
        })
    except Exception, eo:
        current_app.logger.error(str(eo))
        return jsonify({'code': 0, 'error': " activity detail error"})