Exemplo n.º 1
0
def process_request(request):
    # check user permissions and prepare the params
    params = prepare_params(request)

    # handle the form
    form = ThreadForm(request)
    if request.method == 'POST':
        form = ThreadForm(request, request.POST, request.FILES)
        if form.is_valid():
            files = []
            thread, comment = create_thread(request.user,
                                            form.cleaned_data['topic'],
                                            form.cleaned_data['title'],
                                            form.cleaned_data['comment'])
            if form.cleaned_data['file1']:
                cf = hmod.UploadedFile()
                cf.filename = form.cleaned_data['file1'].name
                cf.contenttype = form.cleaned_data['file1'].content_type
                cf.size = form.cleaned_data['file1'].size
                cf.filebytes = form.cleaned_data['file1'].read()
                cf.save()
                comment.files.add(cf)
            send_comment_email_immediate(request, comment)
            return HttpResponseRedirect('/forum/thread/%s/' % thread.pk)

    # render the template
    params['form'] = form
    params['starters'] = [(topic.id, encode64(topic.starter))
                          for topic in fmod.Topic.objects.all()]
    return templater.render_to_response(request, 'newthread.html', params)
Exemplo n.º 2
0
def process_request(request):
  # check user permissions and prepare the params
  params = prepare_params(request)
  
  # handle the form
  form = ThreadForm(request)
  if request.method == 'POST':
    form = ThreadForm(request, request.POST, request.FILES)
    if form.is_valid():
      files = []
      thread, comment = create_thread(request.user, form.cleaned_data['topic'], form.cleaned_data['title'], form.cleaned_data['comment'])
      if form.cleaned_data['file1']:
        cf = hmod.UploadedFile()
        cf.filename = form.cleaned_data['file1'].name
        cf.contenttype = form.cleaned_data['file1'].content_type
        cf.size = form.cleaned_data['file1'].size
        cf.filebytes = form.cleaned_data['file1'].read()
        cf.save()
        comment.files.add(cf)
      send_comment_email_immediate(request, comment)
      return HttpResponseRedirect('/forum/thread/%s/' % thread.pk)

  # render the template
  params['form'] = form
  params['starters'] = [ (topic.id, encode64(topic.starter)) for topic in fmod.Topic.objects.all() ]
  return templater.render_to_response(request, 'newthread.html', params)
  # add any attachments
  for cid, filename, contenttype, filebytes in attachments:
    cf = hmod.UploadedFile()
    cf.filename = filename
    cf.contenttype = contenttype
    cf.size = len(filebytes)
    cf.filebytes = filebytes
    cf.save()
    comment.files.add(cf)
    
  # prepare some fake meta
  meta = {
   'HTTP_HOST': 'island.byu.edu',
   'QUERY_STRING': '',
   'REMOTE_ADDR': '127.0.0.1',
   'REMOTE_PORT': '0',
   'REQUEST_METHOD': 'GET',
  }
    
  # send the emails
  log.warning('Sending email for comment: %s > %s' % (comment.id, comment.comment))
  send_comment_email_immediate(meta, comment)
  
  # signal to exim that we have success
  sys.exit(0)

except Exception as exc:
  exc_info = (type(exc), exc, exc.__traceback__)
  log.warning('Error: %s' % exc, exc_info=exc_info)
  print(str(exc))  # exim accepts this as the error to send back to the user
  sys.exit(1)
    for cid, filename, contenttype, filebytes in attachments:
        cf = hmod.UploadedFile()
        cf.filename = filename
        cf.contenttype = contenttype
        cf.size = len(filebytes)
        cf.filebytes = filebytes
        cf.save()
        comment.files.add(cf)

    # prepare some fake meta
    meta = {
        'HTTP_HOST': 'island.byu.edu',
        'QUERY_STRING': '',
        'REMOTE_ADDR': '127.0.0.1',
        'REMOTE_PORT': '0',
        'REQUEST_METHOD': 'GET',
    }

    # send the emails
    log.warning('Sending email for comment: %s > %s' %
                (comment.id, comment.comment))
    send_comment_email_immediate(meta, comment)

    # signal to exim that we have success
    sys.exit(0)

except Exception as exc:
    exc_info = (type(exc), exc, exc.__traceback__)
    log.warning('Error: %s' % exc, exc_info=exc_info)
    print(str(exc))  # exim accepts this as the error to send back to the user
    sys.exit(1)