Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
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")
Ejemplo n.º 3
0
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')
Ejemplo n.º 4
0
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")
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
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.gencache.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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
    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")
Ejemplo n.º 10
0
    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")
Ejemplo n.º 11
0
    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")
Ejemplo n.º 12
0
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")
Ejemplo n.º 13
0
    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()
Ejemplo n.º 14
0
    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()
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
0
    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
Ejemplo n.º 17
0
def change_password(user, newpassword):
    user.password = bcrypt_password(newpassword)
    user._commit()
    LastModified.touch(user._fullname, 'Password')
    return True
Ejemplo n.º 18
0
 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')
Ejemplo n.º 19
0
 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')
Ejemplo n.º 20
0
def change_password(user, newpassword):
    user.password = bcrypt_password(newpassword)
    user._commit()
    LastModified.touch(user._fullname, 'Password')
    return True