Пример #1
0
def upload_paper(request):
    url = request.POST.get('url')
    category_id = request.POST.get('categoryId')
    if url is None or category_id is None:
        return CustomResponse(code=state.STATE_ERROR)
    if Wallpaper.objects.filter(origin_url=url).exists():
        return CustomResponse()
    try:
        source = tinify.tinify.from_url(url)
        source.to_file(optimized_path)
    except Exception as e:
        print(e)
        return CustomResponse(code=state.STATE_ERROR)
    paper = Wallpaper.objects.create(origin_url=url,
                                     type=TYPE_ANIM,
                                     category_id=category_id)
    md5 = hashlib.md5()
    md5.update(url.encode('utf-8'))
    dest_path = '/image/' + str(paper.id) + '/' + md5.hexdigest() + '.jpg'
    upload_to_cos(optimized_path, dest_path)
    paper.url = "https://wallpager-1251812446.cos.ap-beijing.myqcloud.com" + dest_path
    paper.save()
    # 删除本地临时文件
    if os.path.exists(optimized_path):
        os.remove(optimized_path)
    return CustomResponse()
Пример #2
0
def delete_subject(request):
    sid = request.POST.get('sid')
    if sid is None or Subject.objects.filter(id=sid).exists() is False:
        return CustomResponse(code=state.STATE_SUBJECT_NOT_EXIST)
    subject = Subject.objects.get(id=sid)
    subject.delete()
    return CustomResponse()
Пример #3
0
def set_wallpaper_banner(request):
    try:
        paper = Wallpaper.objects.get(id=request.POST.get('pid'))
        paper.banner_id = request.POST.get('bid')
        paper.save()
    except Wallpaper.DoesNotExist as e:
        return CustomResponse(data=False)
    return CustomResponse(True)
Пример #4
0
def buy_paper(request, pk):
    download_type = int(request.query_params.get('type'))
    resume = Download_Origin_Price if (download_type
                                       == 2) else Download_Normal_Price
    user = MicroUser.objects.get(id=util.get_uid(request))
    if user.pea < resume:
        return CustomResponse(code=state.STATE_PEA_NOT_ENOUGH)
    user.pea -= resume
    user.save()
    return CustomResponse(data=resume)
Пример #5
0
def logout_user(request):
    # auth.logout(request)
    # print(request.META.get('HTTP_UID'))
    try:
        user = MicroUser.objects.get(id=request.META.get('HTTP_UID'))
    except MicroUser.DoesNotExist:
        return CustomResponse(code=state.STATE_USER_NOT_EXIST)
    user.isLogin = False
    user.save()
    return CustomResponse()
Пример #6
0
def register_user(request):
    phone = request.data.get('phone')
    if len(phone) != 11:
        return CustomResponse(code=state.STATE_PHONE_ERROR)
    # user = auth.authenticate(username=phone, password=password)
    if MicroUser.objects.filter(phone=phone).exists() is True:
        return CustomResponse(code=state.STATE_USER_EXIST)
    user = MicroUser.objects.create(username=phone, phone=phone, password='')
    user.save()
    return CustomResponse()
Пример #7
0
def add_collect(request, pid):
    if Wallpaper.objects.filter(id=pid).exists() is False:
        return CustomResponse(code=state.STATE_WALLPAPER_NOT_EXIST)
    uid = request.META.get('HTTP_UID')
    if UserCollectPaper.objects.filter(user_id=uid, paper_id=pid).exists():
        return CustomResponse()
    if len(UserCollectPaper.objects.filter(user_id=uid)) >= 300:
        return CustomResponse(code=state.STATE_COLLECT_OVER)
    collect = UserCollectPaper(user_id=uid, paper_id=pid)
    collect.save()
    # cache.set('COLLECT:PAPER:' + str(paper.id) + ":UID:" + str(request.META.get('HTTP_UID')), True)
    return CustomResponse()
Пример #8
0
def get_is_sign(request):
    try:
        user = MicroUser.objects.get(id=request.META.get('HTTP_UID'))
    except MicroUser.DoesNotExist:
        return CustomResponse(code=state.STATE_USER_NOT_EXIST)
    if timezone.now().date() == user.last_sign.date():
        return CustomResponse(code=state.STATE_TODAY_HAS_SIGN)
    user.last_sign = timezone.now()
    reward = 30 if user.vip else 10
    user.pea += reward
    user.save()
    return CustomResponse(data=reward)
