コード例 #1
0
def myParticipatingActivity(request):
    '''
    首页 我已报名的且未过期或已取消的活动详情
    :param request:openid,sort,address
    :return:
    '''
    if request.method == 'GET':
        try:
            openid = request.GET.get('openid')
            sort = request.GET.get('sort')
            member_id = QyMember.objects.get(openid=openid).id

            # 我组织的活动
            my_objs = QyActivity.objects.filter(originator_id=member_id)
            act_id = []
            for x in my_objs:
                act_id.append(x.id)

            # 我参加的活动
            objs = QyActor_activities.objects.filter(member_id=member_id)
            objs_act = []
            for y in objs:
                objs_act.append(y.activity_id)

            # 取并集
            act = list(set(act_id).union(set(objs_act)))

            # 筛选其中没有过期的活动
            activities_id = []
            for x in act:
                obj = QyActivity.objects.filter(pk=x,activity_state__lte=1)
                if obj:
                    activities_id.append(obj[0].id)

            # 对筛选过的活动排序
            if sort == '3':
                address = request.GET.get('address')
                activities = QyActivity.objects.filter(
                    pk__in=activities_id,
                    address_detailed__contains=address)
            else:
                activities = QyActivity.objects.filter(
                    pk__in=activities_id).order_by(my_sort(sort))

            # 分页
            pag = mypage(request.GET.get('page'), activities)
            # 序列化
            serializer = Act_info(pag['page_list'],many=True)
            return JSONResponse(0,serializer.data)
        except Exception as e:
            return JSONResponse(1007)
コード例 #2
0
def Activity_info(request):
    '''
    获取指定活动详情
    :param request:
    :return:
    '''
    if request.method == 'GET':
        try:
            obj = QyActivity.objects.get(pk=request.GET.get('pk'))
            serializer = Act_info(obj, many=False)
            return JSONResponse(0,serializer.data)
        except:
            return JSONResponse(1007)
    else:
        return JSONResponse(1054)
コード例 #3
0
def Activity_up(request):
    '''
    修改指定活动
    :param request:
    :return:
    '''
    if request.method == 'PUT':
        try:
            data = json.loads(request.body)
            obj = QyActivity.objects.get(
                pk=data.get('pk'),activity_state=1)
        except:
            return JSONResponse(1007)
        try:
            with transaction.atomic():
                try:
                    activity_img = data.get('activity_img')
                    # 修改活动图片并且有历史图片时,删除旧图片
                    if eval(obj.activity_img) and activity_img:
                            for a in eval(obj.activity_img):
                                os.remove("./{}".format(a))
                except:
                    pass
                obj.activity_img = data.get('activity_img',obj.activity_img)
                obj.notice = data.get('notice', obj.notice)
                obj.activity_time = data.get('activity_time', obj.activity_time)
                obj.address_province = data.get('address_province', obj.address_province)
                obj.address_city = data.get('address_city', obj.address_city)
                obj.address_area = data.get('address_area', obj.address_area)
                obj.address_detailed = data.get('address_detailed', obj.address_detailed)
                obj.formater = data.get('formater', obj.formater)
                obj.type = data.get('type', obj.type)
                obj.upper_limit = data.get('upper_limit', obj.upper_limit)
                obj.lower_limit = data.get('lower_limit', obj.lower_limit)
                obj.is_limit = data.get('is_limit', obj.is_limit)
                obj.limit_time = data.get('limit_time', obj.limit_time)
                obj.activity_state = data.get('activity_state', obj.activity_state)
                obj.is_irres = data.get('is_irres',obj.is_irres)
                obj.irres_time = data.get('irres_time',obj.irres_time)
                obj.save()
                serializer = Act_info(obj, many=False)
                return JSONResponse(0,serializer.data)
        except Exception as a:
            return JSONResponse(1000)
    else:
        return JSONResponse(1057)
コード例 #4
0
def Activity_create(request):
    '''
    创建活动
    :param request:
    :return:
    '''
    if request.method == 'POST':
        try:
            data = json.loads(request.body)
            with transaction.atomic():
                originator_id = QyMember.objects.get(
                    openid=data.get('openid')).id
                obj = QyActivity(
                    notice=data.get('notice'),
                    activity_time=data.get('activity_time'),
                    address_province=data.get('address_province'),
                    address_city=data.get('address_city'),
                    address_area=data.get('address_area'),
                    address_detailed=data.get('address_detailed'),
                    formater=data.get('formater', 0),
                    type=data.get('type', 0),
                    upper_limit=data.get('upper_limit'),
                    lower_limit=data.get('lower_limit'),
                    is_limit=data.get('is_limit', 0),
                    limit_time=data.get('limit_time'),
                    price="%.2f" % data.get('price',0.00),
                    activity_img=data.get('activity_img'),
                    originator_id=originator_id,
                    add_time=str(int(time.time())),
                    is_irres=data.get('is_irres',0),
                    irres_time = data.get('irres_time')
                )
                obj.save()
                serializer = Act_info(obj, many=False)
                return JSONResponse(0,serializer.data)
        except Exception as a:
            return JSONResponse(1007)
    else:
        return JSONResponse(1055)
