Example #1
0
 def assign(self, user_id):
     Issue.assign(self, user_id)
     self.clear_cache()
     mc.delete(MC_KEY_PROJECT_ISSUE_ASSIGNEE_N %
               (self.project_id, user_id, 'open'))
     mc.delete(MC_KEY_PROJECT_ISSUE_ASSIGNEE_N %
               (self.project_id, user_id, 'closed'))
Example #2
0
 def add(cls,
         title,
         description,
         creator,
         number=None,
         team=None,
         project=None,
         assignee=None,
         closer=None,
         created_at=None,
         updated_at=None,
         closed_at=None):
     issue = Issue.add(title,
                       description,
                       creator,
                       assignee=assignee,
                       closer=closer,
                       type=cls.target_type,
                       target_id=project)
     if issue and project:
         number = PICounter.incr(project, number)
         store.execute(
             'insert into project_issues (project_id, issue_id, number) '
             'values (%s, %s, %s) ', (project, issue.id, number))
         store.commit()
         mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N %
                   (project, creator, 'open'))
         mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N %
                   (project, creator, 'closed'))
         cls._clean_cache(project)
         return Issue.get_cached_issue(issue.id)
Example #3
0
 def update(self, title='', description=''):
     store.execute(
         "update codedouban_ticket set title=%s, description=%s "
         "where id=%s", (title, description, self.id))
     store.commit()
     mc.delete(MCKEY_TICKET % self.id)
     bdb.set(BDB_TICKET_DESCRIPTION_KEY % self.id, description)
Example #4
0
 def assign(self, user_id):
     Issue.assign(self, user_id)
     self.clear_cache()
     mc.delete(MC_KEY_PROJECT_ISSUE_ASSIGNEE_N % (
         self.project_id, user_id, 'open'))
     mc.delete(MC_KEY_PROJECT_ISSUE_ASSIGNEE_N % (
         self.project_id, user_id, 'closed'))
Example #5
0
 def add(
     cls,
     title,
     description,
     creator,
     number=None,
     team=None,
     project=None,
     assignee=None,
     closer=None,
     created_at=None,
     updated_at=None,
     closed_at=None,
 ):
     issue = Issue.add(
         title, description, creator, assignee=assignee, closer=closer, type=cls.target_type, target_id=project
     )
     if issue and project:
         number = PICounter.incr(project, number)
         store.execute(
             "insert into project_issues (project_id, issue_id, number) " "values (%s, %s, %s) ",
             (project, issue.id, number),
         )
         store.commit()
         mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N % (project, creator, "open"))
         mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N % (project, creator, "closed"))
         cls._clean_cache(project)
         return Issue.get_cached_issue(issue.id)
Example #6
0
 def delete(cls, issue_id, user_id):
     n = store.execute(
         "delete from issue_upvotes "
         "where issue_id = %s and user_id = %s ", (issue_id, user_id))
     if n:
         store.commit()
         mc.delete(MC_KEY_ISSUE_VOTES_COUNT % issue_id)
         return True
Example #7
0
 def delete(self):
     bdb.delete(BDB_ISSUE_COMMENT_CONTENT_KEY % self.id)
     n = store.execute("delete from issue_comments "
                       "where id=%s", (self.id,))
     if n:
         store.commit()
         mc.delete(MC_KEY_ISSUE_COMMENTS_COUNT % self.issue_id)
         return True
Example #8
0
 def update(self, title, description):
     store.execute("update issues "
                   "set title=%s, updated_at=null "
                   "where id=%s", (title, self.issue_id))
     store.commit()
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % self.issue_id, description)
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
Example #9
0
 def delete(self):
     bdb.delete(BDB_ISSUE_COMMENT_CONTENT_KEY % self.id)
     n = store.execute("delete from issue_comments "
                       "where id=%s", (self.id,))
     if n:
         store.commit()
         mc.delete(MC_KEY_ISSUE_COMMENTS_COUNT % self.issue_id)
         return True
