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
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
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
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
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
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
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
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
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)
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
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)
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
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()
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()
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)
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
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
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
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
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