コード例 #1
0
 def post(self, request):
     form = CourseForm(request.POST)
     if form.is_valid():
         data = form.cleaned_data
         title = data.get('title')
         category_id = int(data.get('category'))
         teacher_id = int(data.get('teacher'))
         link = data.get('link')
         times = data.get('times')
         cover = data.get('cover')
         price = data.get('price')
         absract = data.get("abstract")
         teacher = CourseTeacher.objects.get(pk=teacher_id)
         category = CourseCategory.objects.get(pk=category_id)
         try:
             Course.objects.create(title=title,
                                   category=category,
                                   teacher=teacher,
                                   link=link,
                                   times=times,
                                   cover=cover,
                                   price=price,
                                   abstract=absract)
             return restiful.success(message="成功添加文章")
         except Exception as e:
             return restiful.paramserror(message=e)
     else:
         return restiful.paramserror(data=form.get_errors())
コード例 #2
0
ファイル: views.py プロジェクト: heyadong/my_django_webapp
 def post(self, request):
     form = ArticleForm(request.POST)
     if form.is_valid():
         data = form.cleaned_data
         title = data.get('title')
         description = data.get('description')
         thumbnail = data.get('thumbnail')
         tag = data.get("tag")
         categoryTag = NewsTag.objects.get(pk=tag)
         content = data.get('content')
         # 登陆功能出翔bug 暂时指定发布作者
         # author = request.user
         author = User.object.get(pk='Bx9BnppGDx4gwqjwQ8rLvD')
         print(author)
         print(thumbnail)
         print(title, description, thumbnail, tag, content)
         try:
             Article.objects.create(title=title,
                                    thumbnail=thumbnail,
                                    description=description,
                                    tag=categoryTag,
                                    content=content,
                                    author=author)
             return restiful.success()
         except:
             return restiful.paramserror(message="参数错误")
     else:
         return restiful.paramserror(data=form.get_errors())
コード例 #3
0
ファイル: views.py プロジェクト: heyadong/my_django_webapp
 def post(self, request):
     form = TagForm(request.POST)
     if form.is_valid():
         data = form.cleaned_data
         name = data.get('tag')
         exist_tags = NewsTag.objects.filter(name=name)
         if exist_tags:
             return restiful.paramserror(message="标签已经存在")
         tag = NewsTag(name=name)
         tag.save()
         return redirect(reverse("cms:category"))
     else:
         return restiful.paramserror(message='参数错误')
コード例 #4
0
 def post(self, request):
     form = CourseCategoryForm(request.POST)
     if form.is_valid():
         data = form.cleaned_data
         category = data.get('category')
         print(category)
         exist_tags = CourseCategory.objects.filter(category=category)
         if exist_tags:
             return restiful.paramserror(message="标签已经存在")
         tag = CourseCategory(category=category)
         tag.save()
         return redirect(reverse("cms:course_category"))
     else:
         return restiful.paramserror(message='参数错误', data=form.get_errors())
コード例 #5
0
ファイル: views.py プロジェクト: heyadong/my_django_webapp
def uplaod(request):
    form = BannerForm(request.POST, request.FILES)
    if form.is_valid():
        form.save()
        return restiful.success()
    else:
        return restiful.paramserror(message=form.get_errors())
コード例 #6
0
ファイル: views.py プロジェクト: heyadong/DjangoNewsSite
def news_comment(request):
    form = CommentForms(request.POST)
    if form.is_valid():
        data = form.cleaned_data
        content = data.get('content')
        news_id = int(data.get('article'))
        author = request.user  # 当前默认登陆用户
        article = Article.objects.get(pk=news_id)
        try:
            Comments.objects.create(content=content,
                                    author=author,
                                    article=article)
            return restiful.success()
        except:
            return restiful.paramserror(message="服务器内部错误,添加评论失败")
    else:
        return restiful.paramserror(data=form.get_errors())
コード例 #7
0
def course_delete(request):
    course_id = request.POST.get('course_id')
    try:
        course = Course.objects.get(pk=course_id)
        course.delete()
        return restiful.success(message="成功删除电影")
    except:
        return restiful.paramserror(message="要删除的文章不存在")