Example #10
0
 def delete(cls, issue_id, user_id):
     n = store.execute(
         "delete from issue_upvotes "
         "where issue_id = %s and user_id = %s ",
         (issue_id, user_id))
     if n:
         store.commit()
         mc.delete(MC_KEY_ISSUE_VOTES_COUNT % issue_id)
         return True
Example #11
0
 def open(self, operator):
     opened_time = datetime.now()
     store.execute("update codedouban_ticket set closed=null where id=%s",
                   (self.id,))
     store.commit()
     mc.delete(MCKEY_TICKET % self.id)
     self.close_by = None
     self.add_participant(operator)
     TicketNode.add_open(self.id, operator, opened_time)
Example #12
0
 def assign(self, user_id):
     old_id = self.assignee_id
     store.execute("update issues "
                   "set assignee_id=%s "
                   "where id=%s", (user_id, self.issue_id))
     store.commit()
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % old_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % user_id)
Example #13
0
 def assign(self, user_id):
     old_id = self.assignee_id
     store.execute("update issues "
                   "set assignee_id=%s "
                   "where id=%s", (user_id, self.issue_id))
     store.commit()
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % old_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % user_id)
Example #14
0
 def open(self, operator):
     opened_time = datetime.now()
     store.execute("update codedouban_ticket set closed=null where id=%s",
                   (self.id, ))
     store.commit()
     mc.delete(MCKEY_TICKET % self.id)
     self.close_by = None
     self.add_participant(operator)
     TicketNode.add_open(self.id, operator, opened_time)
Example #15
0
 def update(self, title, description):
     store.execute(
         "update issues "
         "set title=%s, updated_at=null "
         "where id=%s", (title, self.issue_id))
     store.commit()
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % self.issue_id, description)
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
Example #16
0
 def open(self):
     store.execute("update issues "
                   "set closer_id=null, closed_at=null "
                   "where id=%s", (self.issue_id,))
     store.commit()
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % self.creator_id)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
     self.closer_id = None
Example #17
0
 def open(self):
     store.execute(
         "update issues "
         "set closer_id=null, closed_at=null "
         "where id=%s", (self.issue_id, ))
     store.commit()
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % self.creator_id)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
     self.closer_id = None
Example #18
0
 def add(cls, issue_id, content, author_id, number=None):
     number = ICCounter.incr(issue_id, number)
     time = datetime.now()
     comment_id = store.execute(
         'insert into issue_comments (issue_id, author_id, number, '
         'created_at, updated_at) values (%s, %s, %s, NULL, NULL)',
         (issue_id, author_id, number))
     store.commit()
     bdb.set(BDB_ISSUE_COMMENT_CONTENT_KEY % comment_id, content)
     mc.delete(MC_KEY_ISSUE_COMMENTS_COUNT % issue_id)
     return cls(comment_id, issue_id, author_id, number, time, time)
Example #19
0
 def add(cls, issue_id, content, author_id, number=None):
     number = ICCounter.incr(issue_id, number)
     time = datetime.now()
     comment_id = store.execute(
         'insert into issue_comments (issue_id, author_id, number, '
         'created_at, updated_at) values (%s, %s, %s, NULL, NULL)',
         (issue_id, author_id, number))
     store.commit()
     bdb.set(BDB_ISSUE_COMMENT_CONTENT_KEY % comment_id, content)
     mc.delete(MC_KEY_ISSUE_COMMENTS_COUNT % issue_id)
     return cls(comment_id, issue_id, author_id, number, time, time)
Example #20
0
 def add(cls, issue_id, user_id):
     upvote = cls.get_by_issue_id_and_user_id(issue_id, user_id)
     if upvote:
         return upvote
     else:
         id = store.execute(
             "insert into issue_upvotes "
             "(issue_id, user_id) "
             "values(%s, %s)", (issue_id, user_id))
         store.commit()
         mc.delete(MC_KEY_ISSUE_VOTES_COUNT % issue_id)
         return cls(id=id, issue_id=issue_id, user_id=user_id)
