Esempio n. 1
0
def create(request,template_name="oa/website_form.html"):
    
    school = get_schools(request.user)[0]
    schools = get_schools(request.user)
    domain_string = helpers.get_parent_domain_string(request)
    if request.method == 'POST':
        form = WebSiteForm(request.POST)
        print form.errors
        if request.is_ajax():
            return helpers.ajax_validate_form(form)
        
        if form.is_valid():
            school_id = request.POST.get("school", '')
            if school_id:
                school = School.objects.get(pk=school_id)
                
            print school,'sssssss'
#            type = form.cleaned_data['type']
#            print type,'tttttttttt'
            website = form.save(commit=False)
            website.creator = request.user
#            if not type:
#                website.domain = website.domain + '.' + domain_string
            website.school = school
            website.save()
            if website.id:
                messages.success(request, u'已成功创建网站%s ' % website.name)
                return redirect("oa_website_list")
    else:
        form = WebSiteForm()
    
    ctx = {'form':form,'schools':schools,'school':school,'domain_string':domain_string}
    return render(request, template_name, ctx)
Esempio n. 2
0
def update_website(request,site_id,template_name="oa/website_detail.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)
    if request.method == 'POST':
        form = WebSiteForm(request.POST,request.FILES,instance=site)
        
        if request.is_ajax():
            return helpers.ajax_validate_form(form)
        print form.errors,'eeeeeeeeee'
        if form.is_valid():
            site = form.save(commit=False)
            site.save()
            messages.success(request, u'已成功修改网站%s ' % site.name)
            return redirect(request.get_full_path())
    else:
        form = WebSiteForm(instance=site)
    ctx = {'form':form,'site':site}
    return render(request, template_name, ctx)
Esempio n. 3
0
def edit_website(request,site_id,template_name="oa/website_form.html"):
    schools = get_schools(request.user)
    site = get_object_or_404(WebSite,id=site_id,school__in=schools)
    school = site.school
    domain_string = helpers.get_parent_domain_string(request)
    if request.method == 'POST':
        form = WebSiteForm(request.POST,instance=site)
#        print form.errors
        if form.is_valid():
            website = form.save(commit=False)
            website.creator = request.user
            website.school = school
            website.save()
            if website.id:
                messages.success(request, u'已成功更新网站%s ' % website.name)
                return redirect("oa_website_list")
    else:
        form = WebSiteForm(instance=site)
    
    ctx = {'form':form,'schools':schools,'school':school,'domain_string':domain_string,'site':site}
    return render(request, template_name, ctx)