本文整理汇总了Python中forms.MessageForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python MessageForm.is_valid方法的具体用法?Python MessageForm.is_valid怎么用?Python MessageForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.MessageForm
的用法示例。
在下文中一共展示了MessageForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_message
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
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))
示例2: submit
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
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
})
示例3: moderation_object
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
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))
示例4: reply
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
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,
})
示例5: view_message
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
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/")
示例6: group_info
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
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)
示例7: message
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
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
示例8: msq_query
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
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("");
示例9: logged_in
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
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))
示例10: message_create
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
def message_create(request):
if request.method == "POST":
form = MessageForm(request.POST)
if form.is_valid():
# TODO: content_object
msg = Message(msg=form.cleaned_data["msg"], user=request.user)
msg.save()
return HttpResponseRedirect("/")
示例11: busi_cooper_page
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
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))
示例12: messaging_compose
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
def messaging_compose(request, response_format='html'):
"New message page"
user = request.user.profile
if request.POST:
if 'cancel' not in request.POST:
message = Message()
message.author = user.get_contact()
if not message.author:
return user_denied(request,
message="You can't send message without a Contact Card assigned to you.",
response_format=response_format)
form = MessageForm(
request.user.profile, None, None, request.POST, instance=message)
if form.is_valid():
message = form.save()
message.recipients.add(user.get_contact())
message.set_user_from_request(request)
message.read_by.add(user)
try:
# if email entered create contact and add to recipients
if 'multicomplete_recipients' in request.POST and request.POST['multicomplete_recipients']:
try:
conf = ModuleSetting.get_for_module(
'anaf.messaging', 'default_contact_type')[0]
default_contact_type = ContactType.objects.get(
pk=long(conf.value))
except Exception:
default_contact_type = None
emails = request.POST[
'multicomplete_recipients'].split(',')
for email in emails:
emailstr = unicode(email).strip()
if re.match('[a-zA-Z0-9+_\-\.][email protected][0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+', emailstr):
contact, created = Contact.get_or_create_by_email(
emailstr, contact_type=default_contact_type)
message.recipients.add(contact)
if created:
contact.set_user_from_request(request)
except:
pass
# send email to all recipients
message.send_email()
return HttpResponseRedirect(reverse('messaging'))
else:
return HttpResponseRedirect(reverse('messaging'))
else:
form = MessageForm(request.user.profile, None)
context = _get_default_context(request)
context.update({'form': form})
return render_to_response('messaging/message_compose', context,
context_instance=RequestContext(request), response_format=response_format)
示例13: message_create
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
def message_create(request):
if request.method == "POST" and request.is_ajax():
form = MessageForm(request.POST)
if form.is_valid():
msg = Message(msg=form.cleaned_data["msg"], user=request.user)
msg.save()
return render(request, "social/message_form_popup_response.html",
{'response': _("Your message has been successfully posted"),
'object': msg,
})
else:
return HttpResponse("sonaste")
elif request.method == "POST":
form = MessageForm(request.POST)
if form.is_valid():
msg = Message(msg=form.cleaned_data["msg"], user=request.user)
msg.save()
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
示例14: message
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
def message(request, event_id, type):
event = get_object_or_404(Event, id=event_id)
form = MessageForm(user=request.user, event=event, type=type, data=(request.POST or None),
initial={"guests": request.GET.get("guests", "").split(",")})
if form.is_valid():
form.save()
messages.success(request, "Your message has been sent.")
return redirect(event)
template = "events/message.html"
return render_to_response(template, locals(), context_instance=RequestContext(request))
示例15: send
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import is_valid [as 别名]
def send(request):
if request.method == 'POST':
form = MessageForm(request.POST)
if form.is_valid():
send_message(from_user=request.user, form=form)
return redirect('/message/sended')
else:
form = MessageForm()
return render_to_response('message/send.html', {'form': form},
context_instance=RequestContext(request))