• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.Author类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中models.Author的典型用法代码示例。如果您正苦于以下问题:Python Author类的具体用法?Python Author怎么用?Python Author使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Author类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: new_session

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})
开发者ID:Cerebro92,项目名称:arena,代码行数:7,代码来源:views.py


示例2: update_books

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
开发者ID:azizmb,项目名称:whatrur,代码行数:33,代码来源:update_books.py


示例3: setUp

 def setUp(self):
     # Create a few Authors.
     self.au1 = Author(name="Author 1")
     self.au1.save()
     self.au2 = Author(name="Author 2")
     self.au2.save()
     # Create a couple of Articles.
     self.a1 = Article(headline="Article 1", pub_date=datetime(2005, 7, 26), author=self.au1)
     self.a1.save()
     self.a2 = Article(headline="Article 2", pub_date=datetime(2005, 7, 27), author=self.au1)
     self.a2.save()
     self.a3 = Article(headline="Article 3", pub_date=datetime(2005, 7, 27), author=self.au1)
     self.a3.save()
     self.a4 = Article(headline="Article 4", pub_date=datetime(2005, 7, 28), author=self.au1)
     self.a4.save()
     self.a5 = Article(headline="Article 5", pub_date=datetime(2005, 8, 1, 9, 0), author=self.au2)
     self.a5.save()
     self.a6 = Article(headline="Article 6", pub_date=datetime(2005, 8, 1, 8, 0), author=self.au2)
     self.a6.save()
     self.a7 = Article(headline="Article 7", pub_date=datetime(2005, 7, 27), author=self.au2)
     self.a7.save()
     # Create a few Tags.
     self.t1 = Tag(name="Tag 1")
     self.t1.save()
     self.t1.articles.add(self.a1, self.a2, self.a3)
     self.t2 = Tag(name="Tag 2")
     self.t2.save()
     self.t2.articles.add(self.a3, self.a4, self.a5)
     self.t3 = Tag(name="Tag 3")
     self.t3.save()
     self.t3.articles.add(self.a5, self.a6, self.a7)
开发者ID:JWW81,项目名称:stochss,代码行数:31,代码来源:tests.py


示例4: insert_paper

def insert_paper():
    if request.method == 'POST':
        paper = db.session.query(Paper).filter_by(doi=request.json['doi']).first()
        if not paper:
            paper = Paper(year=request.json['year'],
                         title=request.json['title'],
                         abstract=request.json['abstract'],
                         user_id=g.user.id,
                         doi=request.json['doi'])
            db.session.add(paper)
            db.session.flush()
            for author in request.json['authors']:
                paper_author = db.session.query(Author).filter_by(name=author).first()
                if paper_author:
                    paper_author.start_owning(paper)
                else:
                    paper_author = Author(name=author)
                    db.session.add(paper_author)
                    db.session.flush()
                    paper_author.start_owning(paper)
            db.session.commit()
            for doi in request.json['doi_refs']:
                ref_paper = db.session.query(Paper).filter_by(doi=doi).first()
                if ref_paper:
                    paper.start_referencing(ref_paper)
                else:
                    ref_paper = Paper(doi=doi)
                    db.session.add(ref_paper)
                    db.session.flush()
                    paper.start_referencing(ref_paper)
            db.session.commit()
    return json.dumps(dict(data=request.json))
开发者ID:mottam,项目名称:dandelionsearch,代码行数:32,代码来源:views.py


示例5: copyFromArticles

    def copyFromArticles(self, request):
        '''Copies articles and authors from legacy Articles Kind into new Article and Author kinds'''
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException('Authorization required')

        for article in Articles().all():
            if '@' not in article.author:
                author_email = article.author + '@gmail.com'
            else:
                author_email = article.author

            a_key = ndb.Key(Author, author_email)
            author = a_key.get()
            # create new Author if not there
            if not author:
                author = Author(
                    key = a_key,
                    authorID = str(Author.allocate_ids(size=1)[0]),
                    displayName = author_email.split('@')[0],
                    mainEmail = author_email,
                )
                author.put()
            
            self.copyArticlesKind(article, author)

        return BooleanMessage(data=True)
