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


Python forms.MessageForm类代码示例

本文整理汇总了Python中forms.MessageForm的典型用法代码示例。如果您正苦于以下问题:Python MessageForm类的具体用法?Python MessageForm怎么用?Python MessageForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: view_message

def view_message(request, pk):
    profile = request.user.get_profile()
    messages = Message.objects.filter(thread=pk)
    if (messages[0].to == profile) or (messages[0].author == profile):
        if request.POST:
            form = MessageForm(request.POST)
            if form.is_valid():
                form.save(commit=False)
                f = form
                f.author = profile
                f.save()
            else:
                print form.errors

        message_list = Message.objects.filter(thread=pk).order_by("-date_created")
        message_form = MessageForm()

        return render_to_response(
            "publication/message_thread.html",
            {"message_list": message_list, "message_form": message_form, "profile": profile},
            context_instance=RequestContext(request),
        )

    else:
        return HttpResponseRedirect("/messages/")
开发者ID:katarinakyh,项目名称:cc7,代码行数:25,代码来源:views.py

示例2: home

def home():
    """Renders the home page."""
    form = MessageForm(request.form)
    if request.method == 'POST' and form.validate():
        #Save to db
        table_service = TableService(account_name=config.ACC_NAME, 
                                     account_key=config.ACC_KEY)
        message = {'PartitionKey': 'message', 
                   'RowKey': form.name.data + datetime.datetime.now().isoformat(), 
                   'name' : form.name.data,
                   'email': form.email.data,
                   'date' : str(datetime.datetime.now())}
        if form.message_body.data:
            message["message"] = form.message_body.data
        table_service.insert_entity('landingmessages', message)
        return render_template(
            'index.html',
            hiden_block='#wright-us',
            form=form,
        )
    return render_template(
        'index.html',
        hiden_block='#got-ur-message',
        form=form,
    )
开发者ID:catInet,项目名称:landingPage,代码行数:25,代码来源:views.py

示例3: logged_in

def logged_in(request, username):
    user = get_object_or_404(User, username=username)

    if request.method == 'POST':
        form = MessageForm(request.POST)

        if form.is_valid():
            Message.objects.create(
                user=user,
                msg=form.cleaned_data['msg'],
            )
            return HttpResponseRedirect('?')
    else:
        form = MessageForm()

    # Use SQL to get the Message objects out via JOIN and DISTINCT
    msgs = Message.objects.filter(
        Q(user=user) | Q(user__following__dst=user)
    ).distinct()

    # Alternatively, use .as_model() to get the User objects out
    msgs = Tree('messages-for-%s' % user).values().as_model(Message)

    return render_to_response('logged_in.html', {
        'user': user,
        'form': form,
        'msgs': Paginator(msgs, 10).page(request.GET.get('page', 1)),
    }, context_instance=RequestContext(request))
开发者ID:lamby,项目名称:swordfish,代码行数:28,代码来源:views.py

示例4: moderation_object

def moderation_object(request, message_id):
    messages = []
    message = get_object_or_404(Message, id=message_id, point__isnull=False)
    if not message.point.location.admins.filter(id=request.user.id).count():
        return HttpResponseNotFound()
    form = None
    if request.method == "POST":
        if message.app.uid != 'webclient':
            mform = MessageForm(request.POST, instance=message)
        else:
            mform = None
        if message.point:
            form = BasePointForm(request.POST, instance=message.point, prefix="point")
    else:
        if message.app.uid != 'webclient':
            mform = MessageForm(instance=message)
        else:
            mform = None
        if message.point:
            form = BasePointForm(instance=message.point, prefix="point")
    if request.method == "POST":
        if all([mform is None or mform.is_valid(), form.is_valid()]):
            if mform is not None:
                mform.save()
            form.save()
            messages.append(u'Изменения успешно сохранены')
    return render_to_response('manager_moderation_obj.html',
                              {'obj': message,
                               'info': {'messages': messages},
                               'mform': mform,
                               'form': form
                               },                              
                              RequestContext(request))
开发者ID:AlexBarauskas,项目名称:rovar2,代码行数:33,代码来源:views.py

示例5: message

def message(request):
    if request.method == 'POST':
        form = MessageForm(request.POST)
        if form.is_valid():
            name    = form.cleaned_data['name']
            content = form.cleaned_data['content']
            ip      = request.META['REMOTE_ADDR']

            sess = request.session
            if not sess.has_key( 'name' ) or sess['name'] != name:
                sess['name'] = name

            if name.lower() == 'orange':
                name    = 'Wrong way'
                content = 'Try to pwn a shell instead of cracking md5.'
            elif md5.new(name).hexdigest() == 'e5bc16fcbca0f279df17b66d8c37e109':
                name = 'Orange'

            Messages( name=name,
                      content=content, 
                      ip=ip ).save()
            return HttpResponseRedirect( '/' )
    else:
        sess = request.session.load()
        if sess.has_key( 'name' ):
            default = sess['name']
        else:
            default = 'Guest'

        form = MessageForm( initial={'name': default} )

    messages = Messages.objects.order_by('id').reverse()[:100]
    response = render_to_response( 'message.html',
                                   {'form': form, 'messages': messages} )
    return response
