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


Python Message.save方法代码示例

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


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

示例1: message_out

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [as 别名]
def message_out():
#    login.logout_user()
    org_form = SelectOrgForm(Orgs=build_orgs())
    print build_orgs().choices[0]
    message_form = MessageForm(Choices=build_users(build_orgs().choices[0][1]))
    save_org = build_orgs().choices[0][1]
    if request.method == 'POST':
        if request.form['btn']=="select":
            print "select"
            d_choices = dict(build_orgs().choices)
            print d_choices[org_form.org.data]
            save_org = d_choices[org_form.org.data]
            message_form = MessageForm(Choices=build_users(d_choices[org_form.org.data]))
        else:
            print "send"
            print save_org
            if save_org is None:
                print "None"
            else:
                d2_choices = dict(build_users(save_org).choices)
                print d2_choices[message_form.name_to.data]
            message = Message()
            message.addr = d2_choices[message_form.name_to.data]
            message.subject = str(message_form.subject.data)
            message.message = str(message_form.content.data)
            message.save()
            flash("Message Sent", category='success')
#    message_form = MessageForm()
    return render_template('forum/org_list.html' ,form=org_form, message_form=message_form)
开发者ID:sheng01,项目名称:DuluthKids.Net,代码行数:31,代码来源:views.py

