示例#1
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')
    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')
示例#3
0
            'prep_time': prep_time,
            'cook_time': cook_time,
            'serves': recipe.serves,
            'img': image_list,
            'avatar': avatar,
            'directions': directions_list,
            'ingredients': ingredient_list,
            'utilities': utilities_list,
            'urlID': recipe.urlID,
            # Student Stuff
            'studentID': studentID,
            'theme' : student.theme,
            'avatar_nav_img': models.getServingURL(student.avatar, 200, True),
            'profile': True,
            'user': users.get_current_user(),
            'login_status': models.getLoginStatus(users.get_current_user()),
            'admin': users.is_current_user_admin(),
            'notes': recipeNotes,
            'favorite': favorite,
        }

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


class GalleryImageHandler(webapp2.RequestHandler):
    def get(self):

        recipes = models.Recipe.query()
        recipeList = recipes.fetch(limit=30)
示例#4
0
            'prep_time': prep_time,
            'cook_time': cook_time,
            'serves': recipe.serves,
            'img': image_list,
            'avatar': avatar,
            'directions': directions_list,
            'ingredients': ingredient_list,
            'utilities': utilities_list,
            'urlID': recipe.urlID,
            # Student Stuff
            'studentID': studentID,
            'theme': student.theme,
            'avatar_nav_img': models.getServingURL(student.avatar, 200, True),
            'profile': True,
            'user': users.get_current_user(),
            'login_status': models.getLoginStatus(users.get_current_user()),
            'admin': users.is_current_user_admin(),
            'notes': recipeNotes,
            'favorite': favorite,
        }

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


class GalleryImageHandler(webapp2.RequestHandler):
    def get(self):

        recipes = models.Recipe.query()
        recipeList = recipes.fetch(limit=30)
    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')