コード例 #5
0
def Activity_org_list(request):
    '''
    获取我曾经组织过的活动列表
    :param request:
    :return:
    '''
    if request.method == 'GET':
        try:
            originator_id = QyMember.objects.get(
                openid=request.GET.get('openid')).id
            obj = QyActivity.objects.filter(
                originator_id=originator_id,
                activity_state=2
            ).order_by('-id')
            # 进行分页
            pag = mypage(request.GET.get('page'), obj)
            serializer = Act_info(pag['page_list'], many=True)
            return JSONResponse(0,serializer.data,pag['page_sum'])
        except:
            return JSONResponse(1007)
    else:
        return JSONResponse(1054)
コード例 #6
0
def Activity_my_list(request):
    '''
    获得我参加过的所有活动列表
    :param request:openid
    :return:
    '''
    if request.method == 'GET':
        try:
            member_id = QyMember.objects.get(
                openid=request.GET.get('openid')).id
            objs = QyActor_activities.objects.filter(
                member_id=member_id,reg_state=1)
            objs_act = []
            for y in objs:
                objs_act.append(y.activity_id)
            obj = QyActivity.objects.filter(
                pk__in=objs_act,activity_state=2)
            pag = mypage(request.GET.get('page'), obj)
            serializer = Act_info(pag['page_list'],many=True)
            return JSONResponse(0,serializer.data,pag['page_sum'])
        except Exception as q:
            return JSONResponse(1007)
    else:
        return JSONResponse(1054)
コード例 #7
0
def my_historical_act(request):
    '''
    我的历史活动
    :param request: openid
    :return:
    '''
    if request.method == 'GET':
        try:
            openid = request.GET.get('openid')
            member_id = QyMember.objects.get(openid=openid).id

            # 我组织的活动
            my_objs = QyActivity.objects.filter(originator_id=member_id)
            act_id = []
            for x in my_objs:
                act_id.append(x.id)

            # 我参加的活动
            objs = QyActor_activities.objects.filter(member_id=member_id)
            objs_act = []
            for y in objs:
                objs_act.append(y.activity_id)

            # 取并集
            act = list(set(act_id).union(set(objs_act)))
            # 我的历史活动
            activities = QyActivity.objects.filter(
                pk__in=act,activity_state=2).order_by('-id')

            # 分页
            pag = mypage(request.GET.get('page'), activities)
            # 序列化
            serializer = Act_info(pag['page_list'],many=True)
            return JSONResponse(0,serializer.data)
        except Exception as e:
            return JSONResponse(1007)