示例2: create

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [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

示例3: do_ntranslate

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [as 别名]
def do_ntranslate(singular, plural, number, translation_function):
    language = trans_real.get_language()

    translation = trans_real.translation(language)
    number = translation.plural(number)

    kw = {'msgid': singular, 'plural': number, 'language': language,
            'domain': 'django'}
    try:
        message = Message.objects.get(**kw)
    except Message.DoesNotExist:
        # Miss
        msgstr = do_ntranslate_old(singular, plural, number,
                                   translation_function)
        kw['msgstr'] = msgstr
        message = Message(**kw)
        message.save()
        return msgstr

    # Hit
    translation = message.translation
    if not translation:
        return do_ntranslate_old(singular, plural, number,
                                 translation_function)

    return translation
开发者ID:emencia,项目名称:django-localizer,代码行数:28,代码来源:__init__.py

示例4: store_message

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [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

示例5: save_msg

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [as 别名]
def save_msg():
    form = request.form
    author = form.get("author")
    content = form.get("content")
    msg = Message(author=author, content=content, time=datetime.now())
    msg.save()
    return jsonify(status='success')
开发者ID:03013314,项目名称:python-1,代码行数:9,代码来源:views.py

示例6: restore_object

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [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
开发者ID:VikParuchuri,项目名称:movide,代码行数:29,代码来源:serializers.py

示例7: save_message

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [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)
开发者ID:FelipePiacsek,项目名称:chat_angular,代码行数:37,代码来源:messages.py

示例8: detail_message

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [as 别名]
def detail_message(request, conv_id):
    """
    view untuk menampilkan detail pesan
    beserta percakapan
    """
    conv = get_object_or_404(Conversation, id=conv_id, users=request.user, membership__deleted=False)
    list_messages = Message.objects.filter(conversation=conv)
    msg = list_messages[0]
    if request.POST:
        form = SendConversationForm(request.POST)
        if form.is_valid():
            msg = Message()
            msg.conversation = conv
            msg.user = request.user
            msg.content = form.cleaned_data['content']
            msg.save()
            to2 = list(conv.users.all())
            to2.remove(request.user)
            notification.send(to2, 'new_message', {'user': request.user, 'message': conv})
            messages.info(request, _('Message sent'))
            return HttpResponseRedirect(conv.get_absolute_url())
    else:
        form = SendConversationForm()
    return render_to_response('message/detail_message.html',
            {"conv": conv,
                'form': form,
                'msg': msg,
                'list_messages': list_messages},
            context_instance=RequestContext(request))
开发者ID:sakti,项目名称:ittelkomnewsmap,代码行数:31,代码来源:views.py

示例9: send_msg

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [as 别名]
def send_msg(request):
    response = {}
    info = ""
    try:
        if request.method == 'POST':
            req = request.POST
            recv_user = req.get('recv_user')
            send_user = req.get('send_user')
            title = req.get('title')
            content = req.get('content')
            msg = Message(title=title, content=content)
            # 发送者ID为1则是系统信息
            if send_user == 1:
                msg.category = 1
            msg.save()
            user_msg = UserMessage(recv_user=recv_user,send_user=send_user,message=msg)
            user_msg.save()
            response['status'] = user_msg.status

    except:
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        return HttpResponse(info)

    response_json = simplejson.dumps(response)
    return HttpResponse(response_json)
开发者ID:yinzhedfs,项目名称:django_demo,代码行数:27,代码来源:views.py

示例10: send

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [as 别名]
def send(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)

        if form.is_valid():
            msg = Message()
            msg.username = form.cleaned_data['username']
            msg.email = form.cleaned_data['email']
            msg.phone = form.cleaned_data['phone']
            msg.location = form.cleaned_data['location']
            msg.job = form.cleaned_data['job']
            msg.description = form.cleaned_data['description']
            msg.area = form.cleaned_data['area']

            try:
                msg.save()
                mail_managers('ZUBIRD webpage - new message received', 'Otrzymałeś nową wiadomość.')
            except Exception as e:
                import traceback
                logger.error(str(e))
                logger.error(traceback.format_exc())
                return render_to_response('error.html', {})
            
            return render_to_response('thanks.html', {})
        else:
            return render_to_response('base.html', Context({'form':form}))
    else:
        return index(request)    
开发者ID:kjopek,项目名称:zubird_webapp,代码行数:30,代码来源:views.py

示例11: displaycontrol

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [as 别名]
def displaycontrol(request):
    """
    If the request is a GET, renders the display control dialog content. If it's
    a POST, uses the POST data to send a Message to Harvest. That Message
    requests a change to a given client's display's hardware state, depending on
    the command specified in the request.
    The client's user must be an administrator for the Message to be sent.
    """
    if request.method == 'GET':
        return render_to_response('orwell/displaycontrol.html',
                                  {},
                                  context_instance=RequestContext(request))
    else:
        if not request.user.is_staff:
            return HttpResponse('DISALLOWED')
        clientid = request.POST.get('client', '')
        client = get_object_or_404(Client, client_id=clientid)
        setpower = request.POST.get('setpower', '')
        cmd = request.POST.get('cmd', '')
        arg = request.POST.get('arg', '')
        packet = {'to':client.jid(), 'method':'displaycontrol'}
        if setpower == 'kill':
            packet['method'] = 'killDDS'
        if setpower in ['on', 'off']:
            packet['setpower'] = setpower == 'on'
        elif cmd != '' and arg != '':
            packet['cmd'] = {'cmd':cmd, 'arg':arg}
        if (('setpower' in packet) or ('cmd' in packet)
            or (packet['method'] == 'killDDS')):
            m = Message(message=json.dumps(packet))
            m.save()
        return HttpResponse('OK')
开发者ID:crew,项目名称:dds-backend,代码行数:34,代码来源:views.py

示例12: process_messages

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [as 别名]
def process_messages(limit):
    count = 0
    date_parser = dateutil.parser.parser()
    omsgs = OriginalMessage.objects()
    if limit:
        omsgs = omsgs.limit(limit)
    for raw_count, om in enumerate(omsgs):
        m = Message()
        m.body = om.body
        m.subFolder = om.subFolder
        m.filename = om.filename
        m.headers = om.headers
        m.subject = om.get_subject()
        m.date = date_parser.parse(om.get_date())
        m.to = [x for x in om.get_to() if "enron.com" in x]
        if not m.to:
            # Skip if none of the "To's" are to enron employees
            continue
        m.from_str = om.get_from()
        if "enron.com" not in m.from_str:
            # Skip if this email was not from an enron employee
            continue
        try:
            m.save()
        except Exception, e:
            print "Error trying to save: %s" % (m)
            print e
        count+=1
        if count % 5000 == 0:
            print "Processing %s raw messages, filtered to %s" % (raw_count, count)
开发者ID:jwmatthews,项目名称:BumptUp,代码行数:32,代码来源:reformat_data.py

示例13: handle_received_message

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [as 别名]
    def handle_received_message(self,
        sender, room_id, username, message, date, **kwargs):
        """
        Default handler for the message_received signal.
        1 - Saves an instance of message to db
        2 - Appends a tuple (message_id, message_obj)
            to the sender.messages queue
        3 - Signals the "New message" event on the sender (decorator)
        4 - Returns the created message

        """
        room = Room.objects.get(id=room_id)
        fields = {
            'room': room,
            'date': date,
            'content': message,
            'username': username,
        }
        user = kwargs.get('user')
        if user:
            fields['user'] = user
        # 1
        new_message = Message(**fields)
        new_message.save()

        # 2
        msg_number = sender.get_next_message_id(room_id)
        messages_queue = sender.get_messages_queue(room_id)
        messages_queue.append((msg_number, new_message))

        # 3 - decorator does
        # sender.signal_new_message_event(room_id)

        # 4
        return new_message
开发者ID:Mondego,项目名称:pyreco,代码行数:37,代码来源:allPythonContent.py

示例14: home_screen

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [as 别名]
def home_screen(request):
    context = {}
    if 'submit' in request.POST:
        msge = Message(name=request.POST['name'], email=request.POST['email'], message=request.POST['message'])
        msge.save()
        context.update({'message': 'Successfully Saved', 'messagetype': 'success'})
    context.update(csrf(request))
    return render(request, 'index.html', context)
开发者ID:mohitreddy1996,项目名称:Personal-Website,代码行数:10,代码来源:views.py

示例15: save

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import save [as 别名]
	def save(self):
		message = Message(
			leave_by=self.user,
			subject=self.cleaned_data['subject'],
			content=self.cleaned_data['content']
		)
		message.save()
		return message
开发者ID:jewelhuq,项目名称:python-simple-book,代码行数:10,代码来源:forms.py


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