Example #1
0
def author_add(request):
    if request.POST:
        error = False
        if re.search(r'[^\d]',request.POST['year']):
            error = True
        try:
            if not error:
                post = request.POST
                if post['name']=="" or post['year']=='' or post['ID']=='':
                    return render_to_response("author_add.html",{'judge':False,})
                new_people = Author(
                    name = post["name"],
                    Age = post["year"],
                    Author_ID = post['ID'],
                    Country = post["Country"],
                    sex = True)    
                if post["sex"] == 'M':
                    new_people.sex = True
                else:
                    new_people.sex = False       
                new_people.save()
            else:
                return render_to_response("author_add.html",{'judge':False,})
        except:
            return render_to_response("author_add.html",{'judge':False,})
    return render_to_response("author_add.html",{'judge':True,})
Example #2
0
def add_author(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect("/login/")
    user=request.user.username
    if request.POST:
        post = request.POST
        new_author = Author(
            user = request.user.username,
            Name = post["Name"],
            Age = post["Age"],
            Country = post["Country"])
        new_author.save()
    return render_to_response("add_author.html")
Example #3
0
def newauthor(post):
    """"to get the room for book to store"""
    new_author = Author(authorid=post["authorid"],
                        name=post["name"],
                        age=post["age"],
                        country=post["country"])
    return new_author
Example #4
0
def add2(request):
    if request.POST:
        post = request.POST
        havenoword2=True
    	if((len(post["AuthorID"])!=0) and (len(post["Name"])!=0)):
                havenoword2=False
                new_author = Author(
                        AuthorID = post["AuthorID"],
                        Name = post["Name"],
                        Age = post["Age"],
                        Countury = post["Countury"])         
                new_author.save()  
                return HttpResponseRedirect("/add/")
        return render_to_response("add2.html",{"havenoword":havenoword2})
    else:
        return render_to_response("add2.html")
Example #5
0
def add_author(request):
    post=request.POST
    c={}
    if post:
        author=Author.objects.filter(AuthorID=post["authorid"],)
        if author:
            c={"error":"this ID is exsited!",}
        else:
            c={"error":"success!",}
            new_author=Author(
                AuthorID=post["authorid"],
                Name=post["name"],
                Age=post["age"],
                Country=post["country"],
              )
            new_author.save()
    return render(request,'add_author.html',c,context_instance=RequestContext(request))