示例#1
0
def get_List(request):
    if request.method == 'GET':
        try:
            data = Blog.objects.all().values()
            return returnJson.json_responre(data)
        except:
            # return JsonResponse({'a':'b'})
            traceback.print_exc()
示例#2
0
def get_detail(request):
    fid = json.loads(request.body).get('id')
    try:
        list = Blog.objects.get(id=fid)
        data = model_to_dict(list)
        return returnJson.json_responre(data)
    except:
        return returnJson.json_error()
示例#3
0
def get_list(requset):
    dr = re.compile(r'<[^>]+>', re.S)
    articl = Blog.objects.all().order_by('id').values()
    list = []
    for item in articl:
        items = item
        items['reContent'] = dr.sub('', item.get('content'))
        list.append(items)
    return returnJson.json_responre(list)
示例#4
0
文件: user.py 项目: David-star6/Blog
def user_login(request):
    form = LoginForm(request.POST)
    if not form.is_valid():
        return returnJson.json_error('请输入账号密码或者正确的邮件')
    user = form.get_user()
    auth.login(request, user)
    token_str = Token.objects.get(user=user).key
    data = {'token': token_str}
    if user.is_active:
        return returnJson.json_responre(data)
    return returnJson.json_error('登录失败')
示例#5
0
def uploadFile(request, **kwargs):
    print(request)
    print(request.META)
    if request.method == 'POST':
        fileform = FileForm(request.POST, request.FILES)
        if fileform.is_valid():
            dic = fileform.cleaned_data
            newfile = File(fid=request.user.id, video=dic.get('file'))
            newfile.save()
            return returnJson.json_responre('success')
        else:
            return returnJson.json_error(fileform.errors)
示例#6
0
def deleFile(requst, **kwargs):
    name = requst.POST.get('name')
    url = name[6:len(name)]
    print(url)
    patch = os.path.join(BASE_DIR, name)
    print(patch)
    if os.path.exists(patch):
        os.remove(patch)
        print(patch)
        try:
            File.objects.get(video=url).delete()
            return returnJson.json_responre('删除成功')
        except:
            return returnJson.json_error("删除失败")
    else:
        return returnJson.json_error("删除失败,图片不存在")
示例#7
0
def get_list_date(request):
    dr = re.compile(r'<[^>]+>', re.S)
    articl = Blog.objects.all().order_by('-creatdate').values()
    dic = dict()
    data = []
    for item in articl:
        item['reContent'] = dr.sub('', item.get('content'))
        date = item['creatdate']
        dateKey = date.strftime("%Y-%m")
        itemData = dic.get(dateKey) if (dic.get(dateKey)) else []
        itemData.append(item)
        dic[dateKey] = itemData
    for key in dic.keys():
        obj = {'date': key, 'data': dic.get(key)}
        data.append(obj)
    return returnJson.json_responre(data)
示例#8
0
def get_topi_content(request):
    obejct = ['json', 'pual', 'george', 'rirga']
    p = Paginator(obejct, 2)
    p = p.page(1).object_list
    return returnJson.json_responre(p, safe=False)
示例#9
0
def get_user_list(requset):
    if requset.method == 'GET':
        data = ForumUser.objects.all()
        data = serializers.serialize("json", data)
        return returnJson.json_responre(json.loads(data), safe=False)
示例#10
0
def get_topic_content(request):
    print(request.POST.get('id'))
    fid = request.POST.get('id')
    model = Blog.objects.get(id=fid)
    u = json.dumps(model_to_dict(model), cls=returnJson.DataTimeEncoder)
    return returnJson.json_responre(json.loads(u), safe=False)
示例#11
0
文件: user.py 项目: David-star6/Blog
def post_api_login(request):
    form = RegisterForm(request.POST)
    if not form.is_valid():
        return returnJson.json_error(form.errors)
    form.save()
    return returnJson.json_responre('success')
示例#12
0
文件: user.py 项目: David-star6/Blog
def get_userCentertitle(request):
    title = UserCenter.objects.all().values()
    return returnJson.json_responre(title)
示例#13
0
文件: user.py 项目: David-star6/Blog
 def post(self, request):
     return returnJson.json_responre('success')
示例#14
0
def getFile(request, **kwargs):
    if request.method == 'GET':
        data = File.objects.all().values()
        for index, item in enumerate(data):
            item['video'] = 'media/' + item.get('video')
        return returnJson.json_responre(data)