Exemple #1
0
def newTopic(request,fid):
  form   = Form()
  fields = request.getForm()
  user   = users.get_current_user()
  uid    = user.user_id()

  # sanitize
  title  = utils.toStr(fields.get('title',''),80)
  imp    = utils.toInt(fields.get('importance','0'))
  author = utils.toStr(fields.get('author',''),40)
  email  = fields.get('email')
  url    = fields.get('url')
  content= utils.toTxt(fields.get('content',''),9000)

  # validate
  ok=True
  warn=[]
  if email or url:
    form.ok=False
    form.redirect=True
    form.url='%s/%s'%(app.root,fid)
    return form
  if not title:
    warn.append('Title can not be empty')
    ok=False
  if title==title.upper():
    warn.append('Title can not be all caps')
    ok=False
  if not author:
    warn.append('You need to identify as the author')
    ok=False
  if author==author.upper():
    warn.append('Author can not be all caps')
    ok=False
  if not content:
    warn.append('You must enter some content')
    ok=False
  if content==content.upper():
    warn.append('Content can not be all caps')
    ok=False
  if ok:
    dat1 = {'forumid':fid,'title':title,'userid':str(uid),'author':author,'importance':imp}
    rec1 = models.newTopic(dat1)
    tid  = rec1.topicid
    dat2 = {'topicid':tid,'forumid':fid,'userid':str(uid),'author':author,'content':content}
    rec2 = models.newMessage(dat2)
    form.ok  = True
    form.url = '%s/%s/%s'%(app.root,fid,tid)
  else:
    form.ok   = False
    form.warn = warn
    form.data = {
      'forum'  :models.getForum(fid),
      'warn'   :warn,
      'title'  :title,
      'author' :author,
      'content':content
    }
  return form
Exemple #2
0
def messages(request, fid, tid):
    form = Form()
    fields = request.getForm()
    user = users.get_current_user()
    uid = user.user_id()

    # sanitize
    author = utils.toStr(fields.get('author', 'Anonymous'), 40)
    email = fields.get('email')
    url = fields.get('url')
    content = utils.toTxt(fields.get('content', ''), 9000)

    # validate
    ok = True
    warn = []
    if email or url or 'http' in content:
        form.ok = False
        form.redirect = True
        form.url = '%s/%s/%s' % (app.root, fid, tid)
        return form
    if not author:
        warn.append('You need to identify yourself as the author')
        ok = False
    if author == author.upper():
        warn.append('Author can not be all caps')
        ok = False
    if not content:
        warn.append('You must enter some content')
        ok = False
    if content == content.upper():
        warn.append('Content can not be all caps')
        ok = False

    # process
    if ok:
        form.ok = True
        form.url = '%s/%s/%s' % (app.root, fid, tid)
        data = {
            'topicid': tid,
            'forumid': fid,
            'userid': str(uid),
            'author': author,
            'content': content
        }
        models.newMessage(data)
    else:
        form.ok = False
        form.warn = warn
        form.data = {
            'forum': models.getForum(fid),
            'topic': models.getTopic(tid),
            'list': models.getMessages(tid),
            'warn': warn,
            'author': author,
            'content': content
        }
    return form
Exemple #3
0
def messages(request,fid,tid):
  form   = Form()
  fields = request.getForm()
  user   = users.get_current_user()
  uid    = user.user_id()

  # sanitize
  author = utils.toStr(fields.get('author','Anonymous'),40)
  email  = fields.get('email')
  url    = fields.get('url')
  content= utils.toTxt(fields.get('content',''),9000)

  # validate
  ok=True
  warn=[]
  if email or url or 'http' in content:
    form.ok=False
    form.redirect=True
    form.url='%s/%s/%s'%(app.root,fid,tid)
    return form
  if not author:
    warn.append('You need to identify yourself as the author')
    ok=False
  if author==author.upper():
    warn.append('Author can not be all caps')
    ok=False
  if not content:
    warn.append('You must enter some content')
    ok=False
  if content==content.upper():
    warn.append('Content can not be all caps')
    ok=False

  # process
  if ok:
    form.ok   = True
    form.url  = '%s/%s/%s'%(app.root,fid,tid)
    data      = {'topicid':tid,'forumid':fid,'userid':str(uid),'author':author,'content':content}
    models.newMessage(data)
  else:
    form.ok   = False
    form.warn = warn
    form.data = {
      'forum'  :models.getForum(fid),
      'topic'  :models.getTopic(tid),
      'list'   :models.getMessages(tid),
      'warn'   :warn,
      'author' :author,
      'content':content
    }
  return form
Exemple #4
0
def newTopic(request, fid):
    form = Form()
    fields = request.getForm()
    user = users.get_current_user()
    uid = user.user_id()

    # sanitize
    title = utils.toStr(fields.get('title', ''), 80)
    imp = utils.toInt(fields.get('importance', '0'))
    author = utils.toStr(fields.get('author', ''), 40)
    email = fields.get('email')
    url = fields.get('url')
    content = utils.toTxt(fields.get('content', ''), 9000)

    # validate
    ok = True
    warn = []
    if email or url:
        form.ok = False
        form.redirect = True
        form.url = '%s/%s' % (app.root, fid)
        return form
    if not title:
        warn.append('Title can not be empty')
        ok = False
    if title == title.upper():
        warn.append('Title can not be all caps')
        ok = False
    if not author:
        warn.append('You need to identify as the author')
        ok = False
    if author == author.upper():
        warn.append('Author can not be all caps')
        ok = False
    if not content:
        warn.append('You must enter some content')
        ok = False
    if content == content.upper():
        warn.append('Content can not be all caps')
        ok = False
    if ok:
        dat1 = {
            'forumid': fid,
            'title': title,
            'userid': str(uid),
            'author': author,
            'importance': imp
        }
        rec1 = models.newTopic(dat1)
        tid = rec1.topicid
        dat2 = {
            'topicid': tid,
            'forumid': fid,
            'userid': str(uid),
            'author': author,
            'content': content
        }
        rec2 = models.newMessage(dat2)
        form.ok = True
        form.url = '%s/%s/%s' % (app.root, fid, tid)
    else:
        form.ok = False
        form.warn = warn
        form.data = {
            'forum': models.getForum(fid),
            'warn': warn,
            'title': title,
            'author': author,
            'content': content
        }
    return form