Ejemplo n.º 1
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))
Ejemplo n.º 2
0
    def get(self):

        for entity in Trending_stream_entity.query().fetch():
            entity.key.delete()

        streams = Stream.query().order(-Stream.view_count).fetch(3)
        rank = 1

        for entity in streams:
            trending = Trending_stream_entity()
            trending.stream_item = entity
            trending.rank = rank
            rank += 1
            trending.put()
            logging.info("************trend:" + str(trending))

        email_body = "\nTeam Maroom Stream Rank:\n"
        rank = 1
        for stream in streams:
            email_body += "\tRank: {} Name {} View count:{}\n".format(
                rank, stream.name, stream.view_count)
            rank += 1
        email_body += "Thanks,\nTeam Maroom\n"

        logging.info("************trend:" + email_body)

        send_approved_mail('*****@*****.**', "*****@*****.**",
                           "Team Maroon Trending", email_body)
        self.response.content_type = 'text/plain'
        self.response.write('Sent an emails.')
Ejemplo n.º 3
0
    def post(self):
        try:
            temp_stream_name = "Labrador"
            upload = self.get_uploads()[0]
            # #logging.info("%s", dir(upload))
            # for i in upload:
            #     logging.info("%s", dir(i))
            #     logging.info("Hello %s", i.key())
            user_email = users.get_current_user()._User__email
            #stream = Stream(parent=user_key(user_obj.email))
            user_photo = Photo(
                name=upload.filename,
                blob_key=upload.key(),
                parent=stream_key(temp_stream_name)
            )
            user_photo.put()

            targets = Stream.query(Stream.name==temp_stream_name).fetch()

            for target in targets:
                logging.info("Before %d", target.num_pictures)
                target.num_pictures += 1
                logging.info("After %d", target.num_pictures)
                target.put()

            self.redirect('/blobstore/view_photo/%s' % upload.key())

        except Exception as e:
            logging.error(e)
            self.error(500)
Ejemplo n.º 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))
Ejemplo n.º 5
0
    def get(self):
        sub_stream = self.request.get('stream')
        user = users.get_current_user()

        # print(user._User__email)
        if user:
            target = Stream.query(Stream.name == sub_stream).fetch()[0]
            id = user.user_id()
            self.response.out.write(id)
            target.subscribers.append(id)
            target.put()
            self.redirect('/view_stream?name=%s' % sub_stream)
        else:
            err_msg = "You are not logged in. Please <a href='/'>login</a> to subscribe."
            self.response.out.write(err_msg)
Ejemplo n.º 6
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 = pic_url
        stream.tags = self.__get_tag(tags)
        stream.subs = self.__get_subs(subscriber_list)
        stream.num_pictures = 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))
Ejemplo n.º 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))
Ejemplo n.º 8
0
    def post(self):
        user = users.get_current_user()

        search_text = self.request.get('txtName')

        #target_query

        # IF USE GOOGLE SEARCH API
        index = search.Index(name="search_stream")
        target_query = Stream.query()
        targets = target_query.fetch()
        for target in targets:
            fields = [search.TextField(name="name", value=target.name)]
            for tag in target.tags:
                fields.append(search.TextField(name="tags", value=tag))
            d = search.Document(fields=fields, language='en')
            search.Index(name="search_stream").put(d)

        #index = search.Index()

        #search_results = index.search("%s in name OR %s in tags" % (search_text, search_text))
        search_results = index.search(search_text)
        #logging.info("%s", dir(search_results))
        logging.info("Found %d number of results" %
                     len(search_results.results))

        final_targets = []
        counter = 0
        for i in search_results:
            found_name = i.field("name".encode('utf-8')).value.decode('utf-8')
            logging.info("Found %s" % found_name)
            if counter < 5:
                target_query = Stream.query(Stream.name == found_name)
                target = target_query.fetch()[0]
                final_targets.append(target)
                counter += 1
            else:
                break
        logging.info("Listing %d of streams" % len(final_targets))
        for i in final_targets:
            logging.info("found %s", i.name)
        # remove all indexes
        while True:
            # until no more documents, get a list of documents,
            # constraining the returned objects to contain only the doc ids,
            # extract the doc ids, and delete the docs.
            document_ids = [
                document.doc_id for document in index.get_range(ids_only=True)
            ]
            if not document_ids:
                break
            index.delete(document_ids)

        # Just try to retrieve from NDB
        # # WORKS BUT NOT USING SEARCH API
        # target_query = Stream.query()
        # targets = target_query.fetch()
        # final_targets = []
        #
        # for target in targets:
        #     logging.info("target name %s, tags: %s, search text %s " % (target.name, target.tags, search_text))
        #     if search_text in target.name or search_text in str(target.tags):
        #         final_targets.append(target)
        #
        # for i in final_targets:
        #     logging.info("found %s", i.name)

        template_values = {
            'stream': final_targets,
        }

        template = JINJA_ENVIRONMENT.get_template('SearchStream.html')
        self.response.write(template.render(template_values))
Ejemplo n.º 9
0
    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))