Esempio n. 1
0
def switch_tab_bar(request):
    models = TabBarSwitchModel.objects.all()
    switch = int(request.POST.get('switch', default=-1))
    # 如果未空插入一条数据 默认隐藏
    if models.__len__() == 0:
        TabBarSwitchModel.objects.create(switch=0)
        return result_handler(0)
    else:
        if switch > -1:
            TabBarSwitchModel.objects.update(switch=switch)
        return result_handler(models[0].switch)
Esempio n. 2
0
def add_start(request):
    demand_id = int(request.POST.get('id'))
    demand = DemandModel.objects.filter(id=demand_id)
    if demand.__len__() > 0:
        start = demand[0].start + 1
        DemandModel.objects.filter(id=demand_id).update(start=start)
    return result_handler(None)
Esempio n. 3
0
def get_user_by_openid(request):
    openId = request.META.get('HTTP_OPENID')
    user = UserModel.objects.filter(openId=openId).values()
    if user.__len__() > 0:
        return result_handler(user[0])
    else:
        return error_handler('请先登录')
Esempio n. 4
0
def update_user(request):
    openId = request.META.get('HTTP_OPENID')
    realName = request.POST.get('realName')
    avatarUrl = request.POST.get('avatarUrl')
    nickName = request.POST.get('nickName')
    phone = request.POST.get('phone')
    tag = request.POST.get('tag')

    find_user = UserModel.objects.filter(openId=openId)
    if find_user.__len__() > 0:
        UserModel.objects.filter(openId=openId).update(avatarUrl=avatarUrl,
                                                       nickName=nickName,
                                                       tag=tag)
    else:
        UserModel.objects.create(openId=openId,
                                 avatarUrl=avatarUrl,
                                 nickName=nickName,
                                 tag=tag)

    if not is_empty(realName):
        UserModel.objects.filter(openId=openId).update(realName=realName)

    if not is_empty(phone):
        UserModel.objects.filter(openId=openId).update(phone=phone)

    user = UserModel.objects.filter(openId=openId).values()
    return result_handler(user[0])
Esempio n. 5
0
def get_feeling_list():
    feelings = FeelingsModel.objects.all().order_by('id')
    return_list = []
    for feeling in feelings:
        item = format_data(feeling)
        item['form'] = format_data(feeling.form)
        return_list.append(item)
    return result_handler(return_list)
Esempio n. 6
0
def update_feeling(request):
    id = int(request.POST.get('id', default=0))
    word = request.POST.get('word')
    form_id = int(request.POST.get('form_id', default=1))
    if id > 0:
        FeelingsModel.objects.filter(id=id).update(word=word, form_id=form_id)
    else:
        FeelingsModel.objects.create(word=word, form_id=form_id)
    return result_handler(None)
Esempio n. 7
0
def update_banner(request):
    id = int(request.POST.get('id', default=0))
    imageUrl = request.POST.get('imageUrl')
    des = request.POST.get('des')
    priority = int(request.POST.get('priority', default=0))
    desColor = request.POST.get('desColor', default='#ffffff')
    if id > 0:
        BannerModel.objects.filter(id=id).update(imageUrl=imageUrl, des=des, priority=priority, desColor=desColor)
    else:
        BannerModel.objects.create(imageUrl=imageUrl, des=des, priority=priority, desColor=desColor)
    return result_handler(None)
Esempio n. 8
0
def user_login(request):
    code = request.POST.get('code')
    appId = "wxc0e17eb1d875cc6a"
    appSecret = "7af371cf4d648b837d37d3bff67b5707"

    r = requests.get('https://api.weixin.qq.com/sns/jscode2session',
                     params={
                         'appid': appId,
                         'secret': appSecret,
                         'js_code': code,
                         'grant_type': 'authorization_code'
                     })
    key = json.loads(r.text)
    return result_handler(key)
Esempio n. 9
0
def upload_net_file(request):
    try:
        file_dir = time.strftime("%Y-%m-%d")
        url = request.POST.get('url')
        file_dir = time.strftime("%Y-%m-%d")
        (path, name) = os.path.split(url)
        file_name = "wx-mini/" + str(file_dir) + "/" + name
        # 网络流将以 Transfer-Encoding:chunked 的方式传输到 COS
        stream = requests.get(url)
        response = client.put_object(Bucket=bucket, Body=stream, Key=file_name)
        return result_handler(host + file_name)
    except Exception as e:
        print(e)
        return error_handler(e)
Esempio n. 10
0
def upload(request):
    """
    上传文件
    :param request:
    :return:
    """
    file = request.FILES.get("file")
    file_name = os.path.splitext(file.name)[0][-30:] + os.path.splitext(
        file.name)[1]
    f = open(os.path.join(settings.MEDIA_ROOT, "upload", file_name), "wb")
    for chunk in file.chunks():
        f.write(chunk)
    f.close()
    return result_handler(os.path.join(settings.MEDIA_URL, "upload",
                                       file_name))
Esempio n. 11
0
def upload_wx_file(request):
    try:
        file_dir = time.strftime("%Y-%m-%d")
        file = request.FILES.get("file")
        file_name = "wx-mini/" + str(file_dir) + "/" + os.path.splitext(file.name)[0][-30:] + \
                    os.path.splitext(file.name)[1]
        for chunk in file.chunks():
            response = client.put_object(Bucket=bucket,
                                         Body=chunk,
                                         Key=file_name,
                                         StorageClass='STANDARD',
                                         EnableMD5=False)
        return result_handler(host + file_name)
    except Exception as e:
        print(e)
        return error_handler(e)
Esempio n. 12
0
def default(request):
    return result_handler('老铁,你来了,我看,你来了就别走了😏')
Esempio n. 13
0
def add_demand(request):
    demand = request.POST.get('demand')
    openId = request.META.get('HTTP_OPENID')
    user = UserModel.objects.filter(openId=openId)[0]
    DemandModel.objects.create(demand=demand, start=0, form_id=user.id)
    return result_handler(None)
Esempio n. 14
0
def get_user_list():
    user_list = UserModel.objects.all().order_by('-id')
    return result_handler(user_list)
Esempio n. 15
0
def get_banner_list():
    return result_handler(BannerModel.objects.all().order_by('priority'))
Esempio n. 16
0
def delete_demand(request):
    demand_id = int(request.POST.get('id'))
    if demand_id > 0:
        DemandModel.objects.filter(id=demand_id).delete()
    return result_handler(None)
Esempio n. 17
0
def delete_feeling(request):
    id = int(request.POST.get('id', default=0))
    FeelingsModel.objects.filter(id=id).delete()
    return result_handler(None)
Esempio n. 18
0
def delete_banner(request):
    banner_id = int(request.POST.get('id', default=0))
    BannerModel.objects.filter(id=banner_id).delete()
    return result_handler(None)
Esempio n. 19
0
def get_demand_list():
    demands = DemandModel.objects.all().order_by('-id').values()
    for demand in demands:
        item = format_data(demand)
        item['form'] = format_data(UserModel.objects.filter(id=demand['form_id'])[0])
    return result_handler(demands)