Example #1
0
def tips_create(request,site_id,template_name="oa/tips_form.html"):
    schools = get_schools(request.user)
    site = get_object_or_404(WebSite,id=site_id,school__in=schools)
    helpers.set_website_visit(request.user,site)
    try:
        category = get_object_or_404(PartCategory,id=11)
    except:
        category = None
    try:
        part = Part.objects.get(site=site,category=category)
    except:
        part =None
    school = get_schools(request.user)[0]
    if request.method == 'POST':
        form = PartForm(request.POST,category=category,user=request.user,instance=part)
        
        if request.is_ajax():
            return helpers.ajax_validate_form(form) 
        
        if form.is_valid():
            part = form.save(commit=False)
            if not form.cleaned_data['creator']:
                part.creator = request.user.teacher
            part.school = school
            part.category = category
            part.site = site
            part.type = 0
            part.save()
            if part.id:
                messages.success(request, u'已成功修改%s ' % part.category)
                return redirect(reverse('oa_part_con_tips_create',kwargs={'site_id':site.id}))
    else:
        form = PartForm(category=category,user=request.user,instance=part)
    ctx = {'form':form,'category':category,'site':site}
    return render(request, template_name, ctx)
Example #2
0
def announcement_create(request,site_id,template_name="oa/announcement_form.html"):
    schools = get_schools(request.user)
    site = get_object_or_404(WebSite,id=site_id,school__in=schools)
    helpers.set_website_visit(request.user,site)
    category = get_object_or_404(PartCategory,id=9)
    school = get_schools(request.user)[0]
    if request.method == 'POST':
        form = PartForm(request.POST,user=request.user,category=category)
        
        if request.is_ajax():
            return helpers.ajax_validate_form(form)
        
        if form.is_valid():
            part = form.save(commit=False)
            if not form.cleaned_data['creator']:
                part.creator = request.user.teacher
            part.school = school
            part.category = category
            part.site = site
            part.save()
            if part.id:
                messages.success(request, u'已成功创建%s ' % part.category)
                return redirect(reverse('oa_part_con_anc_list',kwargs={'site_id':site.id}))
    else:
        form = PartForm(category=category,user=request.user)
    ctx = {'form':form,'category':category,'site':site}
    return render(request, template_name, ctx)
Example #3
0
def update_part(request,part_id,template_name="oa/part_form.html"):
    schools = get_schools(request.user)
    part = get_object_or_404(Part,id=part_id,site__school__in=schools)
    site = part.site
    helpers.set_website_visit(request.user,site)
    category = part.category
    cid = int(request.GET.get("cid", 5))
    categorys = PartCategory.objects.filter(parent_id=part.category.parent_id).exclude(parent_id=0)
    school = site.school
    if request.method == 'POST':
        form = PartForm(request.POST,category=category,user=request.user,instance=part)
        
        if request.is_ajax():
            return helpers.ajax_validate_form(form)
        
        if form.is_valid():
            cid = int(request.POST.get("cid"))
            category = get_object_or_404(PartCategory,id=cid)
            part = form.save(commit=False)
            if not form.cleaned_data['creator']:
                part.creator = request.user.teacher
            part.save()
            if part.id:
                messages.success(request, u'已成功创建%s ' % part.category)
#                return redirect("oa_website_list")
    else:
        form = PartForm(category=category,user=request.user,instance=part)
    ctx = {'form':form,'category':category,'categorys':categorys,'site':site}
    return render(request, template_name, ctx)
Example #4
0
def create_part(request,site_id,template_name="oa/part_form.html"):
    schools = get_schools(request.user)
    site = get_object_or_404(WebSite,id=site_id,school__in=schools)
    helpers.set_website_visit(request.user,site)
    cid = int(request.GET.get("cid", 5))
    try:
        category = get_object_or_404(PartCategory,id=cid)
    except:
        category = None
    try:
        if category.id == 4:
            part = None
        else:
            part = Part.objects.get(site=site,category=category)
        
    except:
        part =None

        
    categorys = []
    if category and category.parent_id == 1:
        categorys = PartCategory.objects.filter(parent=category.parent)
    school = site.school
    if request.method == 'POST':
        form = PartForm(request.POST,category=category,user=request.user,instance=part)
        
        if request.is_ajax():
            return helpers.ajax_validate_form(form)
        
        if form.is_valid():
            cid = int(request.POST.get("cid",0))
            category = get_object_or_404(PartCategory,id=cid)
            part = form.save(commit=False)
            if not form.cleaned_data['creator']:
                part.creator = request.user.teacher
            part.school = school
            part.category = category
            part.site = site
#             part.video_type = 0
#             part.type = 0
            print category,'ccccccccccc'
            part.save()
            if part.id:
                messages.success(request, u'已成功修改%s ' % part.category)
                if part.category_id == 4:
                    return redirect(reverse('oa_part_teache',kwargs={'site_id':site.id}))
    else:
        form = PartForm(category=category,user=request.user,instance=part)
    ctx = {'form':form,'category':category,'categorys':categorys,'site':site,'school':school}
    return render(request, template_name, ctx)
