Example #1
0
    def post(self):
        user_obj = User.query(
            User.email == users.get_current_user().email()).fetch()[0]

        stream_name = self.request.get('name')
        subscriber_list = self.request.get('subs')
        pic_url = self.request.get('pic_url')
        tags = self.request.get('tags')
        cover_picture = self.request.get('cover_pic')

        origin_stream = Stream.query(Stream.name == stream_name).fetch()
        logging.info("*******************origin stream: " + str(origin_stream))

        if len(origin_stream) != 0:
            logging.info("!! DUPLICATE FOUND, ERROR !!")
            template_values_none = {}
            template = JINJA_ENVIRONMENT.get_template('Error.html')
            self.response.write(template.render(template_values_none))
            return

        stream = Stream(parent=user_key(user_obj.email))
        stream.name = stream_name
        stream.cover_image = cover_picture
        stream.tags = self.__get_tag(tags)
        stream.subs = self.__get_subs(subscriber_list)
        stream.num_pictures = 0
        stream.view_count = 0
        stream.put()

        for sub in stream.subs:
            target_user = User.query(User.email == sub).fetch()
            if len(target_user) == 0:
                continue
            logging.info("adding stream %s to user %s's subcription list" %
                         (stream.name, target_user[0].email))
            target_user[0].subscribe_stream.append(stream.name)
            target_user[0].put()

        # Just try to retrieve from NDB
        target_query = Stream.query(ancestor=user_key(user_obj.email))
        targets = target_query.fetch(10)

        sub_list = []
        for subs in user_obj.subscribe_stream:
            stream_subs = Stream.query(
                ancestor=user_key(user_obj.email)).fetch(1)
            if len(stream_subs) == 0:
                continue
            sub_list.append(stream_subs[0])

        logging.info(str(sub_list))

        # template_values = {
        #     'stream': targets,
        #     'stream_subs': sub_list,
        # }
        #
        # template = JINJA_ENVIRONMENT.get_template('management.html')
        # self.response.write(template.render(template_values))
        self.redirect("/management")
Example #2
0
    def post(self):
        user = users.get_current_user()
        if user:
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            # TODO: do something
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        user_obj = User.query(
            User.email == users.get_current_user().email()).fetch()[0]

        stream_name = self.request.get('stream_name')

        if len(user_obj.subscribe_stream) == 0:
            user_obj.subscribe_stream = []

        user_obj.subscribe_stream.append(stream_name)
        user_obj.put()

        logging.info("**************subscribe_stream:" +
                     str(user_obj.subscribe_stream))

        self.redirect("/view_stream?name=" + stream_name)
Example #3
0
    def get(self):
        logging.info("Management page!!!")
        user = users.get_current_user()

        # print(user._User__email)
        if user:
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'

        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        user_obj = User.query(User.email == user.email()).fetch()[0]
        target_query = Stream.query(ancestor=user_key(user_obj.email))
        targets = target_query.fetch()

        sub_target = []

        logging.info("User subscribed for %d of streams" %
                     len(user_obj.subscribe_stream))

        for stream_name in user_obj.subscribe_stream:
            logging.info("Query for %s in stream names" % stream_name)
            stream_query = Stream.query(Stream.name == stream_name)
            # assuming no repeated stream names
            sub_target.append(stream_query.fetch()[0])
        for sub in sub_target:
            logging.info("%s" % sub.name)

        template_values = {'stream': targets, 'stream_subs': sub_target}

        template = JINJA_ENVIRONMENT.get_template('management.html')
        self.response.write(template.render(template_values))
Example #4
0
    def get(self):
        logging.info("Show All Streams!!!")
        user = users.get_current_user()

        # print(user._User__email)
        if user:
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'

        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        user_obj = User.query(User.email == user.email()).fetch()[0]
        target_query = Stream.query()
        targets = target_query.fetch()

        for s in targets:
            logging.info("*********picture: %s " % s.cover_image)

        template_values = {
            'stream': targets,
        }

        template = JINJA_ENVIRONMENT.get_template('AllStreams.html')
        self.response.write(template.render(template_values))
Example #5
0
    def get(self):

        user = users.get_current_user()
        logging.info("*************user:"******"User not found, creating User entity %s" %
                             users.get_current_user().email())
                logging.info("%s", dir(user))
                user_obj = User()
                user_obj.username = user.email()  # not sure what this is for
                user_obj.email = user.email()
                user_obj.put()
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login Using Google'

        template_values = {
            'user': user,
            'url': url,
            'url_linktext': url_linktext,
            # 'url': decorator.authorize_url(),
            # 'has_credentials': decorator.has_credentials()
        }

        template = JINJA_ENVIRONMENT.get_template('Login.html')
        self.response.write(template.render(template_values))
