Beispiel #1
0
 def post(self, topic_id):#done
     if self.request.body:
         linkDict = simplejson.loads(self.request.body)
         try:
             topic = DaoImpl.getTopic(topic_id)
             if not topic:
                 raise TopicNotFoundException
             link = DaoImpl.createLinkFromDict(linkDict, topic)
             DaoImpl.addLinkToTopic(topic, link)
             self.set_status(200)
             self.write(simplejson.dumps(Util.linkToDict(link)))
         except Exception, e:
             self.set_status(400)
             self.write(error(e.__str__()))
Beispiel #2
0
 def get(self, topic_id): #done
     try:
         links = DaoImpl.getLinks(topic_id)
         linksDict = [Util.linkToDict(link) for link in links]
         self.set_status(200)
         self.write(simplejson.dumps(linksDict))
     except TopicNotFoundException, e:
         self.set_status(404)
         self.write(error(e.__str__())) #figure how to write exception text.
Beispiel #3
0
 def get(self): #done
     topics = DaoImpl.getTopics()
     topicsDict = []
     for topic in topics:
         topicDict = Util.topicToDict(topic)
         if topicDict:
             topicsDict.append(topicDict)
     self.set_status(200)
     self.write(simplejson.dumps(topicsDict))
     self.set_header("Content-Type", "application/json")
Beispiel #4
0
 def put(self, topic_id):
     if self.request.body:
         topicDict = simplejson.loads(self.request.body)
         try:
             topic = DaoImpl.updateTopic(topic_id, topicDict)
             self.set_status(200)
             self.write(simplejson.dumps(Util.topicToDict(topic)))
         except Exception, e:
             self.set_status(400)
             self.write(error(e.__str__()))
Beispiel #5
0
 def put(self, link_id): #vote up/down information will be stored in the TopicLink table.
     if self.request.body:
         linkDict = simplejson.loads(self.request.body)
         try:
             link = DaoImpl.updateLink(link_id, linkDict, None)
             self.set_status(200)
             self.write(simplejson.dumps(Util.linkToDict(link)))
         except Exception, e:
             self.set_status(400)
             self.write(error(e.__str__()))
Beispiel #6
0
 def get(self, topic_id, link_id):
     link = DaoImpl.getLink(link_id)
     if link:
         linkDict = Util.linkToDict(link)
         self.set_status(200)
         self.write(simplejson.dumps(linkDict))
     else:
         self.set_status(404)
         self.write(error('Link not found.'))
     self.set_header("Content-Type", "application/json")
Beispiel #7
0
    def get(self, topic_id): #done
        topic = DaoImpl.getTopic(topic_id)

        if topic:
            topicDict = Util.topicToDict(topic)
            self.set_status(200)
            self.write(simplejson.dumps(topicDict))
        else:
            self.set_status(404)
            self.write(error('Topic not found.'))

        self.set_header("Content-Type", "application/json")
Beispiel #8
0
class Service:
    dao_impl = DaoImpl()
    word_book_name_set = ['CET4', 'CET6', 'TOEFL', 'GRE', 'CET4', 'CET6', 'TOEFL', 'GRE', 'CET4', 'CET6', 'TOEFL',
                          'GRE', 'CET4', 'CET6', 'TOEFL', 'GRE', 'CET4', 'CET6', 'TOEFL', 'GRE']

    def is_useremail_exist(self, useremail):
        user = self.dao_impl.select_one_from_email(useremail)
        if user is None:
            return False
        return True

    def register(self, useremail, password, name):
        is_register_success = False
        user = User(userEmail=useremail, password=password, userName=name)
        # check if the user email is duplicated 
        if self.is_useremail_exist(useremail) is True:
            return is_register_success  # False
        if self.dao_impl.insert_user(user) is True:
            is_register_success = True
        return is_register_success

    def can_login(self, userEmail, password):
        user = None
        is_valid = False
        user = self.dao_impl.select_one_from_email(userEmail)
        if user is None:
            is_valid = False
            return is_valid, None
        elif password != (user.getPassword()):
            is_valid = False
            return is_valid, None
        else:
            is_valid = True

        return is_valid, user.getUsername()

    def get_words(self, number_of_words, wordlist_id, pick_style, from_word=""):
        words_array = []
        # id:1=CET4,2=CET6, 3=TOEFL, 4= GRE, 5=CET4,6=CET6,7=TOEFL,8=GRE
        book_name = self.word_book_name_set[int(wordlist_id)]
        words_array = self.dao_impl.select_words(number_of_words, book_name, pick_style, from_word)
        return words_array
Beispiel #9
0
 def testCreateTopic(self):
     """simple create. without links.
     """
     topicDict = {'title': 'topTit', 'speaker': 'topSpeak', 'author': 'topAuth'}
     topic = DaoImpl.createTopic(topicDict)
     self.assertEqual(topic.title, 'topTit2')
Beispiel #10
0
 def testCreateLinkFromUrl(self):
     link = DaoImpl.createLinkFromUrl("http://www.yahoo.com")
Beispiel #11
0
 def get(self, topic_id):
     topic = DaoImpl.getTopic(topic_id)
     topicDict = Util.topicToDict(topic)
     self.render("template.html", topic=topicDict)