当前位置: 首页>>代码示例>>Python>>正文


Python Message.text方法代码示例

本文整理汇总了Python中models.Message.text方法的典型用法代码示例。如果您正苦于以下问题:Python Message.text方法的具体用法?Python Message.text怎么用?Python Message.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Message的用法示例。


在下文中一共展示了Message.text方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import text [as 别名]
 def post(self):
   text = cgi.escape(self.request.get('text'))
   sender = cgi.escape(self.request.get('sender'))
   recipient = cgi.escape(self.request.get('recipient'))
   subject = cgi.escape(self.request.get('subject'))
   parent_message = cgi.escape(self.request.get('parent'))
   q = User.query(User.username == recipient)
   user = q.get()
   if(user):
     if len(parent_message) > 0:
       message_key = ndb.Key(urlsafe=parent_message)
       message = Message(parent = message_key)
     else:
       message = Message()
     message.subject = subject
     message.text = text
     message.sender = sender
     message.recipient = recipient
     message.time = datetime.datetime.now() - datetime.timedelta(hours=7) #For PST
     message.put()
     #Increment message count for navbar
     q = User.query(User.username == recipient)
     user = q.get()
     user.message_count += 1
     user.put()
     self.redirect('/messages')
   else:
     self.redirect('/compose')
开发者ID:tungply7,项目名称:Tutoring-Service,代码行数:30,代码来源:Messages.py

示例2: store_message

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import text [as 别名]
def store_message(text, tagList, user, tags_required, private):
  #Construct the message itself.
  message = Message()
  message.user = user
  message.text = text
  message.tags_required = tags_required
  message.private = private
  message.save()

  #Store each tag.
  for tag in tagList:
    #Remove the prefix.
    prefix = tag[0]
    tag = tag[1:]

    if prefix=="#":
      if tag_exists(tag):
        add_tag_to_message(tag, message)
      else:
        store_tag(tag, message)
    elif prefix=="@":
      if user_exists(tag):
        add_user_to_message(tag, message);
    else:
      raise Exception("Tag has inapproriate prefix. Choices are '@' or '#'.")

  message.save()
  return message
开发者ID:meriada,项目名称:GoBoard,代码行数:30,代码来源:models_constructors.py

示例3: create

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import text [as 别名]
def create():
    ''' Save new message. '''
    if not (request.POST.get('nickname') and request.POST.get('text')):
        redirect('/')
    msg = Message()
    msg.nickname = request.POST['nickname']
    msg.text = request.POST['text']
    if 'image' in request.files:
        upload = request.files['image']
        if not upload.filename.lower().endswith(
                ('.jpg', '.jpeg', '.png', '.bmp', '.gif')):
            redirect('/')
        mime = mimetypes.guess_type(upload.filename)[0]
        msg.image_filename = upload.filename
        # Save fullsize image
        msg.image.put(upload.file, content_type=mime)
        # Create and save thumbnail
        image = Image.open(msg.image)
        image.thumbnail((80, 60), Image.ANTIALIAS)
        data = StringIO.StringIO()
        image.save(data, image.format)
        data.seek(0)
        msg.thumb.put(data, content_type=mime)
    msg.save()
    redirect('/')
开发者ID:iontom,项目名称:bottle-mongodb-example,代码行数:27,代码来源:controllers.py

示例4: save

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import text [as 别名]
 def save(self, author, reciever):
     new = Message()
     new.user1 = author
     new.user2 = reciever
     new.time = datetime.now()
     new.title = self.cleaned_data['title']
     new.text = self.cleaned_data['text']
     new.save()
开发者ID:romanvlasiuk,项目名称:MyNetwork,代码行数:10,代码来源:forms.py

示例5: store_message

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import text [as 别名]
def store_message(text, tagList, user, tags_required, private):
  #Construct the message itself.
  message = Message()
  message.user = user
  message.text = text
  message.tags_required = tags_required
  message.private = private
  message.save()

  #Store each tag.
  for tag in tagList:
    connect_tag(tag, message=message)

  message.save()
  return message
开发者ID:Haverford-FIG,项目名称:GoBoard,代码行数:17,代码来源:models_constructors.py

示例6: store_message

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import text [as 别名]
def store_message(text, tagList, user, tags_required):
  #Construct the message itself.
  message = Message()
  message.user = user
  message.text = text
  message.tags_required = tags_required
  message.save()

  #Store each tag.
  for new_tag in tagList:
    if tag_exists(new_tag):
      new_tag.message.add(message)
    else:
      store_tag(new_tag, message)

  return message