Example #21
0
 def update_pledge(self, user, amount):
     try:
         store.execute('insert into issue_pledge '
                       '(issue_id, user_id, amount) '
                       'values (%s, %s, %s)',
                       (self.issue_id, user.name, amount))
     except IntegrityError:
         store.execute('update issue_pledge '
                       'set amount=%s '
                       'where issue_id=%s and user_id=%s',
                       (amount, self.issue_id, user.name))
     store.commit()
     mc.delete(MC_KEY_ISSUE_PLEDGED % self.issue_id)
Example #22
0
 def update_pledge(self, user, amount):
     try:
         store.execute(
             'insert into issue_pledge '
             '(issue_id, user_id, amount) '
             'values (%s, %s, %s)', (self.issue_id, user.name, amount))
     except IntegrityError:
         store.execute(
             'update issue_pledge '
             'set amount=%s '
             'where issue_id=%s and user_id=%s',
             (amount, self.issue_id, user.name))
     store.commit()
     mc.delete(MC_KEY_ISSUE_PLEDGED % self.issue_id)
Example #23
0
 def add(cls, issue_id, user_id):
     upvote = cls.get_by_issue_id_and_user_id(
         issue_id, user_id)
     if upvote:
         return upvote
     else:
         id = store.execute(
             "insert into issue_upvotes "
             "(issue_id, user_id) "
             "values(%s, %s)",
             (issue_id, user_id))
         store.commit()
         mc.delete(MC_KEY_ISSUE_VOTES_COUNT % issue_id)
         return cls(id=id, issue_id=issue_id, user_id=user_id)
Example #24
0
 def add(cls,
         title,
         description,
         creator,
         assignee=None,
         closer=None,
         created_at=None,
         updated_at=None,
         closed_at=None,
         type='default',
         target_id=0):
     time = datetime.now()
     issue_id = store.execute(
         'insert into issues (title, creator_id, '
         'assignee_id, closer_id, created_at, updated_at, type, target_id) '
         'values (%s, %s, %s, %s, NULL, NULL, %s, %s)',
         (title, creator, assignee, closer, type, target_id))
     store.commit()
     mc.delete(MC_KEY_ISSUE % issue_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % creator)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % assignee)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (type, target_id))
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % issue_id, description)
     issue = cls(issue_id, title, creator, assignee, closer, time, time)
     issue.add_participant(creator)
     return issue
Example #25
0
 def update_rank_score(self):
     vote_count = self.vote_count
     comment_count = self.comment_count
     time_delta = (datetime.now() - datetime(2011, 1, 1)).total_seconds()
     divider = (datetime(2013, 7, 8) - datetime(2011, 1, 1)).total_seconds()
     time_factor = time_delta / divider * 5
     score = (vote_count * 0.5 + comment_count) * time_factor
     store.execute(
         "update issues "
         "set rank_score=%s , updated_at=updated_at "  # 防止字段更新
         "where id=%s ",
         (score, self.issue_id))
     store.commit()
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
     return score
Example #26
0
 def update_rank_score(self):
     vote_count = self.vote_count
     comment_count = self.comment_count
     time_delta = (datetime.now() - datetime(2011, 1, 1)).total_seconds()
     divider = (datetime(2013, 7, 8) - datetime(2011, 1, 1)).total_seconds()
     time_factor = time_delta / divider * 5
     score = (vote_count * 0.5 + comment_count) * time_factor
     store.execute(
         "update issues "
         "set rank_score=%s , updated_at=updated_at "  # 防止字段更新
         "where id=%s ",
         (score, self.issue_id))
     store.commit()
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
     return score
