Esempio n. 1
0
 def create(self):
     import time
     import datetime
     self.id = str(100000000000000000000 / time.time()).replace('.', '')
     self.eventDate = str(datetime.datetime.now())
     self.type = self.TYPE
     self.store(getDb())
Esempio n. 2
0
 def create(self):
   import time
   import datetime
   self.id=str(1/time.time())
   self.eventDate=str(datetime.datetime.now())
   self.type = self.TYPE
   self.store(getDb())
Esempio n. 3
0
 def create(self):
   import time
   import datetime
   self.id=str(100000000000000000000/time.time()).replace('.','')
   self.eventDate=str(datetime.datetime.now())
   self.type = self.TYPE
   self.store(getDb())
Esempio n. 4
0
 def create(self):
     #check for required fields
     if self.asker == None or self.title == None:
         raise Exception(
             'error in question creation: asker,title fields required')
         return
     self.store(getDb())
Esempio n. 5
0
 def create(self):
     import time
     import datetime
     self.id = str(1 / time.time())
     self.eventDate = str(datetime.datetime.now())
     self.type = self.TYPE
     self.store(getDb())
Esempio n. 6
0
 def update(self):
     '''
 update the question
 '''
     if self.id:
         self.store(getDb())
     else:
         print 'invalid state, attempting to update nonexisting question'
         raise IllegalAttempt
Esempio n. 7
0
 def update(self):
   '''
   update the question
   '''
   if self.id:
     self.store(getDb())
   else:
     print 'invalid state, attempting to update nonexisting question'
     raise IllegalAttempt
Esempio n. 8
0
 def findById(self) :
   '''
   return question that matches id
   '''
   view = dblayer.view("question/id", self.id)
   if len(view) == 0:
     return None
   elif len(view) == 1:
     for q in view : return Question.load(getDb(), q.id)
   else:
     print 'ERROR: more than one question for this ID'
     raise IntegrityConstraintException
Esempio n. 9
0
def viewQuestion(request):
    # obtain question by ID
    questionId = request.GET["questionId"]
    q = Question.load(getDb(), questionId)

    # unwrap answer dictionaries so that we can serialize into json
    answerList = []
    for answer in q.answers:
        answerList.append(answer.unwrap())

    response = json.dumps({"id": q.id, "title": q.title, "asker": q.asker, "views": q.views, "answers": answerList})
    return HttpResponse(response)
Esempio n. 10
0
 def findById(self):
     '''
 return question that matches id
 '''
     view = dblayer.view("question/id", self.id)
     if len(view) == 0:
         return None
     elif len(view) == 1:
         for q in view:
             return Question.load(getDb(), q.id)
     else:
         print 'ERROR: more than one question for this ID'
         raise IntegrityConstraintException
Esempio n. 11
0
def viewQuestion(request):
    #obtain question by ID
    questionId = request.GET["questionId"]
    q = Question.load(getDb(), questionId)

    #unwrap answer dictionaries so that we can serialize into json
    answerList = []
    for answer in q.answers:
        answerList.append(answer.unwrap())

    response = json.dumps({
        'id': q.id,
        'title': q.title,
        'asker': q.asker,
        'views': q.views,
        'answers': answerList,
    })
    return HttpResponse(response)
Esempio n. 12
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()
Esempio n. 13
0
def view(request):
    t = loader.get_template('index.html')
    context = RequestContext(request)
    context = checkSession(request, context)

    #topics cloud
    db = getDb()
    duplicatedTopics = db.view('topics/cloud')
    topics = []
    for row in duplicatedTopics:
        topic = row.key[1]
        if topics.__contains__(topic) == False:
            topics.append(topic)
    topics.reverse()  #order by views descending

    #only take top 30 topics
    context['topics'] = topics[:30]

    if request.GET.__contains__('search'):
        context['search'] = request.GET['search']

    return HttpResponse(t.render(context))
Esempio n. 14
0
def view(request):
    t = loader.get_template("index.html")
    context = RequestContext(request)
    context = checkSession(request, context)

    # topics cloud
    db = getDb()
    duplicatedTopics = db.view("topics/cloud")
    topics = []
    for row in duplicatedTopics:
        topic = row.key[1]
        if topics.__contains__(topic) == False:
            topics.append(topic)
    topics.reverse()  # order by views descending

    # only take top 30 topics
    context["topics"] = topics[:30]

    if request.GET.__contains__("search"):
        context["search"] = request.GET["search"]

    return HttpResponse(t.render(context))
Esempio n. 15
0
 def findById(self):
   return Rating.load(getDb(), self.id)
Esempio n. 16
0
def removeAllFromView(view):
  db = getDb()
  v = db.view(view)
  for row in v:
    db.delete( db[row.id] )
    print 'deleted id: ' + row.id + ' in view: ' + view
Esempio n. 17
0
 def findById(self):
     return Rating.load(getDb(), self.id)
Esempio n. 18
0
 def create(self):
     self.type = self.TYPE
     self.store(getDb())
Esempio n. 19
0
 def create(self) :
   #check for required fields
   if self.asker == None or self.title == None:
     raise Exception('error in question creation: asker,title fields required')
     return
   self.store( getDb() )
Esempio n. 20
0
 def create(self):
   self.type = self.TYPE
   self.store(getDb())