コード例 #8
0
def coursecategory_del(request):
    category_id = request.POST['category_id']
    course_category = CourseCategory.objects.get(pk=category_id)
    if course_category:
        course_category.delete()
        return restiful.success()
    else:
        return restiful.paramserror(message="删除的分类不存在")
コード例 #9
0
ファイル: views.py プロジェクト: heyadong/DjangoNewsSite
def bannersdelete(request):
    banners_id = request.POST['banners_id']
    banner = Banners.objects.get(pk=banners_id)
    if banner:
        banner.delete()
        return restiful.success(message="删除轮播图成功")
    else:
        return restiful.paramserror(message="删除的轮播图不存在")
コード例 #10
0
ファイル: views.py プロジェクト: heyadong/my_django_webapp
def tag_delete(request, id):
    # 新闻分类删除
    if id:
        tag = NewsTag.objects.get(id=id)
        tag.delete()
        return restiful.success(message="删除标签成功")
    else:

        return restiful.paramserror(message="删除的标签不存在")
コード例 #11
0
def coursecategory_edit(request):
    category_id = request.POST['category_id']
    tag_name = request.POST['name']
    print(tag_name)
    category = CourseCategory.objects.get(pk=category_id)
    if category:
        category.category = tag_name
        category.save()
        return restiful.success()
    else:
        return restiful.paramserror(message="更改的课程分类不存在")
コード例 #12
0
def login_view(request):
    form = LoginForm(request.POST)
    if form.is_valid():
        telephone = form.cleaned_data.get('telephone')
        password = form.cleaned_data.get('password')
        remember = form.cleaned_data.get('remember')
        user = authenticate(request, username=telephone, password=password)
        if user:
            if user.is_active:
                login(request, user)  # 登陆
                if remember:
                    request.session.set_expiry(None)  # 设置cookies有效期
                else:
                    request.session.set_expiry(0)  # 0是浏览器会话结束时cookies失效
                return restiful.success(message='success')
            else:
                return restiful.unauth(message="用户账号被移除")
        else:
            return restiful.paramserror(message="输入用户名或密码错误")
    else:
        errors = form.get_errors()
        return restiful.paramserror(message=errors)
コード例 #13
0
ファイル: views.py プロジェクト: heyadong/my_django_webapp
def tag_edit(request):
    # 新闻分类编辑
    form = TagForm2(request.POST)
    if form.is_valid():
        data = form.cleaned_data
        tag_name = data.get('tag')
        tag_id = data.get('id')
        try:
            tag = NewsTag.objects.get(id=tag_id)
            tag.name = tag_name
            tag.save()
            return restiful.success()
        except:
            return restiful.paramserror("编辑的的标签不存在")
コード例 #14
0
def register_view(request):
    user = get_user_model()
    form = RegisterForm(request.POST)
    if form.is_valid():
        data = form.cleaned_data
        telephone = data.get('telephone')
        username = data.get('username')
        password = data.get('password1')
        print(telephone, username, password)
        user.object.create_user(username=username,
                                telephone=telephone,
                                password=password)
        return restiful.success(message='注册成功')
    else:
        errors = form.get_errors()
        return restiful.paramserror(message=errors)
コード例 #15
0
ファイル: views.py プロジェクト: heyadong/DjangoNewsSite
def banners(request):
    # 轮播图页面 (新增功能)
    if request.method == "POST":

        form = BannerForm(request.POST)
        if form.is_valid():
            data = form.data
            bannersimg = data.get('bannersimg')
            link_to = data.get('link_to')
            position = data.get('position')
            Banners.objects.create(bannersimg=bannersimg,
                                   link_to=link_to,
                                   position=position)
            return restiful.success(message="添加轮播图成功")
        else:
            return restiful.paramserror(data=form.get_errors())
    banners = Banners.objects.all()
    return render(request,
                  'CMS/cms_banners.html',
                  context={'banners': banners})