开发者ID:orangetw,项目名称:Vulnerable-Django,代码行数:35,代码来源:views.py

示例6: home

def home():
    # return "Hello, World!"  # return a string
    error = None
    print current_user.id

    context =   { 'title': "Login Page",
                  'creator': "Sahai Srichock",
                }
    #print "hello home"
    form =  MessageForm(request.form)

    if form.validate_on_submit():
        new_message = BlogPost(
            form.title.data,
            form.description.data,
            current_user.id
            )
        db.session.add(new_message)
        db.session.commit()
        flash('New entry was successfully posted. Thank.')
        return redirect(url_for('homes.home'))
        #return render_template(
        #'index.html', posts=posts, error=error, form=form, context=context)
    else:
        posts = db.session.query(BlogPost).all()
        return render_template(
            'index.html', posts=posts, error=error, form=form, context=context)  # render a template
开发者ID:sznote,项目名称:flask,代码行数:27,代码来源:views.py

示例7: group_info

def group_info(request, group_id):
    if request.method == 'POST':
        form = MessageForm(request.POST)

        if form.is_valid():
            msg = form.cleaned_data['message']
            message = GroupMessage()
            message.group_id = group_id
            message.from_email = request.user.username
            message.message = msg
            message.save()

            # send signal
            grpmsg_added.send(sender=GroupMessage, group_id=group_id,
                              from_email=request.user.username)
            # Always return an HttpResponseRedirect after successfully dealing
            # with POST data.
            return HttpResponseRedirect(reverse('group_info', args=[group_id]))
    else:
        form = MessageForm()
        
        op = request.GET.get('op', '')
        if op == 'delete':
            return group_remove(request, group_id)
        elif op == 'dismiss':
            return group_dismiss(request, group_id)
        elif op == 'quit':
            return group_quit(request, group_id)

    return render_group_info(request, group_id, form)
开发者ID:chuyskywalker,项目名称:seahub,代码行数:30,代码来源:views.py

示例8: create_message

def create_message(request, recipient_id=None):
    """
    Create a new message
    """
    if request.method == 'POST':
        form = MessageForm(request.POST, request.FILES, user=request.user)

        if form.is_valid():
            message = form.save(commit=False)
            message.author = request.user
            message.sent_at = datetime.now()
            message.save()
            for ban in message.recipient.get_profile().is_banned():
                ban.end_time = datetime.now()
                ban.save()
            return redirect(reverse("private_messages_inbox"))
    else:
        if recipient_id:
            user = User.objects.get(pk=recipient_id)
            form = MessageForm(user=request.user, initial={'recipient': user})
        else:
            form = MessageForm(user=request.user)

    return render_to_response("private_messages/message_new.html",
                {"form": form}, context_instance=RequestContext(request))
开发者ID:frhumanes,项目名称:consulting,代码行数:25,代码来源:views.py

示例9: post

 def post(self):
     user_id = force_int(self.get_argument('user_id', 0), 0)
     sender = self.current_user
     receiver = User.get(id=user_id)
     if receiver:
         form = MessageForm(self.request.arguments)
         if form.validate():
             message = form.save(sender_id=sender.id,
                                 receiver_id=receiver.id)
             result = {
                 "status": "success",
                 "message": "私信发送成功",
                 "content": message.content,
                 "created": message.created,
                 "avatar": sender.get_avatar(size=48),
                 "url": sender.url,
                 "id": message.id,
             }
         else:
             result = {"status": "error", "message": "请填写至少 4 字的内容"}
         self.send_result(result)
         self.finish()
         return WebSocketHandler.send_message(message.receiver_id, message)
     result = {"status": "error", "message": "没有目标用户,不能发送私信哦"}
     self.send_result(result)
开发者ID:hallocrowc,项目名称:collipa,代码行数:25,代码来源:user.py

示例10: msq_query

def msq_query(request, id):
    c = {}
    group_info = get_group(request.session['token'], id)
    c['member_map'] = {member[u'user_id']: member[u'nickname'] for member in group_info[u'members']}
    form = MessageForm(request.GET, created=group_info['created_at'], members=c['member_map'])
    if form.is_valid():
        d = form.cleaned_data

        c['messages'] = Message.objects.filter(group=id, created__lte=d['end_date'],
                            created__gte=d['start_date'],
                            n_likes__gte=d['min_likes'],
                            n_likes__lte=d['max_likes'],
                            author__in=d['sent_by'],
                            text__icontains=d['text_contains'])
        if d['text_not_contain']:
            c['messages'] = c['messages'].exclude(text__icontains=d['text_not_contain'])
        if d['img']:
            c['messages'] = c['messages'].exclude(img__isnull=True)
        if d['random']:
            c['messages'] = list(c['messages'])
            random.shuffle(c['messages'])
            c['messages'] = c['messages'][:int(d['limit'])]
        else:
            sort = '-' + d['sort_by'] if d['sort_order'] else d['sort_by']
            sort = (sort, '-created') if d['sort_by'] == 'n_likes' else (sort, '-n_likes')
            c['messages'] = c['messages'].order_by(sort[0], sort[1])[:int(d['limit'])]
        return render(request, 'message_table.html', c)
    else:
        return HttpResponse("");
