def get(self):

        # Get User
        user = users.get_current_user()
        admin = users.is_current_user_admin()

        if models.getProfileStatus(user):
            print(user)
            student = models.getStudent(user)

            if (student == ''):

                image = models.StockImage.query(models.StockImage.name == "ccNavLogo").fetch(1)[0]
                defaultAvatar = models.getServingURL(image.image, "", True)

                template_values = {
                    'user_email': user.email(),
                    'user_ID': user.user_id(),
                    'admin': admin,
                    'profile': models.getProfileStatus(user),
                    'defaultAvatar': defaultAvatar
                }

                template = JE.get_template('templates/new_profile.html')
                self.response.write(template.render(template_values))

            else:
                self.redirect('/profile')

        else:
            self.redirect(users.create_login_url('/'))
Exemple #2
0
    def post(self):

        # Get User
        user = users.get_current_user()
        admin = users.is_current_user_admin()
        login_status = models.getLoginStatus(user)
        student = models.getStudent(user)

        if (admin):

            allRecipes = models.Recipe.query().fetch(limit=None, projection=[models.Recipe.name, models.Recipe.urlID])
            allStudents = models.Student.query().fetch(limit=None,
                                                       projection=[models.Student.firstname, models.Student.lastname,
                                                                   models.Student.urlID])

            template_values = {
                'user': user,
                'admin': admin,
                'profile': True,
                'login_status': login_status,
                'avatar_nav_img': models.getServingURL(student.avatar, 200, True),
                'all_recipes': allRecipes,
                'all_students': allStudents
            }

            template = JE.get_template('templates/admin.html')
            self.response.write(template.render(template_values))

        else:
            self.redirect('/profile')
Exemple #3
0
    def get(self):

        student = models.getStudent(users.get_current_user())

        stock = models.StockImage.query(models.StockImage.name == "ccNavLogo").fetch(1)[0]
        defaultAvatar = models.getServingURL(stock.image, "", True)
        try:
            defaultAvatar = models.getServingURL(student.avatar, 200, True)
        except Exception, e:
            print e
    def get(self):

        student = models.getStudent(users.get_current_user())

        stock = models.StockImage.query(
            models.StockImage.name == "ccNavLogo").fetch(1)[0]
        defaultAvatar = models.getServingURL(stock.image, "", True)
        try:
            defaultAvatar = models.getServingURL(student.avatar, 200, True)
        except Exception, e:
            print e
    def get(self):

        # Get User
        user = users.get_current_user()
        admin = users.is_current_user_admin()
        login_status = models.getLoginStatus(user)

        if (admin):

            student = models.getStudent(user)
            avatar = models.getServingURL(student.avatar, 200, True)

            recipe_upload_url = blobstore.create_upload_url('/recipe_upload')
            recipe_update_url = blobstore.create_upload_url('/recipe_update')
            stock_image_upload_url = blobstore.create_upload_url(
                '/stock_image_upload')
            allRecipes = models.Recipe.query().fetch(
                limit=None,
                projection=[models.Recipe.name, models.Recipe.urlID])
            allStudents = models.Student.query().fetch(
                limit=None,
                projection=[
                    models.Student.firstname, models.Student.lastname,
                    models.Student.urlID
                ])

            template_values = {
                'user': user,
                'admin': admin,
                'profile': True,
                'login_status': login_status,
                'avatar_nav_img': avatar,
                'recipe_upload_url': recipe_upload_url,
                'recipe_update_url': recipe_update_url,
                'stock_image_upload_url': stock_image_upload_url,
                'all_recipes': allRecipes,
                'all_students': allStudents
            }

            template = JE.get_template('templates/admin.html')
            self.response.write(template.render(template_values))

        else:
            self.redirect('/profile')
