本文整理汇总了Python中models.Author.save方法的典型用法代码示例。如果您正苦于以下问题:Python Author.save方法的具体用法?Python Author.save怎么用?Python Author.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Author
的用法示例。
在下文中一共展示了Author.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_session
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def new_session(request):
q=Author(name=request.GET['name'],email=request.GET['email'],password=request.GET['password'])
q.save()
request.session['author_id']=q.id
request.session['author_name']=q.name
request.session['author_email']=q.email
return render(request,'../../demo/templates/nsession.html',{"author":q})
示例2: update_books
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def update_books(books = get_books()):
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
for book in books:
try:
b = Book.objects.filter(title=book['title']).count()
print '>>>', b
if not b:
b = Book()
b.title = book['title']
author = book['author']
last_name = author.split(' ')[-1]
first_name = ' '.join(author.split(' ')[:-1])
try:
author = Author.objects.get(first_name=first_name, last_name=last_name)
except:
author = Author(first_name=first_name, last_name=last_name)
author.save()
b.author = author
b.external_url = 'http://en.wikipedia.org'+book['link']
try:
content = opener.open('http://en.wikipedia.org'+book['link']).read()
s = Soup(content)
info = s.find('table', {'class':'infobox'})
img = info.find('img')
if img:
b.image = 'http:'+img.get('src')
except:
print "IMAGE FAILED FOR", book
b.save()
except Exception, e:
print e
print "WOAH TOTAL FAILURE", book
示例3: testBasicModelSignature
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def testBasicModelSignature(self):
"""Try to sign a basic model and get a Signature
"""
# Sign
auth1 = Author(name="Raymond E. Feist", title="MR")
auth1.save()
self.c_cert.save()
signed = self.c_cert.make_signature(auth1, self.c_pwd)
self.assertTrue(isinstance(signed, Signature))
content_type = ContentType.objects.get_for_model(auth1)
self.assertEqual(signed.content_type, content_type)
self.assertEqual(signed.object_id, 1)
signed.save()
# Verify
signed = Signature.objects.get(pk=1)
result = signed.check_pkcs7()
self.assertTrue(result)
result = signed.check()
self.assertTrue(result)
auth1.name = "JR"
auth1.save()
signed = Signature.objects.get(pk=1)
result = signed.check()
self.assertFalse(result)
示例4: toaddauthored
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def toaddauthored(request):
author=Author()
author.name=request.GET['name']
author.age=request.GET['age']
author.country=request.GET['country']
author.AuthorID=request.GET['authorid']
author.save()
return render_to_response('addauthorsucceed.html')
示例5: testBasicModelPKCS7
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def testBasicModelPKCS7(self):
"""Try to sign a basic model
"""
# Sign
auth1 = Author(name="Raymond E. Feist", title="MR")
auth1.save()
data_signed = self.c_cert.sign_model(auth1, self.c_pwd)
result = self.c_cert.verify_smime(data_signed)
self.assertTrue(result)
示例6: add_author
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def add_author(request):
if request.POST:
post = request.POST
if post["AuthorID"] and post["Name"] and post["Age"] and post["Country"]:
new_author = Author(AuthorID=post["AuthorID"], Name=post["Name"], Age=post["Age"], Country=post["Country"])
new_author.save()
else:
return HttpResponse("Please full all information.")
return render_to_response("add_author.html")
示例7: update_author
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def update_author(author_id):
"""Updates the author matching the id author_id.
Only the parameters to update or to add should be passed in the request body.
"""
author = Author.objects(id=author_id).get()
patched = Author(**dict(chain(author.to_dict().items(), request.get_json().items())))
patched.save()
return jsonify(patched.to_dict())
示例8: addauthor
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def addauthor(request):
if request.POST:
post = request.POST
new_author = Author(
Name = post["name"],
Age = post["age"],
Country = post["country"])
new_author.save()
return render_to_response('addauthor.html',context_instance=RequestContext(request))
示例9: worker_authors
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def worker_authors(request):
r = Repository.get(db.Key(request.POST["repo"]))
logging.info("processing repository: %s" % r.name)
base_url = "http://github.com/%s/%s" % (r.owner.name, r.name)
url = base_url + "/network_meta"
logging.info(" downloading network_meta from: %s" % url)
try:
s = urllib2.urlopen(url).read()
except urllib2.HTTPError:
logging.info("Probably bad repo, skipping.")
return HttpResponse("Probably bad repo, skipping.\n")
logging.info(" network_meta loaded")
try:
data = simplejson.loads(s)
except ValueError:
logging.info("Probably bad repo, skipping.")
return HttpResponse("Probably bad repo, skipping.\n")
logging.info(" network_meta parsed")
dates = data["dates"]
nethash = data["nethash"]
url = "%s/network_data_chunk?nethash=%s&start=0&end=%d" % (base_url,
nethash, len(dates)-1)
logging.info(" downloading commits from: %s" % url)
s = urllib2.urlopen(url).read()
logging.info(" parsing commits...")
data = simplejson.loads(s, encoding="latin-1")
logging.info(" processing authors...")
commits = data["commits"]
m = [(x["author"], x["id"]) for x in commits]
m = dict(m)
logging.info(m)
authors = m.keys()
authors = list(set(authors))
authors.sort()
logging.info(authors)
queue = get_github_queue()
for author in authors:
q = User.gql("WHERE name = :1", author)
u = q.get()
if u is None:
u = User(name=author, email="None")
u.save()
task = taskqueue.Task(url="/hooks/worker/user_email/",
params={'user': u.key(),
'r_user_id': r.owner.name,
'r_repository': r.name,
'r_sha': m[u.name]
})
queue.add(task)
q = Author.gql("WHERE user = :1 AND repo = :2", u, r)
a = q.get()
if a is None:
a = Author(repo=r, user=u)
a.save()
logging.info(" done.")
return HttpResponse("OK\n")
示例10: dispatch_request
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def dispatch_request(self):
form = AuthorForm()
form.books.query = Book.query.all()
if request.method == "POST":
if form.validate_on_submit():
obj = Author()
form.populate_obj(obj)
obj.save()
return redirect("/authors/")
return render_template("author_add.html", form=form)
示例11: author_add
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def author_add(request):
if request.POST:
post = request.POST
new_author = Author(
AuthorID = post["AuthorID"],
Name = post["Name"],
Age = post["Age"],
Country = post["Country"])
new_author.save()
return render_to_response("add_author.html")
示例12: submitauthor
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def submitauthor(request):
if request.POST:
post = request.POST
new_author = Author(
AuthorID = post["id"],
Name = post["name"],
Age = post["age"],
Country=post["country"]
)
new_author.save()
return HttpResponseRedirect('/authorlist/')
示例13: add_author
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def add_author(request):
"""添加作者"""
if request.POST:
post = request.POST
new_Author = Author(
name = post['name'],
age = post['age'],
country = post['country']
)
new_Author.save()
return render_to_response("add_author.html")
示例14: dbSavePapersAndAuthors
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def dbSavePapersAndAuthors(papers, latestMailing=True):
"""Saves an array of paper information into the database. Returns numbers of new papers and authors added.
If the latestMailing argument is true, then sets the paper dates to either today or tomorrow,
regardless of the date from the arXiv. It sets to today if the function is run before 8pm ET, and to
tomorrow otherwise. The idea is that this function should be run regularly every day, the night that the
mailing goes out. If run late in the day before midnight, then the mailing has tomorrow's date. If run
early in the day, e.g., if for some reason it didn't run when it should have, then the mailing was sent out
yesterday and is for today.
"""
if latestMailing:
latestMailingDate = datetime.date.today()
now = datetime.datetime.now(pytz.timezone('US/Eastern'))
cutoff = now.replace(hour=20,minute=0,second=0,microsecond=0)
if now > cutoff:
latestMailingDate += datetime.timedelta(days=+1) # note: The official mailing date is the day the email goes out, a few hours after the paper was made available
numNewPapersAdded = numNewAuthorsAdded = 0
for paper in papers:
authors = []
for author in paper['authors']:
authorsWithSameName = Author.objects.filter(name=author)
if authorsWithSameName: # author with same name already exists in database---don't add a duplicate
a = authorsWithSameName[0] # there might be duplicates --- take the first (maybe fix later)
else:
a = Author(name=author)
a.save()
numNewAuthorsAdded += 1
authors.append(a)
if Paper.objects.filter(arxivId=paper['arxivId']): continue # NOTE: If we make a mistake adding the paper the first time, this line will keep the code below from ever running to fix it
if latestMailing:
mailing_date = latestMailingDate
else:
mailing_date = mailingDate(paper['datePublished'])
p = Paper(
arxivId = paper['arxivId'],
title = paper['title'],
abstract = paper['abstract'],
date_published = paper['datePublished'],
date_mailed = mailing_date,
#authors = authors, # ManyToManyField is set up later
category = paper['category'],
categories = paper['categories'],
version = paper['version'],
linkAbsPage = paper['linkAbsPage'],
linkPdf = paper['linkPdf']
)
p.save() # need to save before setting up the ManyToMany field of authors
for author in authors: # alternatively, to clear a ManyToMany field, use p.authors.clear()
p.authors.add(author)
p.save()
numNewPapersAdded += 1
print "%d new papers, %d new authors added" % (numNewPapersAdded, numNewAuthorsAdded)
return numNewPapersAdded, numNewAuthorsAdded
示例15: authors
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import save [as 别名]
def authors():
"""Retrieves a list of authors from the database or create a new author.
When retrieving a list of authors, the URL can contain pagination parameters
page and per_page which default to 1 and 10 if omitted.
"""
if request.method == 'GET':
return paginate(resource_name='authors', endpoint='authors', objects=Author.objects)
author = Author(**request.get_json())
author.save()
return jsonify(author.to_dict()), 201