开发者ID:pmcgannon22,项目名称:gma-ui,代码行数:29,代码来源:views.py

示例11: reply

def reply(request, topic):
    if request.method == "POST":
        message_form = MessageForm(request.POST, instance=Message())
        topic = Topic.objects.get(slug=topic)
        if message_form.is_valid():
            message             = message_form.save(commit=False)
            message.category    = topic.forum.category
            message.topic       = topic
            message.forum       = topic.forum
            message.user        = request.user
            message.save()
            action.send(request.user, verb='replied to', target=message.topic)
            message.topic.responded_to = datetime.datetime.now()
            message.topic.save()

            Topic.objects.filter(id=topic.id).update(reply_count=F('reply_count')+1)
            return HttpResponseRedirect(reverse('djero.views.topic', kwargs={
                'category'  : topic.forum.category.slug, 
                'forum'     : topic.forum.slug, 
                'topic'     : topic.slug
            }))
        else:
            return HttpResponse("Invalid")
    else:
        message_form = MessageForm()
        topic = get_object_or_404(Topic, slug=topic)
        return render(request, "forum/reply.html", {
            "message_form"  : message_form,
            "topic"         : topic,
        })
开发者ID:bmelton,项目名称:brisk-django,代码行数:30,代码来源:views.py

示例12: post

 def post(self):
     user_id = force_int(self.get_argument('user_id', 0), 0)
     current_user = self.current_user
     user = User.get(id=user_id)
     if user:
         form = MessageForm(self.request.arguments)
         if form.validate():
             message_box1 = current_user.get_message_box(user=user)
             message_box2 = user.get_message_box(user=current_user)
             if not message_box1:
                 message_box1 = MessageBox(sender_id=current_user.id,
                         receiver_id=user.id, status=1).save()
             if not message_box2:
                 message_box2 = MessageBox(sender_id=user.id,
                         receiver_id=current_user.id).save()
             message = form.save(user_id=current_user.id,
                     message_box1_id=message_box1.id,
                     message_box2_id=message_box2.id)
             result = {"status": "success", "message": "私信发送成功",
                     "content": message.content, "created": message.created,
                     "avatar": current_user.get_avatar(size=48), "url":
                     current_user.url, "id": message.id}
         else:
             result = {"status": "error", "message": "请填写至少 4 字的内容"}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect_next_url()
     result = {"status": "error", "message": "没有目标用户,不能发送私信哦"}
     if self.is_ajax:
         return self.write(result)
     self.flash_message(result)
     return self.redirect_next_url()
开发者ID:laofo,项目名称:collipa,代码行数:33,代码来源:user.py

示例13: submit

def submit(request):
    """
    returns a message submission page
    processes a message submission
    """
	# Process message form if it has been submitted
    if request.method == 'POST':
        message_form = MessageForm(request.POST)
        recipient_form = RecipientForm(request.POST)
        attachment_form = AttachmentForm(request.POST, request.FILES)

		# Enter into database and email users if valid
        if (message_form.is_valid() and
            recipient_form.is_valid() and
            attachment_form.is_valid()):

            message = message_form.save()
            attachment_form.save(message)
            recipient_form.save(message)

            return render_to_response('thanks.html')

	# If message has not submitted, render message form
    else:
        message_form = MessageForm()
        recipient_form = RecipientForm()
        attachment_form = AttachmentForm()
    return render(request, "submit.html",
        {
           "formset": message_form,
           "recipients": recipient_form,
           "attachments": attachment_form
        })
开发者ID:djuta,项目名称:self-destructing-message,代码行数:33,代码来源:views.py

示例14: post

 def post(self):
     abort_if_not_an_admin()
     data = ImmutableMultiDict(request.json)
     message_form = MessageForm(data, csrf_enabled=False)
     if message_form.validate():
         message_form.save()
         return {"status": "success"}
     return message_form.errors
开发者ID:savad,项目名称:monitor,代码行数:8,代码来源:views.py

示例15: busi_cooper_page

def busi_cooper_page(request):
    if request.method == 'POST':
        msgform = MessageForm(request.POST);
        if msgform.is_valid(): 
            ctrls.saveMessageByForm(request,msgform);
            return HttpResponseRedirect("/busi_cooper/")
    else:
        return render_to_response('businesscooper.html',context_instance=RequestContext(request))
开发者ID:zhiaixuexi,项目名称:data_service_aggregation,代码行数:8,代码来源:views.py


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