Example #27
0
 def delete(self):
     store.execute('delete from issues where id=%s', (self.id,))
     store.commit()
     mc.delete(MC_KEY_ISSUE % self.id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % self.creator_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % self.assignee_id)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (type, self.target_id))
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % self.id, '')
Example #28
0
 def delete(self):
     store.execute('delete from issues where id=%s', (self.id, ))
     store.commit()
     mc.delete(MC_KEY_ISSUE % self.id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % self.creator_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % self.assignee_id)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (type, self.target_id))
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % self.id, '')
Example #29
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
Example #30
0
    def close(self, operator):
        closed_time = datetime.now()
        store.execute("update codedouban_ticket set closed=%s where id=%s",
                      (closed_time, self.id))
        store.commit()
        mc.delete(MCKEY_TICKET % self.id)
        self.close_by = operator

        for paticipant in self.participants:
            # FIXME better interface
            from models.user import UserPullRequests
            UserPullRequests(paticipant).remove_participated(self.id)
            UserPullRequests(paticipant).remove_invited(self.id)

        self.add_participant(operator)
        TicketNode.add_close(self.id, operator, closed_time)
Example #31
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
Example #32
0
    def close(self, operator):
        closed_time = datetime.now()
        store.execute("update codedouban_ticket set closed=%s where id=%s",
                      (closed_time, self.id))
        store.commit()
        mc.delete(MCKEY_TICKET % self.id)
        self.close_by = operator

        for paticipant in self.participants:
            # FIXME better interface
            from vilya.models.user import UserPullRequests
            UserPullRequests(paticipant).remove_participated(self.id)
            UserPullRequests(paticipant).remove_invited(self.id)

        self.add_participant(operator)
        TicketNode.add_close(self.id, operator, closed_time)
Example #33
0
 def delete(self):
     issue = self.get_by_issue_id(self.issue_id)
     user_id = issue.assignee_id
     creator = issue.creator_id
     store.execute("delete from project_issues where id=%s", (self.id,))
     store.commit()
     mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N % (
         self.project_id, creator, 'open'))
     mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N % (
         self.project_id, creator, 'closed'))
     mc.delete(MC_KEY_PROJECT_ISSUE_ASSIGNEE_N % (
         self.project_id, user_id, 'open'))
     mc.delete(MC_KEY_PROJECT_ISSUE_ASSIGNEE_N % (
         self.project_id, user_id, 'closed'))
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (
         self.target_type, self.project_id))
     self.delete_issue()
     self._clean_cache(id)
Example #34
0
 def delete(self):
     issue = self.get_by_issue_id(self.issue_id)
     user_id = issue.assignee_id
     creator = issue.creator_id
     store.execute("delete from project_issues where id=%s", (self.id, ))
     store.commit()
     mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N %
               (self.project_id, creator, 'open'))
     mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N %
               (self.project_id, creator, 'closed'))
     mc.delete(MC_KEY_PROJECT_ISSUE_ASSIGNEE_N %
               (self.project_id, user_id, 'open'))
     mc.delete(MC_KEY_PROJECT_ISSUE_ASSIGNEE_N %
               (self.project_id, user_id, 'closed'))
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET %
               (self.target_type, self.project_id))
     self.delete_issue()
     self._clean_cache(id)
Example #35
0
 def add(cls, title, description, creator, assignee=None, closer=None,
         created_at=None, updated_at=None, closed_at=None,
         type='default', target_id=0):
     time = datetime.now()
     issue_id = store.execute(
         'insert into issues (title, creator_id, '
         'assignee_id, closer_id, created_at, updated_at, type, target_id) '
         'values (%s, %s, %s, %s, NULL, NULL, %s, %s)',
         (title, creator, assignee, closer, type, target_id))
     store.commit()
     mc.delete(MC_KEY_ISSUE % issue_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % creator)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % assignee)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (type, target_id))
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % issue_id, description)
     issue = cls(issue_id, title, creator, assignee, closer, time, time)
     issue.add_participant(creator)
     return issue
Example #36
0
 def _clean_cache(cls, id):
     # FIXME: update cache
     mc.delete(MC_KEY_PROJECT_ISSUE_N % (id, 'closed'))
     mc.delete(MC_KEY_PROJECT_ISSUE_N % (id, 'open'))