Пример #9
0
def add_paper_comment(request):
    uid = request.META.get('HTTP_UID')
    pid = request.POST.get('pid')
    content = request.POST.get('content')
    if uid is None or pid is None or content is None or MicroUser.objects.filter(id=uid).exists() is False \
            or Wallpaper.objects.filter(id=pid).exists() is False:
        return CustomResponse(data=state.STATE_ERROR)
    comment = Comment(content=content, paper_id=pid, user_id=uid)
    comment.save()
    paper = Wallpaper.objects.get(id=pid)
    paper.comment_num += 1
    paper.save()
    return CustomResponse(CommentSerializer(comment).data)
Пример #10
0
def del_collect(request):
    ids = json.loads(request.body.decode(encoding='utf-8')).get('ids')
    for pid in ids:
        collect = UserCollectPaper.objects.get(user_id=util.get_uid(request),
                                               paper_id=pid)
        collect.delete()
    return CustomResponse()
Пример #11
0
    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(queryset, many=True)
        return CustomResponse(data=serializer.data)
Пример #12
0
def get_paper_for_web(request, pk):
    paper = Wallpaper.objects.get(id=pk)
    result = json.loads(json.dumps(WallPaperSerializer(paper).data))
    if paper.category is not None:
        result['description'] = paper.category.description
        result['title'] = paper.category.name
    if paper.subject is not None:
        result['description'] = paper.subject.description
        result['title'] = paper.subject.name
    return CustomResponse(data=result)
Пример #13
0
    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        page = self.paginate_queryset(queryset)
        uid = request.META.get('HTTP_UID')
        for paper in page:
            paper.collected = UserCollectPaper.objects.filter(
                user_id=uid, paper_id=paper.id).exists()
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(queryset, many=True)
        return CustomResponse(data=serializer.data)
Пример #14
0
def get_account_info(request):
    uuid = request.GET.get('uuid', '')
    channel = request.META.get('HTTP_CHANNEL')
    version = request.META.get('HTTP_VERSION_CODE')
    # print(channel, version)
    if not MicroUser.objects.filter(uuid=uuid).exists():
        user = MicroUser(uuid=uuid)
        user.save()
    user = MicroUser.objects.get(uuid=uuid)
    data = MicroUserSerializer(user).data
    # data['token'] = Token.objects.get_or_create(user=user)[0].key
    data['nPrice'] = Download_Normal_Price
    data['oPrice'] = Download_Origin_Price
    data['showDonateInterval'] = 24 * 60 * 60 * 1000
    newest_version = models.Config.objects.all()[0].newest_version
    # print('version ', newest_version)
    data['canSetMode'] = False if channel == 'google_play' and version >= str(
        newest_version) else True
    data['defaultContentMode'] = models.TYPE_COS if data[
        'canSetMode'] else models.TYPE_ANIM
    return CustomResponse(data=data)
Пример #15
0
def update_category_cover(request):
    if settings.DEBUG is False:
        return
    cid = request.POST.get('cid')
    return CustomResponse()
Пример #16
0
 def retrieve(self, request, *args, **kwargs):
     instance = self.get_object()
     serializer = self.get_serializer(instance)
     return CustomResponse(data=serializer.data)
Пример #17
0
def set_paper_garbage(request, pk):
    paper = Wallpaper.objects.get(id=pk)
    paper.garbage += 1
    paper.save()
    return CustomResponse()
Пример #18
0
def update_share_num(request):
    pid = str(request.POST.get('pid'))
    paper = Wallpaper.objects.get(id=pid)
    paper.share_num += 1
    paper.save()
    return CustomResponse(data=state.STATE_SUCCESS)
Пример #19
0
def get_update_info(request):
    if Update.objects.count() < 1:
        update = Update(versionCode=0)
    else:
        update = Update.objects.order_by('-id')[0]
    return CustomResponse(data=UpdateSerializer(update).data)