Ejemplo n.º 1
0
 def dashboard(self):
     articles = self.model.fetchall('articles')
     if articles[0]:
         args = {'articles': articles[1]}
         route = Route(False, 'dashboard.html', args)
         return PresentView(route)
     else:
         args = {'msg': 'No article found'}
         route = Route(False, 'dashboard.html', args)
         return PresentView(route)
 def course(self):
     courses = self.model.fetchall(self.model)
     if courses[0]:
         args = {'courses': courses}
         route = Route(False, 'course.html', args)
         return PresentView(route)
     else:
         msg = 'No Course Found'
         args = {'msg': msg}
         route = Route(False, 'course.html', args)
         return PresentView(route)
Ejemplo n.º 3
0
 def articles(self):
     articles = self.model.fetchall('articles')
     if articles[0]:
         args = {'articles': articles[1]}
         route = Route(False, 'articles.html', args)
         return PresentView(route)
     else:
         msg = 'No article found'
         args = {'msg': msg}
         route = Route(False, 'articles.html', args)
         return PresentView(route)
    def course_2(self):
        '''courses = self.model.fetchall(self.model)'''
        courses_2 = self.trans_model.fetchall()

        if courses_2[0]:
            args = {'courses': courses_2[4:]}
            route = Route(False, 'course_2.html', args)
            return PresentView(route)
        else:
            msg = 'No Course Found'
            args = {'msg': msg}
            route = Route(False, 'course_2.html', args)
            return PresentView(route)
Ejemplo n.º 5
0
    def add_article(self, can_add_art, form):
        if can_add_art:
            title = form.title.data
            body = form.body.data
            link = form.link.data

            self.model.add_art((title, body, session['username'], link))
            flash = Flash('Article created', MSG_TYPE.SUCCESS)
            route = Route(True, 'dashboard')
            return PresentView(route, flash)
        args = {'form': form}
        route = Route(False, 'add_article.html', args)
        return PresentView(route)
Ejemplo n.º 6
0
    def edit_article(self, id, can_edit, form):

        article = self.model.art('articles', id)
        form.title.data = article['title']
        form.body.data = article['body']

        if can_edit:
            title = request.form['title']
            body = request.form['body']

            self.model.update_art((title, body, id))
            flash = Flash('Article Updated', MSG_TYPE.SUCCESS)
            route = Route(True, 'dashboard')
            return PresentView(route, flash)
        args = {'form': form}
        route = Route(False, 'edit_article.html', args)
        return PresentView(route)
Ejemplo n.º 7
0
    def add_course(self, can_add, form):
        if can_add:
            course_name = form.course_name.data
            term = form.term.data
            time = form.time.data
            instructor = form.instructor.data
            rating = form.rating.data
            difficulty = form.difficulty.data
            review = form.review.data

            params = (course_name, term, time, instructor, rating, difficulty,
                      review)
            self.model.insert_course(params)
            flash = Flash('Course created', MSG_TYPE.SUCCESS)
            route = Route(True, 'course')
            return PresentView(route, flash)
        args = {'form': form}
        route = Route(False, 'add_course.html', args)
        return PresentView(route)
Ejemplo n.º 8
0
 def register(self, can_register, form):
     if can_register:
         name = form.name.data
         email = form.email.data
         username = form.username.data
         password = sha256_crypt.encrypt(str(form.password.data))
         if self.model.user_existed(name):
             route = Route(True, 'register')
             flash = Flash('Username {0} already existed.'.format(username),
                           MSG_TYPE.FAIL)
             return PresentView(route, flash)
         else:
             self.model.register_user((name, email, username, password))
             route = Route(True, 'login')
             flash = Flash('You have registered.', MSG_TYPE.SUCCESS)
             return PresentView(route, flash)
     args = {'form': form}
     route = Route(False, 'register.html', args)
     return PresentView(route)
Ejemplo n.º 9
0
    def analyze(self, data):
        # Ask model for a description of the image
        photo = data.files['file']
        if photo.filename != '':
            filename = str(uuid.uuid4()) + '-' + photo.filename
            path = Path.cwd() / 'static' / filename
            image = filename
            path.touch()
            path.write_bytes(photo.read())
            photo.seek(0)
            labels = self.model.labelImage(photo)
            label = labels[0].description
            photo.seek(0)
        else:
            label = None
            image = None
        # Ask model for sentiment analysis on the description entered
        description = data.form['description']
        if description == '':
            feelings = None
        else:
            feelings_output = self.model.sentiment_text(description)
            if feelings_output > 0.5:
                feelings = "really like"
            elif feelings_output > 0:
                feelings = "like"
            elif feelings_output > -0.5:
                feelings = "dislike"
            else:
                feelings = "really dislike"
        # If both an image was uploaded and sentiment indicates like or really like,
        # ask model more information about what's in the image
        if label != None and (feelings == "like" or feelings == "really like"):
            detail = self.model.knowledgeGraph(label)
        else:
            detail = None
        # translate label into Spanish
        if label == None:
            labeloutput = ''
        else:
            labeloutput = label + "s"
        translatedText = self.model.translate_text("es", labeloutput)

        # Fill data into the Route
        image_data = {
            'label': label,
            'feelings': feelings,
            'image': image,
            'translatedText': translatedText,
            'detail': detail
        }
        args = {'image_data': image_data}
        route = Route(False, 'index.html', args)
        return PresentView(route)
