示例#1
0
文件: ticket.py 项目: leeccong/code
 def add(cls, ticket_id, content, path, position,
         old, new, from_ref, author, new_path=None):
     # FIXME: mysql里的content是废的啊,是历史原因么?
     line_mark = str(old) + '|' + str(new)
     id = store.execute("insert into codedouban_ticket_codereview "
                        "(ticket_id, content, path, position, line_mark, "
                        "from_ref, author, new_path) "
                        "values (%s, %s, %s, %s, %s, %s, %s, %s)",
                        (ticket_id, content, path, position, line_mark,
                         from_ref, author, new_path))
     if not id:
         store.rollback()
         raise Exception("Unable to add")
     store.commit()
     bdb.set(BDB_TICKET_LINECOMMENT_CONTENT_KEY % id, content)
     comment = cls.get(id)
     ticket = Ticket.get(ticket_id)
     # TODO: 重构feed之后取消signal发送
     codereview_signal.send(comment, content=content,
                            ticket=Ticket.get(ticket_id),
                            author=author, comment=comment)
     dispatch('codereview', data={
              'comment': comment,
              'ticket': ticket,
              'sender': author,
              })
     return comment
示例#2
0
文件: room.py 项目: jackfrued/code-1
def _add(name, owner):
    room_id = store.execute(
        "insert into chat_rooms"
        "(name, author) values(%s, %s)", (name, owner))
    if not room_id:
        store.rollback()
        raise Exception("Unable to insert new room")
    store.commit()
    return room_id
示例#3
0
文件: room.py 项目: 000fan000/code
def _add(name, owner):
    room_id = store.execute("insert into chat_rooms"
                            "(name, author) values(%s, %s)",
                            (name, owner))
    if not room_id:
        store.rollback()
        raise Exception("Unable to insert new room")
    store.commit()
    return room_id
示例#4
0
文件: comment.py 项目: 000fan000/code
def add(proj_id, ref, author, content):
    comment_id = store.execute("insert into codedouban_comments "
                               "(project_id, ref, author, content) "
                               "values (%s, %s, %s, %s)",
                               (proj_id, ref, author, content))
    if not comment_id:
        store.rollback()
        raise Exception("Unable to insert new comment")
    store.commit()
    return comment_id
示例#5
0
 def add(cls, **kw):
     now = datetime.now()
     kw['created_at'] = now
     kw['updated_at'] = now
     p = None
     try:
         p = cls.create(**kw)
     except IntegrityError:
         store.rollback()
     return p
示例#6
0
def add(proj_id, ref, author, content):
    comment_id = store.execute(
        "insert into codedouban_comments "
        "(project_id, ref, author, content) "
        "values (%s, %s, %s, %s)", (proj_id, ref, author, content))
    if not comment_id:
        store.rollback()
        raise Exception("Unable to insert new comment")
    store.commit()
    return comment_id
示例#7
0
 def add(cls, **kw):
     now = datetime.now()
     kw['created_at'] = now
     kw['updated_at'] = now
     kw['password'] = cls.hash_password(kw['password'])
     u = None
     try:
         u = cls.create(**kw)
     except IntegrityError:
         store.rollback()
     return u
示例#8
0
文件: user.py 项目: jhonHouse-L/code
 def add(cls, **kw):
     now = datetime.now()
     kw["created_at"] = now
     kw["updated_at"] = now
     kw["password"] = cls.hash_password(kw["password"])
     u = None
     try:
         u = cls.create(**kw)
     except IntegrityError:
         store.rollback()
     return u
示例#9
0
 def add(cls, project_id, ref, path, position, author, content):
     comment_id = store.execute(
         "insert into codedouban_linecomments "
         "(project_id, ref, path, position, author, content) "
         "values (%s, %s, %s, %s, %s, %s)",
         (project_id, ref, path, position, author, content))
     if not comment_id:
         store.rollback()
         raise Exception("Unable to insert new comment")
     store.commit()
     bdb.set(BDB_COMMIT_LINECOMMENT_CONTENT_KEY % comment_id, content)
     return cls.get(comment_id)
示例#10
0
 def add(cls, project_id, ref, path, position, author, content):
     comment_id = store.execute(
         "insert into codedouban_linecomments "
         "(project_id, ref, path, position, author, content) "
         "values (%s, %s, %s, %s, %s, %s)",
         (project_id, ref, path, position, author, content))
     if not comment_id:
         store.rollback()
         raise Exception("Unable to insert new comment")
     store.commit()
     bdb.set(BDB_COMMIT_LINECOMMENT_CONTENT_KEY % comment_id, content)
     return cls.get(comment_id)
