本文整理汇总了Python中models.Entry.save方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.save方法的具体用法?Python Entry.save怎么用?Python Entry.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Entry
的用法示例。
在下文中一共展示了Entry.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resume
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def resume(user, customer, comment = "", delay = 0):
"""
Start/Resume the current task. Delay specifies how far back (in minutes) the task is started.
"""
topTaskEntry = getCurrentTaskEntry(user)
# check whether there already is a task running
if not isAnyTaskRunning(user):
# make sure tasks don't overlap
if not topTaskEntry or (datetime.now() - timedelta(0, 0, 0, 0, delay) > topTaskEntry.end):
start = datetime.now() - timedelta(0, 0, 0, 0, delay)
else:
start = topTaskEntry.end + timedelta(0, 1)
# no task running, so let's create a new entry
newTaskEntry = Entry(owner = user, customer = customer, start = start, comment = comment)
newTaskEntry.save()
else:
# there is a task running and either the customer or the comment has changed
if topTaskEntry.customer != customer or topTaskEntry.comment != comment:
# not for the same customer, so finish the current task and start a new one
topTaskEntry.end = datetime.now()
topTaskEntry.save()
if datetime.now() - timedelta(0, 0, 0, 0, delay) > topTaskEntry.end:
start = datetime.now() - timedelta(0, 0, 0, 0, delay)
else:
start = topTaskEntry.end + timedelta(0, 1)
newTaskEntry = Entry(owner = user, customer = customer, start = start, comment = comment)
newTaskEntry.save()
else:
# Nothing has changed, so we can keep the task running
pass
示例2: resave_entries
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def resave_entries():
""" Fetch and re-save all entries """
entries = db.get_all_entries()
for item in entries:
print("Updating entry {} from user {}".format(item.get('id'), item.get('created_by')))
entry = Entry(id=item.get('id'), created_by=item.get('created_by'))
entry.save()
示例3: test_existing_id
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def test_existing_id(self):
client = Client()
entry = Entry(title="Hello World!", body="Test Suite action!")
entry.save()
pk = entry.id
response = client.get('/entry/' + str(pk))
self.assertEqual(response.status_code, 200)
示例4: syncWeibo
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def syncWeibo(request):
WBLogin = weiboLogin.weiboLogin()
if WBLogin.login('[email protected]','1234qwer')==1:
urlContent = urllib2.urlopen('http://game.weibo.com/club/forum-315-1').read()
soup = BeautifulSoup(urlContent)
ul = soup.find('ul',{'class':'top_topics'})
lis = ul.findAll('li',{'class':''})
for li in lis:
item = {
'user':li.find('div',{'class':'col1'}).find('img')['alt'],
'link':li.find('div',{'class':'no_rep_line'}).findAll('a')[1]['href'],
'tag':li.find('a',{'class':'navy_tag'}).string,
'title':li.find('div',{'class':'no_rep_line'}).findAll('a')[1].string,
'time':li.find('div',{'class':'col2'}).find('span').string
}
title = "[%s][%s]%s%s"%(item['time'],item['user'],item['tag'],item['title'])
link = item['link']
result = Entry.objects.filter(title=title)
if len(result) == 0:
entry = Entry(title=title,link=link,content='',feedid=0)
entry.save()
send_mail("[email protected]", title, link,
("smtp.163.com", 25, "[email protected]", "1234qwer", False))
pass
pass
return HttpResponse("Login success!")
else:
return HttpResponse("Login error!")
pass
示例5: entries
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def entries(request):
queryset = Entry.objects.order_by('-publication_date')[:5]
logged_in = False
if request.session.get('logged_in'):
logged_in = True
if request.method == 'POST':
form = EntryForm(request.POST)
if form.is_valid():
title = form.cleaned_data['title']
author = User.objects.get(id=request.session.get('user'))
text = form.cleaned_data['text']
new_entry = Entry(text=text, title=title, author=author)
new_entry.save()
form = EntryForm()
else:
form = EntryForm()
else:
form = None
logged_in = False
e_dict = archive_dict()
return render(request, 'entry_list.html', {
'form': form,
'list_of_entries': queryset,
'logged_in': logged_in,
'e_dict': e_dict},
)
示例6: generateFeedEntry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def generateFeedEntry(urlContent,feed):
encodeType = feed['encoding']
urlContent = urlContent.decode(encodeType).encode('utf-8')
global_pattern = re.compile(feed['global_search_pattern'].replace('{%}','(.*?)').replace('{*}','.*?'),re.I|re.S|re.M)
item_pattern = re.compile(feed['item_search_pattern'].replace('{%}','(.*?)').replace('{*}','.*?'),re.I|re.S|re.M)
sub_pattern = re.compile(r'{%(.*?)}',re.I|re.S|re.M)
globalMatch = global_pattern.search(urlContent)
globalContent = globalMatch.group()
globalContent = globalContent[0:len(globalContent)/4]
itemList = item_pattern.findall(globalContent)
print len(itemList)
for i in xrange(len(itemList)-1,-1,-1):
item = itemList[i]
link = feed['item_link']
title = feed['item_title']
content = feed['item_content']
link = sub_pattern.sub(lambda m: str(item[int(m.group(1))-1]),link)
content = sub_pattern.sub(lambda m: str(item[int(m.group(1))-1]),content)
title = sub_pattern.sub(lambda m: str(item[int(m.group(1))-1]),title)
result = Entry.objects.filter(title=title)
if len(result) == 0:
entry = Entry(title=title,link=link,content=content,feedid=feed['id'])
entry.save()
if feed['mail_address']!='':
send_mail(feed['mail_address'], title, link,
("smtp.163.com", 25, "[email protected]", "1234qwer", False))
pass
pass
pass
示例7: add_entry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def add_entry(request):
title = json.loads(request.body)['title']
text = json.loads(request.body)['text']
entry = Entry(user=request.user, title=title, text=text)
entry.save()
data = json.dumps(Entry.serialize(entry))
return HttpResponse(data, content_type="application/json")
示例8: testUndoMyEntry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def testUndoMyEntry(self):
try:
s = get_object_or_404(ProgramSlot, pk=1)
u = get_object_or_404(User, pk=1)
e = Entry(pk=2, notes="", slot=s, user=u)
e.save()
except Http404, e:
self.fail("Something doesn't exist.")
示例9: update_entry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def update_entry(entry_id=None):
'''Update an existing entry at /update/entry_id/ or make a new one at /update/.
Returns the entry_id of the new or updated entry.'''
entry = Entry()
if entry_id != None:
entry = Entry.objects(id=entry_id)[0]
revision = Revision(content=request.form['content'], rows=request.form['rows'])
entry.add_revision(revision)
entry.save()
return str(entry.id)
示例10: pull_feeds
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def pull_feeds(request):
sources = Source.objects.filter(usersource__user=request.user)
for source in sources:
if source.xml_url:
d = feedparser.parse(source.xml_url)
#update source with attributes from feed
if 'icon' in d.feed:
source.icon_url = d.feed.icon
if 'updated_parsed' in d.feed and d.feed.updated_parsed is not None:
source.updated_parsed = datetime.fromtimestamp(mktime(d.feed.updated_parsed))
source.save()
#print [field for field in d]
for e in d['entries']:
if 'published_parsed' in e:
entry_published_date = datetime.fromtimestamp(mktime(e.published_parsed)) #feed timestamp
if source.updated_parsed is None or entry_published_date>source.updated_parsed:
entry = Entry(source=source, title=e.title, raw=e)
if 'author_detail' in e:
if 'name' in e.author_detail:
entry.author_name = e.author_detail.name
if 'href' in e.author_detail:
entry.author_href = e.author_detail.href
if 'email' in e.author_detail:
entry.author_email = e.author_detail.email
if 'comments' in e:
entry.comments_href = e.comments
if 'content' in e:
entry.content = e.content
if 'contributors' in e:
entry.contributors = e.contributors
if 'link' in e:
entry.link = e.link
if 'links' in e:
entry.links = e.links
if 'created_parsed' in e:
entry.created_parsed = datetime.fromtimestamp(mktime(e.created_parsed)) #feed timestamp
if 'expired_parsed' in e:
entry.expired_parsed = datetime.fromtimestamp(mktime(e.expired_parsed)) #feed timestamp
if 'published_parsed' in e:
entry.published_parsed = datetime.fromtimestamp(mktime(e.published_parsed)) #feed timestamp
if 'updated_parsed' in e:
entry.updated_parsed = datetime.fromtimestamp(mktime(e.updated_parsed)) #feed timestamp
if 'summary' in e:
entry.summary = e.summary
entry.save()
else:
print 'Entry with no Publication date: %s' % e
return HttpResponseRedirect( reverse('entries') )
示例11: newentry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def newentry():
"""Create a new entry"""
user = session["user"]
assert user
new_entry = Entry(None, user.username)
new_entry.save()
logging.info("Creating a new entry with id {} for user {}".format(new_entry.id, user.username))
if request.method == "GET":
return redirect(url_for("page"))
else:
return new_entry
示例12: add_entry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def add_entry():
if not session.get('logged_in'):
abort(401)
entry = Entry(
title = request.form['title'],
text = request.form['text']
)
entry.save()
flash('New entry was successfully posted')
return redirect(url_for('show_entries'))
示例13: init
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def init(post=None):
"""Initialises a data entry from a blog post."""
user = User.objects.get(username="Hevok")
posts = Post.objects.all()
if post:
posts = [posts[post]]
for index, post in enumerate(posts):
try:
#entry = Entry(**{'post':post, 'user':user})
entry = Entry(post, user)
entry.save()
except Exception as e:
print("data.models.init: %s (%s %s)" % (e, index, post.title))
示例14: fetch_old_entries
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def fetch_old_entries(feed):
# example url: http://www.google.com/reader/public/atom/feed/http://feeds.feedburner.com/thesimpledollar?n=1000
feed_url = 'http://feeds.feedburner.com/thesimpledollar'
google_url = 'http://www.google.com/reader/public/atom/feed/' + sanitize_url(feed_url) + '?n=' + str(max_entries)
# print "Fetching feed from", feed_url, "..."
f = feedparser.parse(google_url)
# print "Fetched", len(f.entries), "entries of", f.feed.title
# print "Creating new feed..."
for i in f.entries:
e = Entry(title=i.title, link=i.link, description=i.description, date=i.updated_parsed)
e.feed = feed
e.save()
示例15: check_for_updates
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import save [as 别名]
def check_for_updates(records):
for r in records:
name = r['vocab']
for e in r['entries'] :
timestamp = datetime.strptime(e['timestamp'],'%m/%d/%Y %H:%M:%S')
m = Entry.objects.filter(name=name,timestamp=timestamp)
if len(m) == 0 :
entry = Entry(name=name,timestamp=timestamp)
entry.save()
print '{} ({}) is new!'.format(name,str(timestamp))
tweet_about_it(name, e)
else :
print '{} ({}) already exists!'.format(name,str(timestamp))