Exemplo n.º 1
0
def post(request) :
  #get current user
  context = checkSession(request)
  user = getCurrentUser(context)

  #get question data
  questionTitle = smart_unicode(request.POST["title"], encoding='utf-8', strings_only=False, errors='strict')
  questionDescription = smart_unicode(request.POST["description"], encoding='utf-8', strings_only=False, errors='strict')

  if not user:
    message = 'you must be logged in first!'
  elif questionTitle == "":
    message = 'a question needs words!'
  else:
    #create question
    q = Question(asker=user.login, title=questionTitle, description=questionDescription)
    if request.POST.__contains__("tags") :
      tags=smart_unicode(request.POST["tags"], encoding='utf-8', strings_only=False, errors='strict')
      topics=tags.split(',')
      q.topics=topics
    print q
    try :
      q.create()
      q=q.findById()
      user=user.findByLogin()
      user.followedQuestions.append(q.id);
      user.update()
      message = 'question successfully posted'
    except Exception as e:
      message = e
  #remove the displayed question 
  response = HttpResponse();
  response["message"] = message;
  response["questionId"] = q.id;
  return response;
Exemplo n.º 2
0
def post(request):
    # get current user
    context = checkSession(request)
    user = getCurrentUser(context)

    # get question data
    questionTitle = smart_unicode(request.POST["title"], encoding="utf-8", strings_only=False, errors="strict")
    questionDescription = smart_unicode(
        request.POST["description"], encoding="utf-8", strings_only=False, errors="strict"
    )

    if not user:
        message = "you must be logged in first!"
    elif questionTitle == "":
        message = "a question needs words!"
    else:
        # create question
        q = Question(asker=user.login, title=questionTitle, description=questionDescription)
        if request.POST.__contains__("tags"):
            tags = smart_unicode(request.POST["tags"], encoding="utf-8", strings_only=False, errors="strict")
            topics = tags.split(",")
            q.topics = topics
        try:
            q.create()
        except Exception as e:
            message = e
        else:
            message = "question successfully posted"

    response = HttpResponse()
    response["message"] = message
    return response
Exemplo n.º 3
0
def createQuestion(title):
  #get a random user as the asker
  userlist = getDb().view('user/login')
  randomAsker = random.choice( userlist.rows ).value['login']

  #add topics
  topics = title.replace('?','').lower().split(' ')
  #remove prepositions
  f = open('prepositions')
  prepositions = f.read().splitlines()
  f.close()

  for preposition in prepositions:
    topics = [e for e in topics if e != preposition]
  nontopics = [
    'some',
    'is',
    'the',
    'what',
    'when',
    'why',
    'how',
    'who',
    'where',
    'a',
    'this',
    'that',
    'are',
    'i',
    'you',
    'can',
    'do'
  ]
  for word in nontopics:
    topics = [e for e in topics if e != word]
  
  #convert title to unicode
  title = smart_unicode(title, encoding='utf-8', strings_only=False, errors='strict')

  #create question
  q = Question(asker=randomAsker, title=title, topics=topics)
  print '********** creating question ***********\n' + 'title: ' + title + '\nasker: ' + randomAsker + '\ntopics: ' + str(topics)
  q.create()
  q.update()
Exemplo n.º 4
0
def post(request):
    #get current user
    context = checkSession(request)
    user = getCurrentUser(context)

    #get question data
    questionTitle = smart_unicode(request.POST["title"],
                                  encoding='utf-8',
                                  strings_only=False,
                                  errors='strict')
    questionDescription = smart_unicode(request.POST["description"],
                                        encoding='utf-8',
                                        strings_only=False,
                                        errors='strict')

    if not user:
        message = 'you must be logged in first!'
    elif questionTitle == "":
        message = 'a question needs words!'
    else:
        #create question
        q = Question(asker=user.login,
                     title=questionTitle,
                     description=questionDescription)
        if request.POST.__contains__("tags"):
            tags = smart_unicode(request.POST["tags"],
                                 encoding='utf-8',
                                 strings_only=False,
                                 errors='strict')
            topics = tags.split(',')
            q.topics = topics
        try:
            q.create()
        except Exception as e:
            message = e
        else:
            message = 'question successfully posted'

    response = HttpResponse()
    response["message"] = message
    return response