Konstantine Rybnikov avatar Konstantine Rybnikov committed 6c59791

code cleanup

Comments (0)

Files changed (5)

 =====
 
 #. Implement commands::
-    - read message
-    - NICK
+    - read message (ok)
     - reply to message
     - reply to reply
+    - NICK
 
 #. Write tests.

openju/bl/message.py

 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
-# from datetime import datetime
-# from pymongo import DESCENDING
-# from openju.util import get_mongo_db
-# from openju.validators import PostNotExistError
-
-# from pymongo import ASCENDING, DESCENDING
-
 from openju.model import *
 
 def post_message(user, body):
     """
     return Message.objects.get(id=message_id)
 
-# from openju import g
-
-# def get_next_hrid():
-#     """ Get the next human-readable id
-#     TODO: rewrite it somehow! Really! It won't work if you'll have more then one worker
-#     """
-#     with get_mongo_db() as db:
-#         last_message = (
-#             db.messages
-#             .find(None, ['hrid'])
-#             .sort('hrid', DESCENDING)
-#             .limit(1))
-#         return last_message[0]['hrid'] + 1
-
-# def get_next_hrid_r_no(hrid):
-#     with get_mongo_db() as db:
-#         last_reply_no = (
-#             db.messages
-#             .find(
-#                 {'hrid': hrid},
-#                 ['r_no'])
-#             .sort('r_no', DESCENDING)
-#             .limit(1))
-#         val = last_reply_no[0].get('r_no') or 0
-#         return val + 1
-
-    # next_hrid = get_next_hrid()
-    # with get_mongo_db() as db:
-    #     db.messages.insert(dict(
-    #         jid = jid,
-    #         message = message,
-    #         hrid = next_hrid,
-    #         dt = datetime.now()))
-    # return next_hrid
-
 # def post_reply(jid, hrid, message, r_no=None):
 #     # hrid = int(hrid)
 #     # if r_no is not None:
 #             r_no = next_r_no,
 #             dt = datetime.now()))
 #         return next_r_no
-
-# def one_from_hrid(hrid):
-#     """ Get one message by it's hrid. """
-#     with get_mongo_db() as db:
-#         message = db.messages.find_one(dict(
-#             hrid = hrid,
-#             r_id = { '$exists': False }))
-#         if message is None:
-#             raise PostNotExistError(u'Message does not exist')
-#         return message
-
-    # with get_mongo_db() as db:
-    #     messages = (
-    #         db.messages
-    #         .find(dict(r_id = { '$exists': False }))
-    #         .sort('hrid', DESCENDING)
-    #         .limit(limit))
-    #     return messages
-
-# # TODO: rewrite this because of similarity of bl.user.get_users_for_messages
-# def get_replytos_for_messages(messages):
-#     """ Returns map message_id -> message, reply to which it was given """
-#     ids = [x.r_id for x in messages if x.r_id is not None]
-#     with get_mongo_db() as db:
-#         replytos = db.messages.find(dict(
-#             _id = {
-#                 '$in': ids
-#                 }))
-#         replyto_map = dict((x._id, x) for x in replytos)
-#         message__replyto_map = dict((x._id, replyto_map[x.r_id]) for x in messages)
-#         return message__replyto_map
-    

openju/bl/user.py

 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
-# from pymongo.errors import DuplicateKeyError
 from mongoengine.queryset import OperationError
 
 from openju import _
 from openju.model import *
 
-# from openju import g
 from openju import current_app as app
 
-# from openju.util import get_mongo_db
-# from openju.validators import validate_nickname
-
 def register(jid, nick):
     user = User(
         jid=jid,
 #             { '_id': jid,
 #               'nick': nick },
 #             upsert=True)
-
-# def one_from_jid(jid):
-#     with get_mongo_db() as db:
-#         user = db.users.find_one(dict(_id = jid))
-
-# def get_nick_by_jid(jid):
-#     with get_mongo_db() as db:
-#         user = db.users.find_one(dict(_id = jid))
-#         return jid if user is None else user.get('nick', jid)
-
-# def get_users_for_messages(messages):
-#     """ Returns map message_id -> user """
-#     jids = [x.jid for x in messages]
-#     with get_mongo_db() as db:
-#         users = db.users.find(dict(
-#             _id = {
-#                 '$in': jids
-#                 }))
-#         user_map = dict((x._id, x) for x in users)
-#         message__user_map = dict((x._id, user_map[x.jid]) for x in messages)
-#         return message__user_map
-    

openju/message_bus.py

             d = m.groupdict()
             return controllers.message.read(d['message_hrid'])
     
-    # def cmd_read_message(user_jid, text):
-    #     # pattern = re.compile(ur'#(?P<message_hrid>[0-9]+)(/(?P<r_no>[0-9]+))?(?P<more>\+)?\s*')
-    #     pattern = re.compile(ur'^#(?P<message_hrid>[0-9]+)\s*$')
-    #     m = pattern.match(text)
-    #     if m is not None:
-    #         d = m.groupdict()
-    #         # d['r_no'] = none_or_int(d['r_no'])
-    #         return controllers.message.read(int(d['message_hrid']))
-    
     # def cmd_new_nick(user_jid, text):
     #     cmd_text = u'NICK'
     #     if text.startswith(cmd_text):
 # -*- coding: utf-8 -*-
 
 import datetime
-# from pymongo.objectid import ObjectId
-# from mongokit import *
 from mongoengine import *
 
-# from openju.globals import g
-
 class User(Document):
     jid = StringField(max_length=200, required=True, unique=True)
     nick = StringField(max_length=200, required=True, unique=True)
     meta = {
         'ordering': ['-dt']
     }
-    
-# @con.register
-# class User(Document):
-#     __collection__ = 'user'
-#     __database__ = 'openju'
-#     structure = {
-#         'jid': unicode,
-#         'nick': unicode,
-#         }
-#     required_fields = ['jid', 'nick']
-#     use_autorefs = True
-#     indexes = [
-#         {
-#             'fields': ['nick', 'jid'],
-#             'unique': True,
-#             }
-#         ]
-
-# @con.register
-# class Message(Document):
-#     __collection__ = 'message'
-#     __database__ = 'openju'
-#     structure = {
-#         'user': User,
-#         'body': unicode,
-#         'dt': datetime.datetime,
-#         'reply_to': None, # Message
-#         }
-#     required_fields = ['user', 'body', 'dt']
-#     default_values = {'dt': datetime.datetime.utcnow}
-#     use_autorefs = True
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.