Example #6
0
    def get(self):
        user = users.get_current_user()
        if user:
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'
        template_values = {
            'user': user,
        }

        # create user
        user_obj = User()
        user_obj.username =users.get_current_user()
        user_obj.email = users.get_current_user().email()
        user_obj.put()

        template = JINJA_ENVIRONMENT.get_template('show_photo_in_stream.html')
        self.response.write(template.render(template_values))
Example #7
0
    def post(self):


        # assume logged in
        user_obj = User.query(User.email == users.get_current_user().email()).fetch()[0]

        # print(user._User__email)
        # if user:
        #     url = users.create_logout_url(self.request.uri)
        #     url_linktext = 'Logout'
        # else:
        #     url = users.create_login_url(self.request.uri)
        #     url_linktext = 'Login'


        #stream = Stream(parent=user_key('abc'))
        #logging.info("Hello")
        #user_obj = User.query(User.email == user._User__email)
        #user_obj = User()
        #user_obj.username = users.get_current_user()

        all_checkboxes = self.request.get('chkDelete')
        logging.info("%s", all_checkboxes)
        logging.info("%s", dir(all_checkboxes))

        check = self.request.get_all('chkDelete')

        # logging.info("checked: %s" % str(check))
        for i in check:
            stream_to_delete = i.split('/')
            logging.info("User selected deleting %s", stream_to_delete)
            found_stream = Stream.query(Stream.name == stream_to_delete[0], ancestor=user_key(user_obj.email))
            for j in found_stream.fetch():
                # TODO, the clean way is to delete pictures too
                logging.info("Removing stream: %s ", j.name)
                j.key.delete()

        sub_check = self.request.get_all('sub_chkDelete')

        target_query = Stream.query(ancestor=user_key(user_obj.email))
        targets = target_query.fetch()

        for i in targets:
            logging.info("There are %s pics in stream %s " % (i.num_pictures, i.name))


        for i in sub_check:
            stream_to_unsub = i.strip('/')
            logging.info("stream to unsub %s" % stream_to_unsub)
            logging.info("User currently subscribes to %s" % user_obj.subscribe_stream)
            logging.info("User selected to remove subscription %s", stream_to_unsub.encode('utf-8'))
            user_obj.subscribe_stream.remove(stream_to_unsub.encode('utf-8'))
            logging.info("User now subscribe to %s" % user_obj.subscribe_stream)
            user_obj.put()

        sub_target = []

        logging.info("User subscribed for %d of streams" % len(user_obj.subscribe_stream))

        for stream_name in user_obj.subscribe_stream:
            logging.info("Query for %s in stream names" % stream_name)
            stream_query = Stream.query(Stream.name == stream_name)
            # assuming no repeated stream names
            if len(stream_query.fetch()) >= 1:
                sub_target.append(stream_query.fetch()[0])
        for sub in sub_target:
            logging.info("%s" % sub.name)

        template_values = {
            'stream': targets,
            'stream_subs': sub_target
        }

        template = JINJA_ENVIRONMENT.get_template('management.html')
        self.response.write(template.render(template_values))
    def get(self):
        stream_name = self.request.get('name')
        offset = self.request.get('offset')
        offset_int = 0

        stream = Stream.query(Stream.name == stream_name).fetch()[0]
        if offset:
            offset_int = int(offset)

        now = int(time.time())
        if stream.views_ts is None:
            stream.views_ts = [now]
        else:
            stream.views_ts.append(now)

        stream.put()

        logging.info("**********stream:" + str(stream.views_ts))

        user = users.get_current_user()

        user_obj = User()
        #user_obj.username = user._User__email
        if user:
            user_obj.email = user._User__email

        #stream = Stream(parent=user_key(user.email))
        #stream_name = self.request.get('name')
        #current_stream = Stream.query(Stream.name == stream_name).fetch()
        #Update the view count
        logging.info("Stream name: %s" % stream_name)
        target = Stream.query(Stream.name == stream_name).fetch()[0]

        if target.view_count is None:
            target.view_count = 0
        logging.info("Before %d" % target.view_count)
        target.view_count += 1
        logging.info("After %d" % target.view_count)
        target.put()

        # Just try to retrieve from NDB
        targets, next_cursor, more = Photo.query().order(
            -Photo.uploaddate).fetch_page(4, offset=offset_int)
        #targets = Photo.query().order(-Photo.uploaddate).fetch(4)

        next_ = True if more else False
        next_offset = ''
        if next_:
            offset = offset_int + 4

        #upload_url = blobstore.create_upload_url('/view_stream/upload')
        upload_url = '/view_stream/upload'

        template_values = {
            'photos': targets,
            'upload_url': upload_url,
            'stream_name': stream_name,
            'offset': offset,
        }

        template = JINJA_ENVIRONMENT.get_template('ViewStream.html')
        self.response.write(template.render(template_values))