本文整理汇总了Python中forms.MessageForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python MessageForm.save方法的具体用法?Python MessageForm.save怎么用?Python MessageForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.MessageForm
的用法示例。
在下文中一共展示了MessageForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: view_message
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [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/")
示例2: moderation_object
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [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))
示例3: post
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [as 别名]
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
示例4: message
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [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))
示例5: add_message
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [as 别名]
def add_message(request):
if request.method == "POST":
message_form = MessageForm(request.POST or None)
if message_form.is_valid():
message_form.save()
return HttpResponseRedirect(request.session.get('real_url'))
else:
message_form = MessageForm()
context = {
"message_form": message_form,
}
return render(request, 'add_message.html', context)
示例6: create
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [as 别名]
def create(request):
if request.POST:
form = MessageForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/messages/all')
else:
form = MessageForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('create_message.html', args)
示例7: create_message
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [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))
示例8: reply
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [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,
})
示例9: submit
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [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
})
示例10: post
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [as 别名]
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)
示例11: post
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [as 别名]
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()
示例12: messaging_compose
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [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: sendmessage
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [as 别名]
def sendmessage(request):
basic = get_basic(request)
message_sent = False
try:
user = User.objects.get(id=request.GET['id'])
except User.DoesNotExist:
return HttpResponseRedirect('/messages')
if request.method == 'POST':
form = MessageForm(request.POST)
if form.is_valid():
obj = form.save(commit=False)
obj.from_user = request.user
obj.to_user = user
obj.save()
try:
to_prof = Profile.objects.get(user=user)
except Profile.DoesNotExist:
to_prof = Profile()
if to_prof.message_email:
try:
from_prof = Profile.objects.get(user=request.user)
except Profile.DoesNotExist:
from_prof = Profile()
if from_prof.first_name:
from_name = from_prof.first_name
if from_prof.last_name:
from_name = " ".join([from_name, from_prof.last_name])
else:
from_name = request.user.username
if to_prof.first_name:
to_name = to_prof.first_name
else:
to_name = user.username
title = "CreationDex - New Message from " + from_name
msg_url = "https://creationdex.com/viewmessage?id=" + str(obj.id)
from_url = "https://creationdex.com/profile?id=" + str(request.user.id)
options_url = "https://creationdex.com/accounts/options/"
plain_content = ("Hello, " + to_name + ".\n\n" + from_name +
" has sent you a new message. Go to " + msg_url + " to read it" +
" at creationdex.com, or go to " + options_url + " to change" +
" your email options.\n\n Preview: \"" + obj.content + "\"")
html_content = ("<p>Hello, " + to_name + ".</p><p><a href=\"" +
from_url + "\">" + from_name + "</a>" +
" has sent you a new message. Click <a href=\"" + msg_url +
"\">here</a>" + " to read it at creationdex.com, or click" +
" <a href=\"" + options_url + "\">here</a> to change your" +
" email options.</p>" +
"<p>Preview: \"" + obj.content + "\"</p>")
send_mail(title, plain_content, settings.EMAIL_HOST_USER, [user.email],
fail_silently=True, html_message=html_content)
return HttpResponseRedirect('/messages/')
else:
form = MessageForm()
return render(request, 'sendmessage.html', {'form': form, 'basic': basic,
'user': user })
示例14: contact_form_process
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [as 别名]
def contact_form_process(request):
contact_form_done = False
message_form = MessageForm(request.POST or None, prefix="message")
if message_form.is_valid():
obj = message_form.save()
d = {"text": obj.text, "name": obj.name, "phone": obj.phone, "email": obj.email, "subject": obj.subject, }
Email.objects.get(id_name="message").send(settings.NOTIFY_MAIL, d, obj.email)
contact_form_done = True
message_form = None
# return HttpResponseRedirect("/")
return contact_form_done, message_form
示例15: create_pm
# 需要导入模块: from forms import MessageForm [as 别名]
# 或者: from forms.MessageForm import save [as 别名]
def create_pm(request, id):
from forms import MessageForm
model = get_model('net', 'User')
data = {
'content_type': ContentType.objects.get_for_model(model).pk,
'object_id': id,
'parent': request.GET.get('parent'),
'private': request.GET.get('private'),
}
if request.POST:
form = MessageForm(data=request.POST, initials=data)
if form.is_valid():
form.save(request.user.user)
return HttpResponseRedirect(reverse('user_profile', args=[id]))
else:
form = MessageForm(initials=data)
return {
'form': form,
'object_id': id,
}