Example #5
0
def article_create(request,site_id,template_name="oa/article_form.html"):
    """添加精彩文章"""
    schools = get_schools(request.user)
    site = get_object_or_404(WebSite,id=site_id,school__in=schools)
    category = get_object_or_404(PartCategory,id=19)
    if request.method == 'POST':
        form = PartForm(request.POST,category=category)
        if form.is_valid():
            part = form.save(commit=False)
            if not form.cleaned_data['creator']:
                part.creator = request.user.teacher
            part.category = category
            part.site = site
            part.save()
            if part.id:
                messages.success(request, u'已成功创建%s ' % part.title)
                return redirect(reverse('oa_article_list',kwargs={'site_id':site.id}))
    else:
        form = PartForm(category=category)
    ctx = {'form':form,'site':site,'category':category}
    return render(request, template_name,ctx)
Example #6
0
def article_update(request,article_id,template_name="oa/article_form.html"):
    """更新精彩文章"""
    schools = get_schools(request.user)
    article = get_object_or_404(Part,id=article_id,site__school__in=schools)
    site = article.site
    category = article.category
    if request.method == 'POST':
        form = PartForm(request.POST,instance=article,category=category)
        if form.is_valid():
            part = form.save(commit=False)
            if not form.cleaned_data['creator']:
                part.creator = request.user.teacher
#            part.category = category
#            part.site = site
            part.save()
            if part.id:
                messages.success(request, u'已成功修改%s ' % part.title)
                return redirect(reverse('oa_article_list',kwargs={'site_id':site.id}))
    else:
        form = PartForm(instance=article,category=category)
    ctx = {'form':form,'site':site,'category':category,'article':article}
    return render(request, template_name,ctx)
Example #7
0
def update_news(request,part_id,template_name="oa/news_form.html"):
    schools = get_schools(request.user)
    part = get_object_or_404(Part,id=part_id,site__school__in=schools)
    site = part.site
    helpers.set_website_visit(request.user,site)
    category = part.category
    if request.method == 'POST':
        form = PartForm(request.POST,category=category,user=request.user,instance=part)
        
        if request.is_ajax():
            return helpers.ajax_validate_form(form)
        
        if form.is_valid():
            part = form.save(commit=False)
            if not form.cleaned_data['creator']:
                part.creator = request.user.teacher
            part.save()
            if part.id:
                messages.success(request, u'已成功修改%s ' % part.category)
                return redirect(reverse('oa_part_con_news_list',kwargs={'site_id':site.id}))  
    else:
        form = PartForm(category=category,user=request.user,instance=part)
    ctx = {'form':form,'category':category,'site':site}
    return render(request, template_name, ctx)
Example #8
0
def update_video(request,part_id,template_name="oa/video_form.html"):
    schools = get_schools(request.user)
    part = get_object_or_404(Part,id=part_id,site__school__in=schools)
    site = part.site
    helpers.set_website_visit(request.user,site)
    category = part.category
    form = PartForm(category=category,user=request.user,instance=part)
    if request.method == 'POST':
        chunks = request.POST.get('chunks')
        if chunks:#if request.is_ajax():
            f = request.FILES["video"]
            chunk = int(request.POST.get('chunk'))
            chunks = int(chunks)
            file_id = request.POST.get('file_id')
            name = request.POST.get('name')
            
            file_path = FILE_PATH + '/temp/' + str(file_id)
            fp = open(file_path,"a+b")
            fp.write(f.read())
            fp.close()
            
            if chunk + 1  == chunks:
                filename = 'part/' + str(file_id) + '.' +  name.split('.')[-1].lower()

                try:
                    URL('http://' + SITE_INFO.domain + reverse('cron_make_large_img')).post_async(filename=filename,file_path=file_path)
                except:
                    fr = open(file_path,"rb")
                    content = fr.read()
                    fr.close()
                    if os.path.isfile(file_path):
                        os.remove(file_path)
                    AliyunStorage(). _put_file(filename, content)
                    
                part = Part()
                part.creator = request.user.teacher
                part.school = school
                part.category = category
                part.site = site
                part.video = filename
                part.title = request.POST.get('title',name)
                part.video_type = request.POST.get('video_type') or 0
                part.type = request.POST.get('type') or 0
                part.save()
                if part.id:
                    data = json.dumps({'status':1,'desc':"ok"})
                    return HttpResponse(data)

            else:
                return HttpResponse(json.dumps({'status':1,'desc':"ok"}))
            data = json.dumps({'status':0,'desc':"error"})
            return HttpResponse(data) 
        else:
            form = PartForm(request.POST,request.FILES,user=request.user,category=category,instance=part)
            if form.is_valid():
                part = form.save(commit=False)
                if not form.cleaned_data['creator']:
                    part.creator = request.user.teacher
                part.save()           
                if part.id:
                    messages.success(request, u'已成功修改%s ' % part.category)
                    return redirect(reverse('oa_part_con_video_list',kwargs={'site_id':site.id}))   
    else:
        form = PartForm(category=category,user=request.user,instance=part)
    ctx = {'form':form,'category':category,'site':site,'part':part}
    return render(request, template_name, ctx)