def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        AccountFunction.getUser(self)
        template_value = self.get_template_value(self)

        template = JINJA_ENVIRONMENT.get_template('home.html')
        self.response.write(template.render(template_value))
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        template_value = self.get_template_value(self)
        # logging.info(self.request.get("username"))

        AccountFunction.save_username(self.request.get("username"))
        user = AccountFunction.getUser(self)
        if user['user'] and user['user'].user_name:
            self.redirect('/profile')
        template = JINJA_ENVIRONMENT.get_template('home.html')
        self.response.write(template.render(template_value))
    def save_tweet(self, req):
        text = req.request.get("text")
        file = req.get_uploads()
        if not text:
            return {
                "message": "Please enter tweet",
                "status": False,
                "records": {}
            }
        if len(text) > 280:
            return {
                "message": "Only 280 characters allowed",
                "status": False,
                "records": {}
            }

        upload = None
        if file:
            upload = file[0].key()
            info = blobstore.BlobReader(upload)
            if info.blob_info.content_type not in ['image/jpeg', 'image/png']:
                blobstore.delete(upload)
                return {
                    "status": False,
                    "message": "Only png PNG and JPEG can be uploaded"
                }

        userv = AccountFunction.current_user()
        tkey = AccountFunction.tweet_key(userv.user_name)
        Tweet = TweetEntity(id=tkey,
                            tweet=text,
                            user_name=userv.user_name,
                            user_email=userv.email,
                            tweet_image=upload)
        Tweet.put()
        userv.tweet_count = userv.tweet_count + 1
        userv.put()

        document = search.Document(doc_id=tkey,
                                   fields=[
                                       search.TextField(name='tweet',
                                                        value=text),
                                       search.TextField(name='user_name',
                                                        value=userv.user_name)
                                   ],
                                   language='en')

        search.Index(name='tweets').put(document)
        return {
            "message": "Tweet saved successfully",
            "status": True,
            "records": {}
        }
    def template_value(self, req):
        user = AccountFunction.getUser(req)
        tweet_data = AccountFunction.get_tweets_for_current_user()
        # logging.info(tweet_data)
        template_value = {
            'user': user,
            'following': len(user['user'].following),
            'follow': len(user['user'].follows),
            'tweet_data': tweet_data,
            'upload_url': blobstore.create_upload_url('/profile'),
            'images': images,
            'AccountFunction': AccountFunction,
        }

        # logging.info(user)
        return template_value
示例#5
0
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        template_value = self.get_tempate_values(self)
        template_value["data"] = AccountFunction.update_profile(self)

        template = JINJA_ENVIRONMENT.get_template('edit_profile.html')
        self.response.write(template.render(template_value))
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        template_value = self.template_value(self)
        template_value["edit_tweet"] = False
        if self.request.params and "edit-tweet" in self.request.params:
            template_value["edit_tweet"] = True
            template_value["single_tweet"] = AccountFunction.get_tweet_by_id(
                self.request.params["edit-tweet"])

        if self.request.params and "delete-tweet" in self.request.params:
            template_value["delete_tweet"] = AccountFunction.delete_tweet(
                self.request.params["delete-tweet"])
            template_value[
                'tweet_data'] = AccountFunction.get_tweets_for_current_user()

        template = JINJA_ENVIRONMENT.get_template('profile.html')
        self.response.write(template.render(template_value))
示例#7
0
 def get_tempate_values(self,req):
     user = AccountFunction.getUser(req)
     logging.info(user['user'])
     template_value = {
         'user': user,
         'following': len(user['user'].following),
         'follow': len(user['user'].follows),
     }
     return template_value
    def get_template_value(self, req):
        user = AccountFunction.getUser(req)

        if user['user'] and user['user'].user_name:
            req.redirect('/profile')

        template_value = {
            'user': user
        }
        
        return template_value
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'


        button = self.request.get("button")
        data = AccountFunction.change_follow_status(self)
        template_value = self.template_value(self)
        template_value['data'] = data
        # if button == "Search User":
        #     template_value['user_search'] =  self.search_user(self)
        # elif button == "Tweet":
        #     template_value['save_tweet'] = self.save_tweet(self)

        template = JINJA_ENVIRONMENT.get_template('show_profile.html')
        self.response.write(template.render(template_value))
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        template_value = self.template_value(self)
        template_value["edit_tweet"] = False
        if self.request.params and "edit-tweet" in self.request.params:
            template_value["edit_tweet"] = True
            template_value["single_tweet"] = AccountFunction.get_tweet_by_id(
                self.request.params["edit-tweet"])

        button = self.request.get("button")
        if button == "Search User":
            template_value['user_search'] = self.search_user(self)
        elif button == "Tweet":
            template_value['save_tweet'] = self.save_tweet(self)
        elif button == "Update Tweet":
            template_value['update_tweet'] = self.update_tweet(self)
        elif button == "Search Tweet":
            template_value['search_tweet'] = AccountFunction.search_tweet(self)

        template_value[
            'tweet_data'] = AccountFunction.get_tweets_for_current_user()
        # logging.info(template_value)
        template = JINJA_ENVIRONMENT.get_template('profile.html')
        self.response.write(template.render(template_value))
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        template_value = self.template_value(self)
        current_user = AccountFunction.current_user()
        if current_user.user_name == self.request.params["user"]:
            return self.redirect("/profile")

        # logging.info(self.request.params)
        # params = self.request.params
        # if params:
        #     params['user']
        #
        # template_value["username"] =  params['user']

        template = JINJA_ENVIRONMENT.get_template('show_profile.html')
        self.response.write(template.render(template_value))
    def update_tweet(self, req):
        text = req.request.get("text")
        if not text:
            return {
                "message": "Please enter tweet",
                "status": False,
                "records": {}
            }
        if len(text) > 280:
            return {
                "message": "Only 280 characters allowed",
                "status": False,
                "records": {}
            }

        userv = AccountFunction.current_user()
        t_key = ndb.Key(
            'TweetEntity',
            userv.user_name + '/' + req.request.params["edit-tweet"])
        tweet = t_key.get()
        tweet.tweet = text
        tweet.put()
        # userv.tweet_count = userv.tweet_count - 1
        # userv.put()

        index = search.Index('tweets')
        index.delete(userv.user_name + '/' + req.request.params["edit-tweet"])
        document = search.Document(doc_id=userv.user_name + '/' +
                                   req.request.params["edit-tweet"],
                                   fields=[
                                       search.TextField(name='tweet',
                                                        value=text),
                                       search.TextField(name='user_name',
                                                        value=userv.user_name)
                                   ],
                                   language='en')

        search.Index(name='tweets').put(document)
        return {
            "message": "Tweet updated successfully",
            "status": True,
            "records": {}
        }
    def template_value(self, req):
        user = AccountFunction.getUser(req)
        params = req.request.params

        if params:
            params['user']

        template_value = {
            'user': user,
            'username':params['user'],
            'status':AccountFunction.get_following_flag(req),
            'tweets':AccountFunction.get_tweets_by_username(params['user']),
            'profile_info':AccountFunction.get_user_by_ueraname(params['user']),
            'followers':len(AccountFunction.get_user_by_ueraname(params['user']).follows),
            'following':len(AccountFunction.get_user_by_ueraname(params['user']).following),
            'images': images,
            'AccountFunction': AccountFunction,
        }

        return template_value