コード例 #1
0
ファイル: Conversation.py プロジェクト: nikko0327/Ninja-Tutor
 def get(self):
    logging.info("hi")
    user = self.user_model
    user.msg_count = 0
    msg_count = user.msg_count
    user.put()
    conversations = Conversation.query(ndb.OR(
        user.username == Conversation.sender, 
        user.username == Conversation.recipient))

    notifications = NotifiedMessage.query(NotifiedMessage.person_reference == user.username).fetch(10)
    notis_count = len(notifications)
    



    self.response.out.write(template.render('views/messages.html', {'viewer': user, 
                                                                    'conversations': conversations,
                                                                    'notifications': notifications,
                                                                    'notis_count': notis_count,
                                                                    'msg_count': msg_count
                                                                    }))
コード例 #2
0
ファイル: Conversation.py プロジェクト: nikko0327/Ninja-Tutor
 def post(self):

    recipient = cgi.escape(self.request.get('recipient'))
    text = cgi.escape(self.request.get('text'))
    sender = cgi.escape(self.request.get('sender'))


    #create msg and put

    #is this conversation already existed?
    #Yes
        #attach message
    #No create a new one
        #owner, sender, msg

    #put

    #There's a new coming msg to owner
    mesg = Message()
    mesg.time = datetime.datetime.now() - datetime.timedelta(hours=8)
    mesg.sender = sender
    mesg.recipient = recipient
    mesg.text = text
    mesg.put()
    
    owners_temp = []
    owners_temp.append(sender)
    owners_temp.append(recipient)

    temp1 = " ".join((sender, recipient))
    temp2 = " ".join((recipient, sender))

    recipient_user = User.query(User.username == recipient).get()
    if recipient_user:
        recipient_user.msg_count += 1
    recipient_user.put()



    
    conversation_qry = Conversation.query(ndb.OR(Conversation.owners == temp1, Conversation.owners == temp2)).get()
    
    if conversation_qry:
        logging.info("yes")
        #logging.info(conversation_qry.owners)
        conversation_qry.children.append(mesg.key)
        conversation_qry.msg_count = conversation_qry.msg_count + 1
        conversation_qry.most_recent_msg = mesg.text
        conversation_qry.most_recent_date = str(mesg.time)


        conversation_qry.put()
        
    else:
        logging.info("noooooooooo")
        #logging.info(conversation_qry)
        conv = Conversation()
        conv.sender = sender
        conv.recipient = recipient
        conv.owners = " ".join((sender, recipient))
        conv.children.append(mesg.key)
        conv.msg_count = conv.msg_count + 1
        conv.most_recent_msg = mesg.text
        conv.most_recent_date = str(mesg.time)
        conv.put()
コード例 #3
0
ファイル: Conversation.py プロジェクト: nikko0327/Ninja-Tutor
  def get(self, conv_reference):
    user = self.user_model
    #parse string
    #get messages
    temp_query = conv_reference.strip()
    temp = temp_query.split('&')

    msg_count = user.msg_count


    notifications = NotifiedMessage.query(NotifiedMessage.person_reference == user.username).fetch(10)
    notis_count = len(notifications)

    string1 = str(temp[0])
    string1 = str(string1).replace('[','').replace(']','')
    string1 = str(string1).replace("'",'').replace("'",'')
    string1 = str(string1).replace(" ","")
    string1 = str(string1).replace(","," ")

    string2 = str(temp[1:2])
    string2 = str(string2).replace('[','').replace(']','')
    string2 = str(string2).replace("'",'').replace("'",'')
    string2 = str(string2).replace(" ","")
    string2 = str(string2).replace(","," ")


    #logging.info(string2 + " " + string1)
    #logging.info(string1 + " " + string2)

    temp1 = " ".join((string1, string2))    #conv_ref
    temp2 = " ".join((string2, string1))    #conv_ref_inverse

    if user.username != string1 and user.username != string2:
        self.response.out.write(template.render('views/404notfound.html',{}))

    else:



        conversation_qry = Conversation.query(ndb.OR(Conversation.owners == temp1, Conversation.owners == temp2)).get()

        messages = []

        if conversation_qry:
            for oneMessage in conversation_qry.children:
                logging.info(oneMessage.get())
                messages.append(oneMessage.get())

        else:
            logging.info("not found")


        #self.response.out.write(template.render('views/404notfound.html',{})) #prevent people other than tutor and tutee to see this transaction
        self.response.out.write(template.render('views/readMessage.html', {'messages': messages, 
                                                                            'user': user, 
                                                                            'temp2': temp2, 
                                                                            'temp1': temp1,
                                                                            'notifications': notifications,
                                                                            'notis_count': notis_count,
                                                                            'msg_count': msg_count
                                                                            }))
コード例 #4
0
ファイル: inbox.py プロジェクト: alexmedanchuk/Code-Samples
 def get(self):
     conversations = Conversation.query(Conversation.user_keys == self.user.key,
         Conversation.visibleto_user_keys == self.user.key).order(-Conversation.modified).fetch()
     self.render_json_response(conversations)