def post(self, video_id):
        content = self.request.get("content")
        vote = self.request.get("vote")
        user = self.get_user()
        user_id = user["model_id"]

        if content:
            c = VideoComment(
                content=content,
                video_id=int(video_id),
                upvotes=0,
                submitter=user["username"],
                user_id=user_id,
                downvotes=0,
            )
            c.put()
            video = Video.get_by_id(int(video_id))
            video.comment_count = video.comment_count + 1
            video.put()

            currentregistereduser = User.get_by_id(int(user["model_id"]))
            currentregistereduser.prestige = currentregistereduser.prestige + 2
            currentregistereduser.put()
            # video_comment_cache(int(group_id), True)
            self.redirect("/video/%s" % video_id)
        elif vote:
            keyname = str(user_id) + "-" + str(video_id) + "-post"
            previous_vote = Vote.get_by_id(keyname)
            # previous_vote = Vote.get_by_key_name(keyname)
            if previous_vote != None:
                video = Video.get_by_id(int(video_id))
                vote_count = video.upvotes - video.downvotes
                self.response.write(vote_count)
            else:
                vote_record = Vote.get_or_insert(keyname, vote_record=str(user_id))
                video = Video.get_by_id(int(video_id))
                vote_count = video.upvotes - video.downvotes
                if vote == "upvote":
                    vote_count = vote_count + 1
                    video.upvotes = video.upvotes + 1
                    video.put()
                    currentregistereduser = User.get_by_id(int(video.user_id))
                    currentregistereduser.prestige = currentregistereduser.prestige + 1
                    currentregistereduser.put()
                elif vote == "downvote":
                    vote_count = vote_count - 1
                    video.downvotes = video.downvotes + 1
                    video.put()
                self.response.write(vote_count)
        else:
            something = "nada"
    def post(self, user_id):
        upload_files = self.get_uploads("file")  # 'file' is file upload field in the form
        blob_info = upload_files[0]
        user = User.get_by_id(int(user_id))

        video = Video(
            title="",
            geo_center="",
            sportcategory="",
            subcategory="",
            upvotes=0,
            downvotes=0,
            submitter=user.username,
            comment_count=0,
            user_id=int(user_id),
            original_video_ref=blob_info.key(),
            mp4_video_ref=None,
            webm_video_ref=None,
            tags=[],
            spam=0,
            spamComfirmed=False,
        )
        video.put()

        # should I do this with some sort of response in a post request and send some sort of token so that it can't be done randomly
        self.redirect("/encodevideo/%s" % video.key.id())
 def post(self, profile_id):
     upload_files = self.get_uploads('file')
     blob_info = upload_files[0]
     blobRef = blob_info.key()
     user = User.get_by_id(int(profile_id))
     user.avatar = blobRef
     user.put()
     user.created = None
     user.last_modified = None
     self.redirect('/profile/%s' % (profile_id))   
 def get(self, *args, **kwargs):
     user = self.get_user()
     if user:
         profile_id = int(kwargs.get("profile_id"))
         profileowner = User.get_by_id(profile_id)
         current_profile_id = user['model_id']
         
         videos = Video.query(Video.user_id == int(profile_id)).order(-Video.created).fetch(10)
         videos = list(videos)
         videos_to_display = []
         for video in videos:
             if video.title != "":
                 videos_to_display.append(video)
         
         quote = profileowner.quote            
         
         avatar=None
         if profileowner.avatar:
             try:
                 avatar = images.get_serving_url(profileowner.avatar, size=None, crop=False, secure_url=None)
             except TransformationError:
                 logging.error('we just got a TransformationError while trying to open the users image')
                 avatar = None
         if not avatar:
             avatar = 'http://i.imgur.com/RE9OX.jpg'
         
         owner = False
         if current_profile_id == profile_id:
             owner = True               
             
         upload_url = blobstore.create_upload_url('/profileupload/%s' % (profile_id))
         
         self.render('profile.html', user=user, avatar=avatar, videos_to_display=videos_to_display,
                     profile_id=profile_id, upload_url=upload_url, profileowner=profileowner, owner=owner)
     else:
         self.render('login.html')
    def get(self):
        user = self.get_user()
        if user["model_id"] == 5187942536445952:
            user_model = User.get_by_id(5187942536445952)
            user_model.admin = True
            user_model.put

            all_videos = Video.query()
            video_count = 0
            for v in all_videos:
                video_count = video_count + 1

            all_users = User.query()
            user_count = 0
            for u in all_users:
                user_count = user_count + 1

            all_comments = VideoComment.query()
            comment_count = 0
            for c in all_comments:
                comment_count = comment_count + 1

            all_votes = Vote.query()
            vote_count = 0
            for vs in all_votes:
                vote_count = vote_count + 1

            self.response.write("There are " + str(video_count) + " videos.")
            self.response.write("<br>")
            self.response.write("There are " + str(user_count) + " users.")
            self.response.write("<br>")
            self.response.write("There are " + str(comment_count) + " comments.")
            self.response.write("<br>")
            self.response.write("There are " + str(vote_count) + " votes.")
        else:
            self.redirect("/noaccess")
    def post(self, video_id):
        title = self.request.get("title")
        sportcategory = self.request.get("sportcategory")
        sportlevel = self.request.get("sportlevel")

        tags = self.request.get("tags")
        shoutouts = self.request.get("shoutouts")
        subcategory = self.request.get("subcategory")
        description = self.request.get("description")
        winner = self.request.get("winner")
        loser = self.request.get("loser")
        geo_center = self.request.get("geo_center")

        user = self.get_user()

        if title and sportcategory != "choose" and sportlevel != "choose":

            video = Video.get_by_id(int(video_id))

            video.title = title
            video.sportcategory = sportcategory
            video.sportlevel = sportlevel

            if tags:
                try:
                    tags = tags.split(",")
                    for i in xrange(len(tags)):
                        if tags[i][0] == " ":
                            tags[i] = tags[i][1:]
                        if tags[i][0] == "#":
                            tags[i] = tags[i][1:]
                except IndexError:
                    dud_value = None
            if shoutouts:
                shoutouts = shoutouts.split(", ")
                for i in xrange(len(shoutouts)):
                    if shoutouts[i][0] == "@":
                        shoutouts[i] = shoutouts[i][1:]
                video.shoutouts = shoutouts
            if subcategory != "choose":
                video.subcategory = subcategory
            if description:
                video.description = description
            if winner:
                video.winner = winner
            if loser:
                video.loser = loser

            error = None
            GPSlocation = None
            if geo_center:
                g = geocoders.GoogleV3()
                # to catch an error where there is no corresponding location
                try:
                    # to catch an error where there are multiple returned locations
                    try:
                        place, (lat, lng) = g.geocode(geo_center)
                        place, searched_location = g.geocode(geo_center)
                    except ValueError:
                        geocodespot = g.geocode(geo_center, exactly_one=False)
                        place, (lat, lng) = geocodespot[0]
                        place, searched_location = geocodespot[0]
                    GPSlocation = "(" + str(lat) + ", " + str(lng) + ")"

                # this is straight from the docs:  http://code.google.com/p/geopy/wiki/Exceptions and happens when there is no location that matches
                except geocoders.googlev3.GQueryError:
                    logging.error("we hit an error here in that we could not find it")
                    error = (
                        "We cannot find '"
                        + geo_center
                        + "' try to be a little more specific or search a nearby location."
                    )
                except geocoders.googlev3.GTooManyQueriesError:
                    logging.error("the request did not go through because there are too many queries")
                    # TODO
                    something = "nada"

            if error:
                self.render(
                    "videoinfo.html",
                    user=user,
                    error=error,
                    title=title,
                    sportcategory=sportcategory,
                    sportlevel=sportlevel,
                    tags=tags,
                    subcategory=subcategory,
                    description=description,
                    winner=winner,
                    loser=loser,
                    geo_center=geo_center,
                )

            else:
                if GPSlocation:
                    video.geo_center = GPSlocation
                if not video.geo_center:
                    video.geo_center = None

                video.put()

                currentregistereduser = User.get_by_id(int(user["model_id"]))
                currentregistereduser.prestige = currentregistereduser.prestige + 10
                currentregistereduser.put()

                # get this to redirect to a permalink
                self.redirect("/video/%s" % video_id)

        else:
            error = "Please complete all the required sections."
            self.render(
                "videoinfo.html",
                user=user,
                error=error,
                title=title,
                sportcategory=sportcategory,
                sportlevel=sportlevel,
                tags=tags,
                subcategory=subcategory,
                description=description,
                winner=winner,
                loser=loser,
                geo_center=geo_center,
            )