Example #37
0
 def _flush(self):
     mc.delete('email:%s:user' % self.email)
Example #38
0
 def invalidate(self, key, **kw):
     mc.delete(key)
Example #39
0
 def check(cls, apikey, code):
     key = cls.__mc_key(apikey, code)
     user_id = mc.get(key)
     if user_id:
         mc.delete(key)
     return user_id
Example #40
0
 def invalidate(self, key, **kw):
     mc.delete(key)
Example #41
0
 def clear_mc(cls, id_):
     project = cls.get(id_)
     if project:
         mc.delete(MCKEY_PROJECT_ID_BY_NAME % project.name)
     mc.delete(MCKEY_PROJECT % id_)
Example #42
0
 def _flush_project_ids_by_owner(cls, owner=None):
     mc.delete(MCKEY_PROJECT_IDS_BY_OWNER_SORTBY_SUMUP % owner)
Example #43
0
 def _clean_cache(cls, id):
     # FIXME: update cache
     mc.delete(MC_KEY_PROJECT_ISSUE_N % (id, 'closed'))
     mc.delete(MC_KEY_PROJECT_ISSUE_N % (id, 'open'))
Example #44
0
 def release(self):
     mc.delete(self.mc_key)
Example #45
0
 def open(self):
     Issue.open(self)
     self.clear_cache()
     mc.delete(MC_KEY_PROJECT_ISSUE_N % (self.project_id, 'open'))
Example #46
0
 def close(self, user_id):
     Issue.close(self, user_id)
     self.clear_cache()
     mc.delete(MC_KEY_PROJECT_ISSUE_N % (self.project_id, 'closed'))
Example #47
0
 def confirm(cls, user_id, cid):
     key = OAUTH_CONFIRM % (user_id, cid)
     if mc.get(key):
         mc.delete(key)
         return True
Example #48
0
 def _flush(self):
     mc.delete('email:%s:user' % self.email)
Example #49
0
 def release(self):
     mc.delete(self.mc_key)
Example #50
0
 def close(self, user_id):
     Issue.close(self, user_id)
     self.clear_cache()
     mc.delete(MC_KEY_PROJECT_ISSUE_N % (self.project_id, 'closed'))
Example #51
0
 def _flush_project_ids_by_owner(cls, owner=None):
     mc.delete(MCKEY_PROJECT_IDS_BY_OWNER_SORTBY_SUMUP % owner)
Example #52
0
 def check(cls, apikey, code):
     key = cls.__mc_key(apikey, code)
     user_id = mc.get(key)
     if user_id:
         mc.delete(key)
     return user_id
Example #53
0
 def confirm(cls, user_id, cid):
     key = OAUTH_CONFIRM % (user_id, cid)
     if mc.get(key):
         mc.delete(key)
         return True
Example #54
0
 def clear_cache(self):
     mc.delete(MC_KEY_ISSUE % self.issue_id)
Example #55
0
 def clear_cache(self):
     mc.delete(MC_KEY_ISSUE % self.issue_id)
Example #56
0
 def update(self, title='', description=''):
     store.execute("update codedouban_ticket set title=%s, description=%s "
                   "where id=%s", (title, description, self.id))
     store.commit()
     mc.delete(MCKEY_TICKET % self.id)
     bdb.set(BDB_TICKET_DESCRIPTION_KEY % self.id, description)
Example #57
0
 def open(self):
     Issue.open(self)
     self.clear_cache()
     mc.delete(MC_KEY_PROJECT_ISSUE_N % (self.project_id, 'open'))
Example #58
0
 def clear_mc(cls, id_):
     project = cls.get(id_)
     if project:
         mc.delete(MCKEY_PROJECT_ID_BY_NAME % project.name)
     mc.delete(MCKEY_PROJECT % id_)
Example #59
0
 def clear_new_badges(cls, item_id, kind=KIND_USER):
     mc.delete(MC_NEW_BADGE % (item_id, kind))