示例#11
0
 def add(cls, from_user, to_user, content):
     if from_user == to_user:
         return
     recommendation_id = store.execute(
         "insert into codedouban_recommendations "
         "(from_user, to_user, content) "
         "values (%s, %s, %s)", (from_user, to_user, content))
     if not recommendation_id:
         store.rollback()
         raise Exception("Unable to insert new recommendation")
     store.commit()
     rec = cls.get(recommendation_id)
     dispatch('recommend', data={'recommend': rec})
     return rec
示例#12
0
 def add(cls, from_user, to_user, content):
     if from_user == to_user:
         return
     recommendation_id = store.execute(
         "insert into codedouban_recommendations "
         "(from_user, to_user, content) "
         "values (%s, %s, %s)",
         (from_user, to_user, content))
     if not recommendation_id:
         store.rollback()
         raise Exception("Unable to insert new recommendation")
     store.commit()
     rec = cls.get(recommendation_id)
     dispatch('recommend', data={'recommend': rec})
     return rec
示例#13
0
 def add(cls, target_id, from_sha, to_sha, old_path, new_path, from_oid,
         to_oid, old_linenum, new_linenum, author, content):
     id = store.execute(
         "insert into codedouban_linecomments_v2 "
         "(target_type, target_id, from_sha, to_sha, "
         "old_path, new_path, from_oid, to_oid, old_linenum, new_linenum, "
         "author, content, created_at, updated_at) "
         "values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL, NULL)",  # noqa
         (cls._target_type, target_id, from_sha, to_sha, old_path, new_path,
          from_oid, to_oid, old_linenum, new_linenum, author, content))
     if not id:
         store.rollback()
         raise Exception("Unable to add new linecomment")
     store.commit()
     bdb.set(BDB_LINECOMMENT_CONTENT_KEY % id, content)
     return cls.get(id)
示例#14
0
 def add(cls, project_id, title, description, author, ticket_number=None):
     ticket_number = PRCounter.incr(project_id, ticket_number)
     id = store.execute(
         "insert into codedouban_ticket "
         "(ticket_number, project_id, title, description, author) "
         "values (%s, %s, %s, %s, %s)",
         (ticket_number, project_id, title, description, author))
     if not id:
         store.rollback()
         raise Exception("Unable to add")
     store.commit()
     mc.delete(MCKEY_TICKET % id)
     bdb.set(BDB_TICKET_DESCRIPTION_KEY % id, description)
     ticket = cls.get(id)
     ticket.add_participant(author)
     return ticket
示例#15
0
文件: ticket.py 项目: leeccong/code
 def add(cls, project_id, title, description, author, ticket_number=None):
     ticket_number = PRCounter.incr(project_id, ticket_number)
     id = store.execute(
         "insert into codedouban_ticket "
         "(ticket_number, project_id, title, description, author) "
         "values (%s, %s, %s, %s, %s)",
         (ticket_number, project_id, title, description, author))
     if not id:
         store.rollback()
         raise Exception("Unable to add")
     store.commit()
     mc.delete(MCKEY_TICKET % id)
     bdb.set(BDB_TICKET_DESCRIPTION_KEY % id, description)
     ticket = cls.get(id)
     ticket.add_participant(author)
     return ticket
示例#16
0
def update(comment_id, changes):
    assert changes, "Must have some changes to propose"
    assert all(k in ('content', )
               for k in changes.keys()), "Can only update some fields"
    setters, values = _make_update_setters(changes)
    n = store.execute(
        "update codedouban_comments set %s "
        "where comment_id = %%s" % setters, values + [comment_id])
    if n == 0:
        store.rollback()
        raise Exception("Comment %s not found, not updated" % comment_id)
    if n > 1:
        store.rollback()
        raise Exception(
            "Weird: more than one comment found for id %s, not updated".format(
                comment_id))
    store.commit()
示例#17
0
文件: comment.py 项目: 000fan000/code
def update(comment_id, changes):
    assert changes, "Must have some changes to propose"
    assert all(k in (
        'content', ) for k in changes.keys()), "Can only update some fields"
    setters, values = _make_update_setters(changes)
    n = store.execute(
        "update codedouban_comments set %s "
        "where comment_id = %%s" % setters, values + [comment_id])
    if n == 0:
        store.rollback()
        raise Exception("Comment %s not found, not updated" % comment_id)
    if n > 1:
        store.rollback()
        raise Exception(
            "Weird: more than one comment found for id %s, not updated".format(
                comment_id))
    store.commit()