コード例 #8
0
def Activity_filter(request):
    '''
    筛选活动
    :param request:
    :return:
    '''
    if request.method == 'GET':
        try:
            address_detailed = request.GET.get('address_detailed')
            formater = request.GET.get('formater')
            type = request.GET.get('type')
            org_nickname = request.GET.get('org_nickname')
            if address_detailed and (not formater) and (not type):
                obj = QyActivity.objects.filter(
                    address_detailed__contains=address_detailed,
                    activity_state__lte=2).order_by('-id')
            elif org_nickname and (not formater) and (not type):
                originator_id = []
                originator = QyMember.objects.filter(
                    nickname__contains=request.GET.get('org_nickname'))
                for ori in originator:
                    originator_id.append(ori.id)
                obj = QyActivity.objects.filter(
                    originator_id__in=originator_id,
                    activity_state__lte=2).order_by('-id')
            elif formater and (not address_detailed) \
                    and (not type) and (not org_nickname):
                obj = QyActivity.objects.filter(
                    formater=formater,activity_state__lte=2).order_by('-id')
            elif type and (not formater) and (not address_detailed) \
                    and (not org_nickname):
                obj = QyActivity.objects.filter(
                    type=type,activity_state__lte=2).order_by('-id')
            elif address_detailed and formater and (not type):
                obj = QyActivity.objects.filter(
                    address_detailed__contains=address_detailed,
                    formater=formater,activity_state__lte=2).order_by('-id')
            elif address_detailed and type and (not formater):
                obj = QyActivity.objects.filter(
                    address_detailed__contains=address_detailed,
                    type=type,activity_state__lte=2).order_by('-id')
            elif org_nickname and formater and (not type):
                originator_id = []
                originator = QyMember.objects.filter(
                    nickname__contains=request.GET.get('org_nickname'))
                for ori in originator:
                    originator_id.append(ori.id)
                obj = QyActivity.objects.filter(
                    originator_id__in=originator_id,formater=formater,
                    activity_state__lte=2).order_by('-id')
            elif org_nickname and type and (not formater):
                originator_id = []
                originator = QyMember.objects.filter(
                    nickname__contains=request.GET.get('org_nickname'))
                for ori in originator:
                    originator_id.append(ori.id)
                obj = QyActivity.objects.filter(
                    originator_id__in=originator_id,type=type,
                    activity_state__lte=2).order_by('-id')
            elif formater and type and (not address_detailed) \
                    and (not org_nickname):
                obj = QyActivity.objects.filter(
                    formater=formater,type=type,
                    activity_state__lte=2).order_by('-id')
            elif formater and type and address_detailed:
                obj = QyActivity.objects.filter(
                    address_detailed__contains=address_detailed,
                    formater=formater,type=type,
                    activity_state__lte=2).order_by('-id')
            elif formater and type and org_nickname:
                originator_id = []
                originator = QyMember.objects.filter(
                    nickname__contains=request.GET.get('org_nickname'))
                for ori in originator:
                    originator_id.append(ori.id)
                obj = QyActivity.objects.filter(
                    originator_id__in=originator_id,
                    type=type,formater=formater,
                    activity_state__lte=2).order_by('-id')
            else:
                obj = QyActivity.objects.filter(
                    activity_state__lte=2).order_by('-id')
            # 进行分页
            pag = mypage(request.GET.get('page'), obj)
            serializer = Act_info(pag['page_list'], many=True)
            return JSONResponse(0, serializer.data, pag['page_sum'], pag['page_count'])
        except:
            return JSONResponse(1007)
コード例 #9
0
def recommend_activity(request):
    '''
    推荐的活动列表
    :param request:
    :return:
    '''
    if request.method == 'GET':
        try:
            openid = request.GET.get('openid')
            my_id = QyMember.objects.get(openid=openid).id

            # 查询 所有不是本人举办的且状态为可参加的活动
            objs_notOriginator = QyActivity.objects.filter(
                activity_state=1).exclude(originator_id=my_id)

            notOriginator = []
            for x in objs_notOriginator:
                notOriginator.append(x.id)

            # 获取其中 本人没有参与的活动
            notActor = []
            for y in notOriginator:
                actor_activity = QyActor_activities.objects.filter(
                    activity_id=y, member_id=my_id)
                if not actor_activity:
                    notActor.append(y)

            # 获取其中 活动状态为可参加的 并排序
            sort = request.GET.get('sort')
            address = request.GET.get('address')
            activity_time = request.GET.get('activity_time')
            formater = request.GET.get('formater')

            # 地点
            if sort == '3':
                objs = QyActivity.objects.filter(
                    pk__in=notActor, activity_state=1,
                    address_detailed__contains=address
                )
            # 时间
            elif sort == '1':
                objs = QyActivity.objects.filter(
                    pk__in=notActor, activity_state=1,
                    activity_time__gte=time_stamp(activity_time).get('star'),
                    activity_time__lte=time_stamp(activity_time).get('end')
                )
            # 赛制
            elif sort == '2':
                objs = QyActivity.objects.filter(
                    pk__in=notActor, activity_state=1,
                    formater = formater
                    )
            else:
                objs = QyActivity.objects.filter(
                    pk__in=notActor, activity_state=1
                ).order_by(my_sort(sort))

            # 判断活动类别是 散踢(可见)/队内(与origin为好友可见)
            objs_actor = []
            for obj in objs:
                if obj.type == 0:
                    objs_actor.append(obj)
                elif obj.type == 1:
                    friend = QyGroup.objects.filter(
                        member_a_id=obj.originator_id,
                        member_b_id=my_id)
                    if friend:
                        objs_actor.append(obj)
                    else:
                        pass
                else:
                    pass
            pag = mypage(request.GET.get('page'), objs_actor)
            serializer = Act_info(pag['page_list'], many=True)
            return JSONResponse(0,serializer.data)
        except Exception as e:
            return JSONResponse(1007)
    else:
        return JSONResponse(1054)