开发者ID:bsmith8108,项目名称:GoBoard,代码行数:18,代码来源:models_constructors.py

示例7: api_compose

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import text [as 别名]
def api_compose():
    if not request.json:
        return jsonify({'status': 'false', 'error': 'Not JSON'})
    mess = Message()
    try:
        mess.text = request.json['text']
        mess.destName = request.json['destName']
        mess.originName = request.json['originName']
    except KeyError:
        return jsonify({'status': 'false', 'error': 'Missing fields.'})
    if load_user(mess.destName) is None or load_user(mess.originName) is None:
        return jsonify({'status': 'false', 'error': 'Users do not exist.'})
    mess.read = False
    mess.sent = datetime.datetime.now()
    db.session.add(mess)
    db.session.commit()
    return jsonify({'status': 'true'})
开发者ID:mikaylathompson,项目名称:Pigeon,代码行数:19,代码来源:views.py

示例8: convertItem

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import text [as 别名]
    def convertItem(self, item, minDate):

        date = parser.parse(item.pubDate.string)

        # Check if needs to parse
        if minDate and minDate >= date:
            return

        message = self.cleanTag(item.title.string)
        author = item.find(name='creator', text=False).string
        url = item.link.string

        text = u'<b>%s:</b> %s \n\n<a href="%s">%s</a>' \
               % (author, message, url, url)

        message = Message()
        message.text = text
        message.date = date

        return message
开发者ID:HackLab-Almeria,项目名称:hacklabalmeria-telegrambot,代码行数:22,代码来源:adapters.py

示例9: create

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import text [as 别名]
def create():
    """ Save new message. """
    if not (request.POST.get("nickname") and request.POST.get("text")):
        redirect("/")
    msg = Message()
    msg.nickname = request.POST["nickname"]
    msg.text = request.POST["text"]
    if "image" in request.files:
        upload = request.files["image"]
        if not upload.filename.lower().endswith((".jpg", ".jpeg", ".png", ".bmp", ".gif")):
            redirect("/")
        mime = mimetypes.guess_type(upload.filename)[0]
        msg.image_filename = upload.filename
        # Save fullsize image
        msg.image.put(upload.file, content_type=mime)
        # Create and save thumbnail
        image = Image.open(msg.image)
        image.thumbnail((80, 60), Image.ANTIALIAS)
        data = StringIO.StringIO()
        image.save(data, image.format)
        data.seek(0)
        msg.thumb.put(data, content_type=mime)
    msg.save()
    redirect("/")
开发者ID:srackham,项目名称:bottle-mongodb-example,代码行数:26,代码来源:controllers.py

示例10: post

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import text [as 别名]
 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()
开发者ID:nikko0327,项目名称:Ninja-Tutor,代码行数:67,代码来源:Conversation.py

示例11: Http404

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import text [as 别名]
    host: The hostname of the computer the client is running on
    """
    if request.method != "POST":
        print "Did not post"
        raise Http404("You must post to this URL")

    receiver_account = get_or_create_account(protocol, request.POST["receiver_account"], request.POST["owner_account"])
    sender_account = get_or_create_account(protocol, request.POST["sender_account"], request.POST["owner_account"])  
    if sender_account.full_name == "":
        sender_account.full_name = request.POST["alias"]
        sender_account.save()
    
    try:
        timestamp = datetime.datetime.strptime(request.POST["timestamp"][:-6], "%Y-%m-%dT%H:%M:%S")
    except Exception, e:
        print e.message
        timestamp = datetime.datetime.strptime(request.POST["timestamp"][:-6], "%Y-%m-%d %H:%M:%S")
    messages = Message.objects.filter(sender=sender_account).filter(receiver=receiver_account).filter(timestamp=timestamp)
    if len(messages) > 0:
        return HttpResponse(simplejson.dumps({"result":False,"reason":"Duplicate message"}), mimetype="application/json")
    message = Message()
    message.receiver = receiver_account
    message.sender = sender_account
    message.timestamp = timestamp
    message.text = request.POST["message_text"]
    message.client_type = request.POST["client_type"]
    message.host = request.POST["host"]
    message.save()

    data = simplejson.dumps({"result":True})
    return HttpResponse(data, mimetype="application/json")
开发者ID:tangerilli,项目名称:dool,代码行数:33,代码来源:views.py


注:本文中的models.Message.text方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。