开发者ID:dansalmo,项目名称:new-aca,代码行数:27,代码来源:aca.py


示例6: edit_book

def edit_book(id):
    book = Book.query.get(id)
    if book == None:
        flash("Book is not found")
        return redirect(url_for('books'))
    print book.authors
    form = EditBook(book=book)    
    print form.data, 'hah'
    #form.authors.min_entries = len(book.authors)
    # print form.authors.data
    # form.authors[0].data = book.authors[0].name
    # for author in book.authors[1:]:
    #     form.authors.append_entry(author.name)    
    # print form.authors.data

    if form.validate_on_submit():        
        print form.data
        name = form.data['title']
        newbook = Book.query.filter_by(name=name).first()         
        if newbook and id != newbook.id:
            flash("Can't change name to existing one.")
            return redirect(url_for('edit_book', id=id))
        book.name = name
        authors = list(set([Author.by_name(name=a)
            for a in form.data['authors'] if Author.exists(name=a)]))
        #print authors
        book.authors = authors        
        db.session.commit()
        flash('Changes have been saved.')
        return redirect(url_for('edit_book', id=id))
    return render_template('edit_book.html', form=form)
开发者ID:overborn,项目名称:library,代码行数:31,代码来源:views.py


示例7: make_author

def make_author(author_link, commit=True):
    id = find_int(author_link['href'])
    username = unicode(author_link.string)
    key = db.Key.from_path('Author', int(id))
    author = Author(key=key, username=username)
    if commit:
        author.put()
    return author
开发者ID:mccutchen,项目名称:wongthesis,代码行数:8,代码来源:importer.py


示例8: add_author

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")
开发者ID:clllyw,项目名称:lab4,代码行数:9,代码来源:views.py


示例9: delete_project

def delete_project(project_id):
    """Deletes the project matching the id project_id."""
    project = Project.objects(id=project_id).get()
    project.delete()

    # Removes the project from the list of the author projects.
    Author.objects(id=project.author_id).update_one(pull__projects=project.id)

    return jsonify(project.to_dict())
开发者ID:fendgroupproject,项目名称:backend,代码行数:9,代码来源:main.py


示例10: update_author

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())
开发者ID:fendgroupproject,项目名称:backend,代码行数:9,代码来源:main.py


示例11: addauthor

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))
开发者ID:frankness,项目名称:mygit,代码行数:9,代码来源:views.py


示例12: testBasicModelPKCS7

 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)
开发者ID:bearstech,项目名称:django-signature,代码行数:9,代码来源:tests.py


示例13: worker_authors

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")
开发者ID:certik,项目名称:webhooks,代码行数:56,代码来源:views.py


示例14: author_add

def author_add():
    name = request.args.get('author')
    print name
    print Author.by_name(name)
    if name and not Author.by_name(name):        
        author = Author(name)
        db.session.add(author)
        db.session.commit()
        #return jsonify(author=author)
        return render_template('author.html', author=author)
开发者ID:overborn,项目名称:library,代码行数:10,代码来源:views.py


示例15: author_add

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")
开发者ID:QieHan,项目名称:lab3,代码行数:10,代码来源:views.py


示例16: dispatch_request

 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)
开发者ID:bilunyk,项目名称:elibrary,代码行数:10,代码来源:views.py


示例17: create

def create(request):
    """
    Create an author.
    """
    name = request.POST["name"]

    author = Author(name=name)
    author_id = author.put().id()

    return HttpResponse("Created an author: %s %s " % (name, author_id))
开发者ID:andrewhao,项目名称:mailsafe,代码行数:10,代码来源:author.py


示例18: submitauthor

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/') 
开发者ID:DDawnlight,项目名称:commit,代码行数:11,代码来源:views.py


示例19: add_author

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")
开发者ID:jingyihiter,项目名称:lab3-R1-R7-,代码行数:11,代码来源:views.py


示例20: dbSavePapersAndAuthors

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
开发者ID:breic,项目名称:quantphr,代码行数:53,代码来源:daily.py



注:本文中的models.Author类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Blog类代码示例发布时间:2022-05-27
下一篇:
Python models.Association类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap