本文整理汇总了Python中models.Message.message_type方法的典型用法代码示例。如果您正苦于以下问题:Python Message.message_type方法的具体用法?Python Message.message_type怎么用?Python Message.message_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Message
的用法示例。
在下文中一共展示了Message.message_type方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import message_type [as 别名]
def save_message(user_id, message):
type_name = message.get('type_name')
args = message.get('args')
file = message.get('file', '')
conversation_id = message.get('conversation_id')
mt = MessageType.select().where(MessageType.name == type_name).first()
u = User.select().where(User.id == user_id).first()
cps = ConversationParty.select().where(ConversationParty.conversation == conversation_id)
number_of_conversationees = cps.count()
if not mt or not u or not cps or not number_of_conversationees:
raise InvalidMessageDataException('Couldn\'t save message: invalid message data')
m = Message()
with database.transaction():
m.conversation = conversation_id
m.message_type = mt
m.sender_id = user_id
m.ts = datetime.now()
m.file = file
m.content, m.display_content = __save_content(args, mt, user_id, cps)
m.save()
update_conversation(conversation_id=conversation_id,
last_message=m)
mark_message_as_read(user_id=user_id,
message=m,
conversation_id=conversation_id)
message_object = get_message_json(message=m)
message_object['recipient_ids'] = [cp.user.id for cp in cps]
return json.dumps(message_object)
示例2: restore_object
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import message_type [as 别名]
def restore_object(self, attrs, instance=None):
user = self.context['request'].user
classgroup = attrs.get('classgroup')
attributes = ["text", "source", "reply_to"]
if (classgroup.class_settings is not None and
classgroup.class_settings.enable_posting is False and
not ClassGroupPermissions.is_teacher(classgroup, user)):
raise serializers.ValidationError("You are not allowed to make a post right now.")
if instance is None:
instance = Message(user=user, classgroup=classgroup)
else:
if instance.user != user:
raise serializers.ValidationError("Attempting to edit a message that is not yours.")
message_type = attrs.get('message_type')
if message_type == "A" and not ClassGroupPermissions.is_teacher(classgroup, user):
raise serializers.ValidationError("You cannot make an announcement unless you own a course.")
instance.message_type = message_type
instance = set_attributes(attributes, attrs, instance)
instance.save()
return instance
示例3: get_error_message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import message_type [as 别名]
def get_error_message(e, current_user_id):
mt = MessageType()
mt.constructor = 'error_message'
m = Message()
m.message_type = mt
m.run_constructor(e)
return __jsonify_error_message(m, current_user_id)
示例4: Message
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import message_type [as 别名]
from models import BaseModel, User, Conversation, ConversationParty, Message, MessageType, database
from datetime import datetime
# Messages
m = Message()
m.conversation = Conversation.get(Conversation.id==1)
m.sender = User.get(User.id==1)
m.message_type = MessageType.get(MessageType.name=='directive_quotation_mt')
m.ts = datetime.now()
args = {'currency':'R$',
'per_day_beneficiary_value':'20.50',
'number_of_beneficiaries':'5',
'company_name':'VR',
'company_picture':''
}
with database.transaction():
m.save()
m.run_constructor(args)
m.save()
示例5: test_location_req
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import message_type [as 别名]
def test_location_req(self):
m = Message()
m.imei = '865328021048409'
m.message_type = config.MESSAGE_TYPE_REQ_LOCATION
m.save()