Konstantine Rybnikov avatar Konstantine Rybnikov committed 3c7b758

fucking commenting everything out

Comments (0)

Files changed (5)

         
         from openju.globals import _request_ctx_stack
         
+        from mongokit import Connection
+        params = [
+            x for x in [
+                self.config.get('MONGO_HOST'),
+                self.config.get('MONGO_PORT')
+                ]
+            if x is not None]
+        
         meta = MetaObject()
         meta.current_app = self
         meta.g = MetaObject()
+        meta.g.connection = Connection(*params)
+        meta.g.db = meta.g.connection.openju
         _request_ctx_stack.push(meta)
         
         def step_on(conn):
         # step on
         while step_on(conn):
             pass
-        

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 datetime import datetime
+# from pymongo import DESCENDING
+# from openju.util import get_mongo_db
+# from openju.validators import PostNotExistError
 
-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
+from openju import g
 
-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
+# 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
 
 def post_message(jid, message):
-    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
+    pass
+    # 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 = int(r_no)
-    with get_mongo_db() as db:
-        # check is post exist and get id
-        post = (
-            db.messages
-            .find(
-                dict(
-                    hrid = hrid,
-                    r_no = r_no),
-                [],
-                )
-            .limit(1))
-        if post.count() == 0:
-            raise PostNotExistError(u'Message does not exist')
-        post_id = post[0]['_id']
-        next_r_no = get_next_hrid_r_no(hrid)
-        db.messages.insert(dict(
-            jid = jid,
-            message = message,
-            hrid = hrid,
-            r_to = post_id,
-            r_no = next_r_no,
-            dt = datetime.now()))
-        return next_r_no
+# def post_reply(jid, hrid, message, r_no=None):
+#     # hrid = int(hrid)
+#     # if r_no is not None:
+#     #     r_no = int(r_no)
+#     with get_mongo_db() as db:
+#         # check is post exist and get id
+#         post = (
+#             db.messages
+#             .find(
+#                 dict(
+#                     hrid = hrid,
+#                     r_no = r_no),
+#                 [],
+#                 )
+#             .limit(1))
+#         if post.count() == 0:
+#             raise PostNotExistError(u'Message does not exist')
+#         post_id = post[0]['_id']
+#         next_r_no = get_next_hrid_r_no(hrid)
+#         db.messages.insert(dict(
+#             jid = jid,
+#             message = message,
+#             hrid = hrid,
+#             r_to = post_id,
+#             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
+# 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
 
 def get_last_messages(limit=10):
-    with get_mongo_db() as db:
-        messages = (
-            db.messages
-            .find(dict(r_id = { '$exists': False }))
-            .sort('hrid', DESCENDING)
-            .limit(limit))
-        return messages
+    return g.db.Message.find().limit(limit)
+    
+    # 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):

openju/controllers/message.py

 from openju import bl, g
 
 def post(text):
-    next_hrid = int(bl.message.post_message(g.user_jid, text))
-    return u'Message #%s posted' % next_hrid
+    next_id = int(bl.message.post_message(g.auth_user, text))
+    return u'Message #%s posted' % next_id
 
-def post_reply(hrid, message, r_no=None):
-    r_no = bl.message.post_reply(
-        g.user_jid,
-        hrid,
-        message,
-        r_no=r_no)
-    return u'Reply posted. #%s/%s' % (hrid, r_no)
+# def post_reply(hrid, message, r_no=None):
+#     r_no = bl.message.post_reply(
+#         g.user_jid,
+#         hrid,
+#         message,
+#         r_no=r_no)
+#     return u'Reply posted. #%s/%s' % (hrid, r_no)
 
-def read(hrid):
-    message = bl.message.one_from_hrid(hrid)
-    user_nick = bl.user.get_nick_by_jid(message['jid'])
+# def read(hrid):
+#     message = bl.message.one_from_hrid(hrid)
+#     user_nick = bl.user.get_nick_by_jid(message['jid'])
     
-    ret_msg = (
-        u"""\n@%(user)s:\n"""
-        u"""%(body)s\n"""
-        u"""#%(hrid)s posted at %(dt)s""") % dict(
-        user = user_nick,
-        body = message['message'],
-        hrid = hrid,
-        dt = message['dt']
-        )
-    return ret_msg
+#     ret_msg = (
+#         u"""\n@%(user)s:\n"""
+#         u"""%(body)s\n"""
+#         u"""#%(hrid)s posted at %(dt)s""") % dict(
+#         user = user_nick,
+#         body = message['message'],
+#         hrid = hrid,
+#         dt = message['dt']
+#         )
+#     return ret_msg
 
 def last_messages():
     messages = bl.message.get_last_messages()
             body = message['message'],
             hrid = int(message['hrid']),
             dt = message['dt'])
+    else:
+        ret_val = u'There are no messages yet. Go on, post one!'
     return ret_val

openju/message_bus.py

 from openju.validators import UserAlertError
 import openju.controllers as controllers
 
+from openju.globals import current_app as app
+
 def error_handler(f):
     def new_f(conn, *args, **kw):
         try:
             g.user = user
             g.text = text
             g.user_jid = user_jid
-
+            g.auth_user = (
+                app.db.Message
+                .find_one(
+                    jid = user_jid))
+            
             call_list(
                 cmd_last_messages,
                 cmd_read_message,
+# -*- coding: utf-8 -*-
+
+import datetime
+from pymongo.objectid import ObjectId
+from mongokit import *
+
+from openju.globals import current_app
+
+con = current_app.connection
+
+@con.register
+class User(Document):
+    structure = {
+        'jid': unicode,
+        'nick': unicode,
+        }
+    required_fields = ['jid']
+
+@con.register
+class Message(Document):
+    __collection__ = 'message'
+    structure = {
+        'user': User,
+        'message': unicode,
+        'reply_to': ObjectId,
+        'dt': datetime.datetime,
+        }
+    required_fields = ['user', 'message']
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.