本文整理汇总了Python中r2.models.last_modified.LastModified.touch方法的典型用法代码示例。如果您正苦于以下问题:Python LastModified.touch方法的具体用法?Python LastModified.touch怎么用?Python LastModified.touch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类r2.models.last_modified.LastModified
的用法示例。
在下文中一共展示了LastModified.touch方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: revise
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import touch [as 别名]
def revise(self, content, previous = None, author=None, force=False, reason=None):
if content is None:
content = ""
if self.content == content:
return
force = True if previous is None else force
max_length = special_length_restrictions_bytes.get(self.name, MAX_PAGE_LENGTH_BYTES)
if len(content) > max_length:
raise ContentLengthError(max_length)
revision = getattr(self, 'revision', None)
if not force and (revision and previous != revision):
if previous:
origcontent = WikiRevision.get(previous, pageid=self._id).content
else:
origcontent = ''
try:
content = threewaymerge(origcontent, content, self.content)
except ConflictException as e:
e.new_id = revision
raise e
wr = WikiRevision.create(self._id, content, author, reason)
self.content = content
self.last_edit_by = author
self.last_edit_date = wr.date
self.revision = str(wr._id)
self._commit()
LastModified.touch(self._fullname, "Edit")
return wr
示例2: add_comment_tree
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import touch [as 别名]
def add_comment_tree(comments):
# update the comment cache
add_comments(comments)
# update last modified
links = Link._byID(list(set(com.link_id for com in tup(comments))), data=True, return_dict=False)
for link in links:
set_last_modified(link, "comments")
LastModified.touch(link._fullname, "Comments")
示例3: _commit
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import touch [as 别名]
def _commit(self, *a, **kw):
assert self._id == self._rowkey(self.thing1_id, self.thing2_id)
retval = ThingBase._commit(self, *a, **kw)
from r2.models.last_modified import LastModified
fullname = self._thing1_cls._fullname_from_id36(self.thing1_id)
LastModified.touch(fullname, self._cf.column_family)
return retval
示例4: update_vote_lookups
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import touch [as 别名]
def update_vote_lookups(user, thing, direction):
"""Store info about the existence of this vote (before processing)."""
# set the vote in memcached so the UI gets updated immediately
key = prequeued_vote_key(user, thing)
grace_period = int(g.vote_queue_grace_period.total_seconds())
direction = Vote.serialize_direction(direction)
g.cache.set(key, direction, time=grace_period+1)
# update LastModified immediately to help us cull prequeued_vote lookups
rel_cls = VotesByAccount.rel(thing.__class__)
LastModified.touch(user._fullname, rel_cls._last_modified_name)
示例5: update_last_visit
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import touch [as 别名]
def update_last_visit(self, current_time):
from admintools import apply_updates
apply_updates(self)
prev_visit = LastModified.get(self._fullname, "Visit")
if prev_visit and current_time - prev_visit < timedelta(days=1):
return
g.log.debug("Updating last visit for %s from %s to %s" % (self.name, prev_visit, current_time))
LastModified.touch(self._fullname, "Visit")
示例6: update_last_visit
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import touch [as 别名]
def update_last_visit(self, current_time):
from admintools import apply_updates
apply_updates(self)
#prev_visit = getattr(self, 'last_visit', None)
prev_visit = last_visit(self)
if prev_visit and current_time - prev_visit < timedelta(1):
return
g.log.debug ("Updating last visit for %s from %s to %s" %
(self.name, prev_visit, current_time))
set_last_visit(self)
LastModified.touch(self._fullname, "Visit")
示例7: handle_vote
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import touch [as 别名]
def handle_vote(user, thing, dir, ip, organic,
cheater=False, foreground=False, timer=None):
if timer is None:
timer = SimpleSillyStub()
from r2.lib.db import tdb_sql
from sqlalchemy.exc import IntegrityError
try:
v = Vote.vote(user, thing, dir, ip, organic, cheater = cheater,
timer=timer)
except (tdb_sql.CreationError, IntegrityError):
g.log.error("duplicate vote for: %s" % str((user, thing, dir)))
return
timestamps = []
if isinstance(thing, Link):
new_vote(v, foreground=foreground, timer=timer)
#update the modified flags
if user._id == thing.author_id:
timestamps.append('Overview')
timestamps.append('Submitted')
#update sup listings
sup.add_update(user, 'submitted')
#update sup listings
if dir:
sup.add_update(user, 'liked')
elif dir is False:
sup.add_update(user, 'disliked')
elif isinstance(thing, Comment):
#update last modified
if user._id == thing.author_id:
timestamps.append('Overview')
timestamps.append('Commented')
#update sup listings
sup.add_update(user, 'commented')
timer.intermediate("sup")
for timestamp in timestamps:
set_last_modified(user, timestamp.lower())
LastModified.touch(user._fullname, timestamps)
timer.intermediate("last_modified")
示例8: update_last_visit
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import touch [as 别名]
def update_last_visit(self, current_time):
from admintools import apply_updates
timer = g.stats.get_timer("account.update_last_visit")
timer.start()
apply_updates(self, timer)
prev_visit = LastModified.get(self._fullname, "Visit")
timer.intermediate("get_last_modified")
if prev_visit and current_time - prev_visit < timedelta(days=1):
timer.intermediate("set_last_modified.noop")
timer.stop()
return
LastModified.touch(self._fullname, "Visit")
timer.intermediate("set_last_modified.done")
timer.stop()
示例9: create
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import touch [as 别名]
def create(cls, thing1, thing2s, **kw):
"""Create a relationship between thing1 and thing2s.
If there are any other views of this data, they will be updated as
well.
Takes kwargs which can be used by views
or value_for to get additional information.
"""
thing2s = tup(thing2s)
values = {thing2._id36 : cls.value_for(thing1, thing2, **kw)
for thing2 in thing2s}
cls._cf.insert(thing1._id36, values, ttl=cls._ttl)
for view in cls._views:
view.create(thing1, thing2s, **kw)
if cls._write_last_modified:
from r2.models.last_modified import LastModified
LastModified.touch(thing1._fullname, cls._last_modified_name)
示例10: change_password
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import touch [as 别名]
def change_password(user, newpassword):
user.password = bcrypt_password(newpassword)
user._commit()
LastModified.touch(user._fullname, 'Password')
return True
示例11: add_comments
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import touch [as 别名]
def add_comments(self, comments):
impl = self.IMPLEMENTATIONS[self.link.comment_tree_version]
impl.add_comments(self, comments)
utils.set_last_modified(self.link, 'comments')
LastModified.touch(self.link._fullname, 'Comments')