示例#18
0
 def add_raw(cls, target_id, from_sha, to_sha,
             old_path, new_path, from_oid, to_oid, old_linenum, new_linenum,
             author, content, position, created_at, updated_at):
     id = store.execute(
         "insert into codedouban_linecomments_v2 "
         "(target_type, target_id, from_sha, to_sha, "
         "old_path, new_path, from_oid, to_oid, old_linenum, new_linenum, "
         "author, content, position, created_at, updated_at) "
         "values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",  # noqa
         (cls._target_type, target_id, from_sha, to_sha,
          old_path, new_path, from_oid, to_oid, old_linenum, new_linenum,
          author, content, position, created_at, updated_at))
     if not id:
         store.rollback()
         raise Exception("Unable to add new linecomment")
     store.commit()
     bdb.set(BDB_LINECOMMENT_CONTENT_KEY % id, content)
     return cls.get(id)
示例#19
0
 def create_by_project(cls, project, name, user):
     target_number = MTCounter.incr(project.id, PROJECT_MILESTONE_TYPE)
     try:
         ms = cls.create(
             name=name,
             target_id=project.id,
             target_type=PROJECT_MILESTONE_TYPE,
             target_number=target_number,
             creator_id=user.name,
             created_at=datetime.now(),
         )
     except IntegrityError:
         store.rollback()
         rs = cls.gets_by(target_id=project.id, target_type=PROJECT_MILESTONE_TYPE, target_number=target_number)
         ms = rs[0]
         ms.name = name
         ms.save()
     return ms
示例#20
0
 def create_by_project(cls, project, name, user):
     target_number = MTCounter.incr(project.id, PROJECT_MILESTONE_TYPE)
     try:
         ms = cls.create(name=name,
                         target_id=project.id,
                         target_type=PROJECT_MILESTONE_TYPE,
                         target_number=target_number,
                         creator_id=user.name,
                         created_at=datetime.now())
     except IntegrityError:
         store.rollback()
         rs = cls.gets_by(target_id=project.id,
                          target_type=PROJECT_MILESTONE_TYPE,
                          target_number=target_number)
         ms = rs[0]
         ms.name = name
         ms.save()
     return ms
示例#21
0
    def add_vote(self, user):
        rs = store.execute(
            "select id from codedouban_recommendation_votes"
            " where recommendation_id=%s and user=%s", (self.id, user))
        r = rs and rs[0]
        if r:
            return
        vote_id = store.execute(
            "insert into codedouban_recommendation_votes "
            "(recommendation_id, user) "
            "values (%s, %s)", (self.id, user))
        if not vote_id:
            store.rollback()
            raise Exception("Unable to insert new vote")

        store.execute(
            "update codedouban_recommendations "
            "set n_vote=n_vote+1 "
            "where id=%s", (self.id, ))
        store.commit()
        return True
示例#22
0
    def add_vote(self, user):
        rs = store.execute(
            "select id from codedouban_recommendation_votes"
            " where recommendation_id=%s and user=%s", (self.id, user))
        r = rs and rs[0]
        if r:
            return
        vote_id = store.execute(
            "insert into codedouban_recommendation_votes "
            "(recommendation_id, user) "
            "values (%s, %s)",
            (self.id, user))
        if not vote_id:
            store.rollback()
            raise Exception("Unable to insert new vote")

        store.execute("update codedouban_recommendations "
                      "set n_vote=n_vote+1 "
                      "where id=%s", (self.id,))
        store.commit()
        return True
示例#23
0
 def add(cls,
         ticket_id,
         content,
         path,
         position,
         old,
         new,
         from_ref,
         author,
         new_path=None):
     # FIXME: mysql里的content是废的啊,是历史原因么?
     line_mark = str(old) + '|' + str(new)
     id = store.execute(
         "insert into codedouban_ticket_codereview "
         "(ticket_id, content, path, position, line_mark, "
         "from_ref, author, new_path) "
         "values (%s, %s, %s, %s, %s, %s, %s, %s)",
         (ticket_id, content, path, position, line_mark, from_ref, author,
          new_path))
     if not id:
         store.rollback()
         raise Exception("Unable to add")
     store.commit()
     bdb.set(BDB_TICKET_LINECOMMENT_CONTENT_KEY % id, content)
     comment = cls.get(id)
     ticket = Ticket.get(ticket_id)
     # TODO: 重构feed之后取消signal发送
     codereview_signal.send(comment,
                            content=content,
                            ticket=Ticket.get(ticket_id),
                            author=author,
                            comment=comment)
     dispatch('codereview',
              data={
                  'comment': comment,
                  'ticket': ticket,
                  'sender': author,
              })
     return comment