Ejemplo n.º 10
0
 def course(self):
     courses = [
         dict(course_name=row[0],
              term=row[1],
              time=row[2],
              instructor=row[3],
              rating=row[4],
              difficulty=row[5],
              review=row[6],
              edit_time=row[7]) for row in self.model.fetchall()
     ]
     if courses:
         args = {'courses': courses}
         route = Route(False, 'course.html', args)
         return PresentView(route)
     else:
         msg = 'No Course Found'
         args = {'msg': msg}
         route = Route(False, 'course.html', args)
         return PresentView(route)
Ejemplo n.º 11
0
 def login(self, request_method, request_form):
     if request_method:
         username = request_form['username']
         password_candidate = request_form['password']
         can_login = self.model.auth_login(username, password_candidate)
         if can_login[0]:
             #compare password
             if can_login[1]:
                 session['logged_in'] = True
                 session['username'] = username
                 flash = Flash('You are now logged in.', MSG_TYPE.SUCCESS)
                 route = Route(True, 'dashboard')
                 return PresentView(route, flash)
             else:
                 error = {'error': 'Invalid login'}
                 route = Route(False, 'login.html', error)
                 return PresentView(route)
         else:
             error = {'error': 'USER DOES NOT EXIST!'}
             route = Route(False, 'login.html', error)
             return PresentView(route)
     route = Route(False, 'login.html')
     return PresentView(route)
Ejemplo n.º 12
0
 def logout(self):
     flash = Flash('You are now logged out.', MSG_TYPE.SUCCESS)
     route = Route(True, 'login')
     return PresentView(route, flash)
Ejemplo n.º 13
0
 def test_equals4(self):
     temp = PresentView(self.r2, self.f1)
     self.assertTrue(self.v21.equals(temp))
Ejemplo n.º 14
0
 def test_equals5(self):
     temp = Flash("FAILLL", MSG_TYPE.SUCCESS)
     temp = PresentView(self.r2, temp)
     self.assertFalse(self.v21.equals(temp))
Ejemplo n.º 15
0
 def article(self, id):
     article = self.model.art('articles', id)
     args = {'article': article}
     route = Route(False, 'article.html', args)
     return PresentView(route)
Ejemplo n.º 16
0
 def delete_article(self, id):
     self.model.delete_art(id)
     flash = Flash('Article Deleted', MSG_TYPE.SUCCESS)
     route = Route(True, 'dashboard')
     return PresentView(route, flash)
Ejemplo n.º 17
0
 def test_equals9(self):  # None flash
     temp = PresentView(self.r2)
     self.assertFalse(temp.equals(temp))
Ejemplo n.º 18
0
class TestPresentView(unittest.TestCase):

    r1 = Route(True, 'test', {})
    r2 = Route(True, 'test', {0: 1, 1: 'obj'})

    f1 = Flash("test", MSG_TYPE.SUCCESS)
    f2 = Flash("test", MSG_TYPE.FAIL)

    v11 = PresentView(r1, f1)
    v12 = PresentView(r1, f2)
    v21 = PresentView(r2, f1)
    v22 = PresentView(r2, f2)

    def test_get_route1(self):  #deep equality
        temp = Route(True, 'test', {})
        self.assertTrue(self.v11.get_route().equals(temp))

    def test_get_route2(self):  # pointer equality
        self.assertEqual(self.v11.get_route(), self.r1)

    def test_get_route3(self):  # pointer equality
        temp = Route(True, 'test', {})
        self.assertNotEqual(self.v11.get_route(), temp)

    def test_get_flash1(self):
        temp = Flash("test", MSG_TYPE.FAIL)
        self.assertTrue(self.v22.get_flash().equals(temp))

    def test_get_flash2(self):  # pointer equality
        self.assertEqual(self.v11.get_flash(), self.f1)

    def test_get_flash3(self):  # pointer equality
        temp = Flash("test", MSG_TYPE.SUCCESS)
        self.assertNotEqual(self.v11.get_flash(), temp)

    def test_get_flash4(self):  # pointer equality
        temp = PresentView(self.r2)
        self.assertEqual(temp.get_flash(), None)

    #
    def test_equals1(self):
        self.assertFalse(self.v11.equals(self.v12))

    def test_equals2(self):
        self.assertFalse(self.v11.equals(2))

    def test_equals3(self):
        self.assertTrue(self.v11.equals(self.v11))

    def test_equals4(self):
        temp = PresentView(self.r2, self.f1)
        self.assertTrue(self.v21.equals(temp))

    def test_equals5(self):
        temp = Flash("FAILLL", MSG_TYPE.SUCCESS)
        temp = PresentView(self.r2, temp)
        self.assertFalse(self.v21.equals(temp))

    def test_equals6(self):  # None flash
        temp = PresentView(self.r2)
        self.assertFalse(temp.equals(self.v11))

    def test_equals7(self):  # None flash
        temp = PresentView(self.r2)
        self.assertFalse(self.v22.equals(temp))

    def test_equals8(self):  # None flash
        temp = PresentView(self.r2)
        temp2 = PresentView(self.r2)
        self.assertFalse(temp.equals(temp2))

    def test_equals9(self):  # None flash
        temp = PresentView(self.r2)
        self.assertFalse(temp.equals(temp))
Ejemplo n.º 19
0
 def review(self):
     review = self.model.fetchall('review')
     args = {'review': review}
     route = Route(False, 'review.html', args)
     return PresentView(route)
Ejemplo n.º 20
0
 def test_get_flash4(self):  # pointer equality
     temp = PresentView(self.r2)
     self.assertEqual(temp.get_flash(), None)