Exemple #6
0
    def get(self):

        recipes = models.Recipe.query()
        recipeList = recipes.fetch(limit=30)

        student = models.getStudent(users.get_current_user())

        images = []
        for recipe in recipeList:
            images.append(
                dict(
                    url=models.getServingURL(recipe.avatar, random.randint(2, 6) * 100, False)
                )
            )

        stock = models.StockImage.query(models.StockImage.name == "ccNavLogo").fetch(1)[0]
        defaultAvatar = models.getServingURL(stock.image, "", True)
        try:
            defaultAvatar = models.getServingURL(student.avatar, 200, True)
        except Exception, e:
            print e
Exemple #7
0
    def get(self):

        recipes = models.Recipe.query()
        recipeList = recipes.fetch(limit=30)

        student = models.getStudent(users.get_current_user())

        images = []
        for recipe in recipeList:
            images.append(
                dict(url=models.getServingURL(recipe.avatar,
                                              random.randint(2, 6) *
                                              100, False)))

        stock = models.StockImage.query(
            models.StockImage.name == "ccNavLogo").fetch(1)[0]
        defaultAvatar = models.getServingURL(stock.image, "", True)
        try:
            defaultAvatar = models.getServingURL(student.avatar, 200, True)
        except Exception, e:
            print e
    def get(self):

        # Get User
        user = users.get_current_user()
        admin = users.is_current_user_admin()

        student = models.getStudent(user)

        if student:

            # Student has a Profile
            profile = True
            # Create Recipes List
            recipes = []
            # Get Favorite Recipes List
            favRecipes = student.favRecipes

            # PHONES
            phones = []
            types = ['home', 'cell', 'work']
            for p in student.phone:
                # Remove Existing from types list
                types = [i for i in types if i != p.type]
                # Append to phones list
                phones.append(p)

            for t in types:
                phones.append(dict(
                    type=t,
                    number=''
                ))


            # ADDRESS
            if student.address:
                address = student.address
            else:
                address = [{'type': 'home'}]


            # Loop Through Student Recipes
            for item in student.recipes:
                # Get Recipe Using Key
                recipe_key = ndb.Key(urlsafe=item.urlID)
                recipe = recipe_key.get()
                # Create Categories List
                categories = []

                # Combine Categories into List
                for cat in recipe.category:
                    categories.append(cat)


                # COOK TIME
                cook_time = dict(
                    hours=int(recipe.cook_time / 60),
                    minutes=int(recipe.cook_time % 60)
                )

                # PREP TIME
                prep_time = dict(
                    hours=int(recipe.prep_time / 60),
                    minutes=int(recipe.prep_time % 60)
                )

                # Check if Recipe is a Favorite
                if item.urlID in favRecipes:
                    # Append Recipe Dict to List
                    recipes.append(dict(name=recipe.name, description=recipe.description, urlID=recipe.urlID,
                                        avatar=models.getServingURL(blobkey=recipe.avatar, size='', shape=False),
                                        serves=recipe.serves, cookTime=cook_time, prepTime=prep_time,
                                        categories=categories, favorite=True))
                else:
                    # Append Recipe Dict to List
                    recipes.append(dict(name=recipe.name, description=recipe.description, urlID=recipe.urlID,
                                        avatar=models.getServingURL(blobkey=recipe.avatar, size='', shape=False),
                                        serves=recipe.serves, cookTime=cook_time, prepTime=prep_time,
                                        categories=categories, favorite=False))

            template_values = {
                'user': user,
                'admin': users.is_current_user_admin(),
                'profile': profile,
                'login_status': models.getLoginStatus(user),
                'uploadURL': blobstore.create_upload_url('/update_avatar'),
                'userID': student.userID,
                'urlID': student.urlID,
                'avatar': student.avatar,
                'avatar_img': models.getServingURL(student.avatar, "", False),
                'avatar_nav_img': models.getServingURL(student.avatar, 200, True),
                'date_joined': student.date.strftime('%b %d, %Y'),
                'nickname': student.nickname,
                'firstname': student.firstname,
                'lastname': student.lastname,
                'email': student.email,
                'phone': phones,
                'address': address,
                'recipes': recipes,
                'favRecipes': favRecipes,
                'theme' : student.theme
            }

            template = JE.get_template('templates/profile.html')
            self.response.write(template.render(template_values))

        else:

            self.redirect('/new_profile')