@login_required
@mobile_template('messages/{mobile/}new.html')
def new_message(request, template):
 to = request.GET.get('to')
 if to:
  try:
   for username in to.split(','):
    User.objects.get(username=username)
  except User.DoesNotExist:
   contrib_messages.add_message(request, contrib_messages.ERROR, _('Invalid username provided. Enter a new username below.'))
   return HttpResponseRedirect(reverse('messages.new'))
 message = request.GET.get('message')
 form = MessageForm((request.POST or None), initial={'to': to, 'message': message})
 if ((request.method == 'POST') and form.is_valid() and (not is_ratelimited(request, 'primate-message-day', '50/d'))):
  send_message(form.cleaned_data['to'], form.cleaned_data['message'], request.user)
  if form.cleaned_data['in_reply_to']:
   irt = form.cleaned_data['in_reply_to']
   try:
    m = InboxMessage.objects.get(pk=irt, to=request.user)
    m.update(replied=True)
   except InboxMessage.DoesNotExist:
    pass
  contrib_messages.add_message(request, contrib_messages.SUCCESS, _('Your message was sent!'))
  return HttpResponseRedirect(reverse('messages.inbox'))
 return render(request, template, {'form': form})

@ login_required @ mobile_template ( 'messages/{mobile/}new.html' ) def new_message ( request , template ) : to = request . GET . get ( 'to' ) if to : try : for username in to . split ( ',' ) : User . objects . get ( username = username ) except User . DoesNotExist : contrib_messages . add_message ( request , contrib_messages . ERROR , _ ( 'Invalid username provided. Enter a new username below.' ) ) return HttpResponseRedirect ( reverse ( 'messages.new' ) ) message = request . GET . get ( 'message' ) form = MessageForm ( ( request . POST or None ) , initial = { 'to' : to , 'message' : message } ) if ( ( request . method == 'POST' ) and form . is_valid ( ) and ( not is_ratelimited ( request , 'primate-message-day' , '50/d' ) ) ) : send_message ( form . cleaned_data [ 'to' ] , form . cleaned_data [ 'message' ] , request . user ) if form . cleaned_data [ 'in_reply_to' ] : irt = form . cleaned_data [ 'in_reply_to' ] try : m = InboxMessage . objects . get ( pk = irt , to = request . user ) m . update ( replied = True ) except InboxMessage . DoesNotExist : pass contrib_messages . add_message ( request , contrib_messages . SUCCESS , _ ( 'Your message was sent!' ) ) return HttpResponseRedirect ( reverse ( 'messages.inbox' ) ) return render ( request , template , { 'form' : form } )
creates an email with a random subject .