Example #1
0
	def get(self):
		show_all_key = ''
		if self.request.get('show_all_key'):
			show_all_key = ndb.Key(urlsafe=self.request.get('show_all_key'))
		self.response.headers['Content-Type'] = 'text/html'

		url = ''
		url_string = ''
		post = ''

		welcome = 'Welcome back'
		myuser = None
		posts = []
		comment_dictonary = {}
		user = users.get_current_user()
		if user:
			url = users.create_logout_url(self.request.uri)
			url_string = 'logout'
			myuser_key = ndb.Key('MyUser', user.user_id())
			myuser = myuser_key.get()

			post = BlobCollection.query().order(-BlobCollection.posted_date).fetch(limit=50)
			if myuser == None:
				welcome = 'Welcome to the Instagram'
				myuser = MyUser(id=user.user_id())
				myuser.name = user.email()
				myuser.put()
			key_list = []
			if myuser:
				for follo in myuser.following:
					use = MyUser.query().filter(MyUser.name == follo)
					use = use.fetch(10)
					for ussss in use:
						key_list.append(ussss.key)
				# raise UserWarning(key_list)
				for p in post:
					if p.user_key == myuser.key or p.user_key in key_list:
						posts.append(p)
				for pst in posts:
					comments = Comments.query().filter(Comments.post_key == pst.key).order(-Comments.posted_date)
					comment_dictonary[pst.key] = comments

		else:
			url = users.create_login_url(self.request.uri)
			url_string = 'login'
		# raise UserWarning(posts)
		template_values = {
			'url' : url,
			'show_all_key' : show_all_key,
			'posts': posts,
			'comment_dictonary': comment_dictonary,
			'upload_url': blobstore.create_upload_url('/upload'),
			'url_string' : url_string,
			'user' : user,
			'welcome' : welcome,
			'myuser' : myuser
		}

		template = JINJA_ENVIRONMENT.get_template('main.html')
		self.response.write(template.render(template_values))
Example #2
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'

        boardId = self.request.get('id')

        user = users.get_current_user()
        myuser_key = ndb.Key('MyUser', user.email())
        myuser = myuser_key.get()

        getBoard = TaskBoard.get_by_id(boardId)

        name_of_board = getBoard.tb_name
        creator = getBoard.creator

        allUsers = MyUser.query().fetch()

        template_values = {
            'myuser': myuser,
            'board_name': name_of_board,
            'creator': creator,
            'users': allUsers,
            'board_id': boardId
        }

        template = JINJA_ENVIRONMENT.get_template('invite.html')
        self.response.write(template.render(template_values))
    def post(self):

        user = users.get_current_user()

        myuser_key = ndb.Key('MyUser', user.user_id())
        myuser = myuser_key.get()

        # user_id = self.request.get('id')
        # profile_key = ndb.Key('MyUser', user_id)
        # profile = profile_key.get()

        if self.request.get('button') == 'search':
            search_result = []
            search_string = self.request.get('search_string').lower()
            user_list = MyUser.query().order(MyUser.username).fetch()
            for i in user_list:
                temp = i.username.startswith(search_string)
                if temp:
                    search_result.append(i)

            user = users.get_current_user()
            myuser_key = ndb.Key('MyUser', user.user_id())
            myuser = myuser_key.get()

            template_values = {
                'url': users.create_logout_url(self.request.uri),
                'user': user,
                'myuser': myuser,
                'upload_url': blobstore.create_upload_url('/upload'),
                'search_result': search_result
            }

            template = JINJA_ENVIRONMENT.get_template('list.html')
            self.response.write(template.render(template_values))
Example #4
0
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        if self.request.get('button') == 'Research':
            key = ndb.Key('ListUser', 'default')
            list_user = key.get()
            del list_user.list_user
            research = self.request.get('email_address')
            research_user = MyUser.query(MyUser.email_address == research)
            for i in research_user:
                list_user.list_user.append(i)
            list_user.put()
            self.redirect('/')

        if self.request.get('button') == 'Add comment':
            post_id = self.request.get('post_id')
            comment = self.request.get('comment')

            user = users.get_current_user()
            myuser_key = ndb.Key('MyUser', user.user_id())
            myuser = myuser_key.get()

            my_comment = MyComment(user=myuser, comment=comment, creation_time=datetime.now())
            my_comment.put()
            list_comment = ListComment.query(ListComment.post_id == post_id)
            for i in list_comment:
                i.list_comment.append(my_comment)
                i.list_comment = sorted(i.list_comment, key=lambda comment: comment.creation_time)
                i.put()
            self.redirect('/')
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'

        # pull the current user from the Request
        user = users.get_current_user()

        if user == None:
            url_string = 'login'
            url = users.create_login_url(self.request.uri)
            template_values = {
                'url_string': url_string,
                'url': url,
                'login_url': users.create_login_url(self.request.uri)
            }

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

        url_string = 'logout'
        url = users.create_logout_url(self.request.uri)
        query = MyUser.query()

        template_values = {
            "user": user,
            'url_string': url_string,
            'url': url,
        }

        # pull the template file and ask jinja to render
        # it with the given template values
        template = JINJA_ENVIRONMENT.get_template('create_taskboard.html')
        self.response.write(template.render(template_values))
Example #6
0
    def post(self):
        new_board_name = self.request.get('new_board_name')

        boardId = self.request.get('id')

        getBoard = TaskBoard.get_by_id(boardId)
        board_name = getBoard.tb_name

        getAllUsers = MyUser.query().fetch()

        action = self.request.get('button')

        if action == 'rename':

            for a in list(getAllUsers):
                for b in list(a.myuser_board):
                    if (b.tb_name == board_name):
                        b.tb_name = new_board_name
                        a.put()

                        getBoard.tb_name = new_board_name
                        getBoard.put()
                        self.redirect('/view_board?id=' + boardId)

        elif action == 'cancel':
            self.redirect('/view_board?id=' + boardId)
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        template = JINJA_ENVIRONMENT.get_template('main.html')
        action = self.request.get('button')
        if action == 'Search':
            tweet_username_list = []
            tweet_text_list = []

            tweet_search = self.request.get('tweet_search')
            if tweet_search == '':
                tweet_username_list = []
                tweet_text_list = []
            else:
                username_query = MyUser.query().fetch()
                tweet_content_query = TweetModel.query().fetch()

                for user in username_query:
                    if any(word in user.username
                           for word in tweet_search.split()):
                        tweet_username_list.append(user.username)
                        tweet_text_list.append("")

                for tweet in tweet_content_query:
                    if all(word in tweet.tweet_text
                           for word in tweet_search.split()):
                        tweet_username_list.append(tweet.tweet_username)
                        tweet_text_list.append(tweet.tweet_text)
            template_values = {
                'tweet_username_list': tweet_username_list,
                'tweet_text_list': tweet_text_list
            }
            template = JINJA_ENVIRONMENT.get_template('search.html')
            self.response.write(template.render(template_values))
        if action == 'Back':
            self.redirect('/')
 def get(self):
     x = ''
     if self.request.get('submit'):
         use = self.request.get('use')
         if use == '':
             x = MyUser.query()
         else:
             n = list(MyUser.query().filter(
                 MyUser.email_address == self.request.get('use')).fetch(
                     keys_only=True))
             if n == None:
                 self.response.write('No user found')
             else:
                 x = ndb.get_multi(n)
     template_values = {'use': self.request.get('use'), 'x': x}
     template = JINJA_ENVIRONMENT.get_template('searchpage.html')
     self.response.write(template.render(template_values))
 def post(self):
     self.response.headers['Content-Type'] = 'text/html'
     action = self.request.get('button')
     user = users.get_current_user()
     myuser_key = ndb.Key('MyUser', user.user_id())
     myuser = myuser_key.get()
     follow = ''
     if self.request.get('back') == 'Back':
         self.redirect('/')
     elif action == 'Follow':
         username = self.request.get('username')
         myuser.following.append(username)
         username_query = MyUser.query(MyUser.username == username).fetch()
         logging.info(username_query)
         user_profile_key = ndb.Key('MyUser', username_query[0].userid)
         user_profile = user_profile_key.get()
         user_profile.followers.append(myuser.username)
         follow = 'Follow'
         logging.info(follow)
         myuser.put()
         user_profile.put()
         self.redirect('/user?username='******'Unfollow':
         username = self.request.get('username')
         myuser.following.remove(username)
         username_query = MyUser.query(MyUser.username == username).fetch()
         logging.info(username_query)
         user_profile_key = ndb.Key('MyUser', username_query[0].userid)
         user_profile = user_profile_key.get()
         logging.info(user_profile_key)
         user_profile.followers.remove(myuser.username)
         follow = 'Unfollow'
         logging.info(follow)
         myuser.put()
         user_profile.put()
         self.redirect('/user?username=' + username)
Example #10
0
    def post(self):
        action = self.request.get('button')

        if action == 'Search':
            #Retrieve user input
            name = self.request.get('name')

            #If nothing is selceted display all ev's in the db
            if not name:

                user = users.get_current_user()
                myuser_key = ndb.Key('MyUser', user.user_id())
                myuser = myuser_key.get()
                query = MyUser.query()
                template_values = {'myuser': myuser, 'search_list': query}
                template = JINJA_ENVIRONMENT.get_template('search.html')
                self.response.write(template.render(template_values))

            else:

                query = MyUser.query()
                search_list = []
                for i in query:
                    if name.lower() in i.name.lower():
                        search_list.append(i)

                user = users.get_current_user()
                myuser_key = ndb.Key('MyUser', user.user_id())
                myuser = myuser_key.get()

                template_values = {
                    'myuser': myuser,
                    'search_list': search_list
                }
                template = JINJA_ENVIRONMENT.get_template('search.html')
                self.response.write(template.render(template_values))
Example #11
0
    def get(self):
        self.request.headers['Content-Type'] = 'text/html'
        user = users.get_current_user()

        if user == None:
            template_values = {
                'login_url': users.create_login_url(self.request.url)
            }

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

        myuser_key = ndb.Key('MyUser', user.user_id())
        myuser = myuser_key.get()

        if myuser == None:
            myuser = MyUser(id=user.user_id())
            myuser.put()

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

        userbio = MyUser.query(MyUser.name == name).fetch()
        list_tweets = MyUser.UserTweets.query(UserTweets.name == name).fetch()

        twitter_key = ndb.Key('UserTweets', myuser.name)
        twitter = twitter_key.get()
        usertweets_new = myuser.usertweets

        followBool = True

        if userbio[0]:
            logging.info(myuser.following)
            if userbio[0].name in myuser.following:
                followBool = False

        template_values = {
            'logout_url': users.create_logout_url(self.request.url),
            'userbio': userbio,
            'tweets': list_tweets,
            'usertweets': myuser.usertweets,
            'followBool': followBool,
            'currentuser_name': myuser.name
        }

        template = JINJA_ENVIRONMENT.get_template('profile.html')
        self.response.write(template.render(template_values))
Example #12
0
    def post(self):
        current_user = users.get_current_user()
        if self.request.get('button') == 'Search':

            name = self.request.get('name')
            user_list = MyUser.query()
            if name:
                # raise UserWarning("ssssssssssss")
                user_list = user_list.filter(MyUser.name == name)
            user_list = user_list.fetch(10)
            # raise UserWarning(user_list)
            template_values = {
                'users': user_list,
                'current_user': current_user,
            }
            template = JINJA_ENVIRONMENT.get_template('search_user.html')
            self.response.write(template.render(template_values))
Example #13
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/html' ''

        query = MyUser.query()

        # URL that will contain a login or logout link
        # and also a string to represent this
        url = ''
        url_string = ''
        welcome = 'Welcome back'
        myuser = ''

        # pull the current user from the Request
        user = users.get_current_user()

        # determine if we have a user logged in or not
        if user:
            myuser_key = ndb.Key('MyUser', user.user_id())
            myuser = myuser_key.get()

            if myuser == None:
                welcome = 'Welcome to the application'
                myuser = MyUser(id=user.user_id(), )
                myuser.email_address = user.email()
                myuser.put()

            if not myuser.username:
                self.redirect('/')

        else:
            url = users.create_login_url(self.request.uri)
            login_status = "You are not logged in."
            url_string = 'login'
            self.redirect('/')

        template_values = {
            'user': user,
            'myuser': myuser,
        }

        # pull the template file and ask jinja to render
        # it with the given template values
        template = JINJA_ENVIRONMENT.get_template('search.html')
        self.response.write(template.render(template_values))
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        template = JINJA_ENVIRONMENT.get_template('username.html')
        user = users.get_current_user()
        action = self.request.get('button')
        if action == 'Submit':
            edit = self.request.get('edit')

            full_name = self.request.get('full_name')
            description = self.request.get('description')
            myuser_key = ndb.Key('MyUser', user.user_id())
            myuser = myuser_key.get()
            if edit == 'yes':
                myuser.full_name = full_name
                myuser.description = description
                myuser.put()
                self.redirect('/')

            elif edit == 'no':
                username = self.request.get('username')
                username_query = MyUser.query(
                    MyUser.username == username).fetch()
                if not username_query:
                    if myuser == None:
                        myuser = MyUser(id=user.user_id(),
                                        userid=user.user_id(),
                                        email_address=user.email(),
                                        username=username,
                                        full_name=full_name,
                                        description=description,
                                        followers=[],
                                        following=[])
                        myuser.put()
                        self.redirect('/')
                else:
                    error = 'Username already exists'
                    template_values = {'error': error, 'myuser': myuser}
                    self.response.write(template.render(template_values))
        elif action == 'Back':
            self.redirect('/')
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        username = self.request.get('username')
        user = users.get_current_user()
        myuser_key = ndb.Key('MyUser', user.user_id())
        myuser = myuser_key.get()
        same_user = ''
        username_query = MyUser.query(MyUser.username == username).fetch()
        logging.info(username_query)
        full_name = username_query[0].full_name
        description = username_query[0].description
        tweet_list = []
        followers_count = len(username_query[0].followers)
        following_count = len(username_query[0].following)

        if myuser.username == username:
            same_user = '******'
        following_list = myuser.following
        follow = 'Follow'
        if username in following_list:
            follow = 'Unfollow'

        tweet_query = TweetModel.query(
            TweetModel.tweet_username == username).fetch(limit=50)

        for tweet in tweet_query:
            tweet_list.append(tweet)

        template_values = {
            'username': username,
            'full_name': full_name,
            'description': description,
            'follow': follow,
            'followers_count': followers_count,
            'following_count': following_count,
            'same_user': same_user,
            'tweet_list': tweet_list
        }
        template = JINJA_ENVIRONMENT.get_template('view_user.html')
        self.response.write(template.render(template_values))
Example #16
0
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'

        users_list = []
        users_email_list = []
        #all_users = MyUser.query(ndb.AND(MyUser.email_address != myuser.email_address))

        if (self.request.get('button') == 'Search user'):
            query = MyUser.query()
            query = list(query)

            id = self.request.get("ID")

            myuser_key = ndb.Key('MyUser', id)
            myuser = myuser_key.get()

            username_s = self.request.get("username")

            for i in query:

                if username_s.lower() in i.username.lower():
                    users_list.append(i)
                    #logging.info("# DEBUG: ")
                    #print(users_list)
                    #print(i.username)
                    #print(username_s)
                    #logging.info("End")

            #myuser.put()
            #self.redirect('/')

            template_values = {'myuser': myuser, 'users_list': users_list}

            # pull the template file and ask jinja to render
            # it with the given template values
            template = JINJA_ENVIRONMENT.get_template('search.html')
            self.response.write(template.render(template_values))
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'

        # pull the current user from the Request
        user = users.get_current_user()

        if user == None:
            url_string = 'login'
            url = users.create_login_url(self.request.uri)
            template_values = {
                'url_string': url_string,
                'url': url,
                'login_url': users.create_login_url(self.request.uri)
            }

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

        url_string = 'logout'
        url = users.create_logout_url(self.request.uri)

        id = user.user_id()
        tb_clicked = ''
        tb_name_clicked = ""
        tb_name_clicked_inv = ""
        tb_key_clicked = []
        tb_users_email_clicked = []
        tb_users_email_clicked_inv = []
        total_users_incl_creator = []
        title_list = []
        assigned_user_list = []
        duedate_list = []
        status_list = []
        state = -1
        task_status = []
        #message = ''

        myuser_key = ndb.Key('MyUser', id)
        myuser = myuser_key.get()

        #name = self.request.get('tbd_name')
        url_ID = long(self.request.get('ID'))
        #print(name)
        print(url_ID)
        logging.info("EFF")

        #queries the datastore for all users except the creator
        all_users = MyUser.query(
            ndb.AND(MyUser.email_address != myuser.email_address))
        #all_users = MyUser.query()
        query = MyUser.query().fetch(keys_only=True)
        for i in query:
            total_users_incl_creator.append(i.get().email_address)
            print(total_users_incl_creator)

        tbd_id = ndb.Key('TaskBoard', url_ID)
        tb_clicked = tbd_id.get()

        #if tb_clicked == None:
        #tb_clicked = TaskBoard()
        #tb_clicked.put()

        #if (myuser.email_address == i.get().tbd_creator_email):
        #tb_name_clicked = tb_clicked.tbd_name
        #tk_key_clicked = tb_clicked.tk_key
        tb_users_email_clicked = tb_clicked.tbd_users_email

        # getting the task ID from the form
        #t_ID=self.request.get("t_id")
        #t_ID=long(t_ID)

        #t_id = ndb.Key('TaskBoard', t_ID)
        #task_clicked = tbd_id.get()

        length = 0
        completedtaskcount = 0
        activetasks = 0
        completedtoday = 0
        totaltask = 0
        datetimeobj = datetime.now()
        dtime = datetimeobj.strftime("%d-%m-%Y")
        #i.get().date_task_completed = datetimeobj.strftime("%d-%b-%Y (%H:%M:%S)")

        #if (len(tb_clicked.tk_key) != 0):
        for i in tb_clicked.tk_key:
            task_id = ndb.Key('Task', i.id())
            task_obj = task_id.get()

            #logging.info("HEY")
            #print(task_obj.status)
            if task_obj.status == True:
                completedtaskcount = completedtaskcount + 1

                if i.get().date_task_completed == dtime:
                    completedtoday = completedtoday + 1
            if task_obj.status == False:
                activetasks = activetasks + 1

        totaltask = completedtaskcount + activetasks

        template_values = {
            'tb_clicked': tb_clicked,
            #'task_obj' : task_obj,
            'length': length,
            'url_string': url_string,
            'url': url,
            'completedcount': completedtaskcount,
            'activetasks': activetasks,
            'totaltask': totaltask,
            'completedtoday': completedtoday,
            #'message' : message,

            #'task_clicked' : task_clicked,
            'user': user,
            'myuser': myuser,
            'all_users': all_users,
            #'tb_name_clicked' : tb_name_clicked,
            #'tb_name_clicked_inv' : tb_name_clicked_inv,
            'users_list': tb_users_email_clicked,
            #'users_list_inv' : tb_users_email_clicked_inv,
            #'tasks_list' : tb_clicked.tk_key,
            #'duedate_list' : duedate_list,
            #'title_list' : title_list,
            #'assigned_user_list' : assigned_user_list,
            #'status_list' : status_list,
            #'status' : task_status,
        }

        # pull the template file and ask jinja to render
        # it with the given template values
        template = JINJA_ENVIRONMENT.get_template('view_each_tb.html')
        self.response.write(template.render(template_values))
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'

        query = MyUser.query()
        tb_invited_users_list = []
        user = users.get_current_user()
        id = user.user_id()
        myuser_key = ndb.Key('MyUser', id)
        myuser = myuser_key.get()
        message = ''

        all_users = MyUser.query(
            ndb.AND(MyUser.email_address != myuser.email_address))

        if (self.request.get('button') == 'Invite users'):
            url_ID = self.request.get("f_id")
            url_ID = long(url_ID)
            #logging.info("HEY")
            #print(url_ID)
            #logging.info("YEE")

            name = self.request.get('tbd_name')

            # For the selected user,add the TB key to the invited TB list
            selected = self.request.get('invite')
            selected_user = ndb.Key('MyUser', selected)
            selected_user_obj = selected_user.get()
            #logging.info("MNX")
            #print(type(i.get().key.id()))
            #print(i.get().key.id())
            #print(type(url_ID))
            #print(url_ID)
            #print(url_ID == i.id())
            #logging.info("END")

            # For the current user/ creator of the taskboard
            adduser_key = ndb.Key('TaskBoard', url_ID)
            adduser_obj = adduser_key.get()

            if (myuser.email_address == adduser_obj.tbd_creator_email):
                #When inviting a new user to the TB, check if the User and the TB creator is in the TB members' list
                if (selected_user.get().email_address
                        not in adduser_obj.tbd_users_email):
                    if (adduser_obj.tbd_creator_email
                            not in adduser_obj.tbd_users_email):
                        adduser_obj.tbd_users_email.append(
                            adduser_obj.tbd_creator_email)
                        #adduser_obj.tbd_users.append(myuser_key)

                    else:
                        print("Do nothing")

                    adduser_obj.tbd_users_email.append(
                        selected_user.get().email_address)
                    #selected_user_obj.tb_key.append(adduser_key )

                    selected_user_obj.put()
                    adduser_obj.put()
                    message = 'New user added to the taskboard'

                    #self.redirect('/view_each_tb?tbd_name=' + name)

                else:
                    message = 'User already exists in the Taskboard'
                self.redirect('/view_each_tb?ID=' + str(url_ID))
            else:
                #logging.info("Start message 1")
                #print('Only the creator can invite users')
                #logging.info("Debug message 2")
                message = 'Only the creator can invite users'
                self.redirect('/view_each_tb?tbd_name=' + name)

        elif self.request.get('button') == 'Add a task':

            url_ID = self.request.get("f_id")
            url_ID = long(url_ID)

            exist = 0

            task_obj = Task()

            tbd_key = ndb.Key('TaskBoard', url_ID)
            tbd_obj = tbd_key.get()
            mtitle = self.request.get('title')

            #for i in tbd_obj.tk_key:
            #task_id = ndb.Key('Task', i.id())
            #task_obj = task_id.get()

            for i in tbd_obj.tk_key:
                if i.get().title.lower() == mtitle.lower():
                    exist += 1  #Task already exist

            #if task_obj == None:
            #task_obj = Task()
            #task_obj.put()

            # If task object exists in the taskboard, check to see if task
            # with similar name already exists
            if (exist == 0):
                # Task doesnt exist
                htitle = self.request.get('title')
                hassigned_user = self.request.get('assigned_user')
                due_date = self.request.get('due_date')
                hstripped_due_date = datetime.strptime(due_date, '%Y-%m-%d')

                hcreator = myuser.email_address
                hstatus = False  #a new task is defaulted to not complete

                # Append values to the lists
                task_obj.title = htitle
                task_obj.assigned_user = hassigned_user
                task_obj.due_date = hstripped_due_date
                task_obj.creator = hcreator
                task_obj.status = hstatus
                task_obj.word_status = "not completed"

                #task_obj.total_t += 1
                #task_obj.active_t += 1

                task_obj.put()

                tkey = ndb.Key('Task', task_obj.key.id())
                task_obj = tkey.get()
                tbd_obj.tk_key.append(tkey)
                tbd_obj.put()
                message = 'New%20Task%20added'
                self.redirect('/view_each_tb?ID=' + str(url_ID))

            else:
                message = 'Task already exists'
                self.redirect('/view_each_tb?ID=' + str(url_ID))

        elif self.request.get('button') == 'not completed':
            logging.info(self.request.get('button'))
            url_ID = self.request.get("f_id")
            url_ID = long(url_ID)
            t_ID = self.request.get("t_id")
            t_ID = long(t_ID)
            exist = 0

            index = int(self.request.get('index')) - 1

            #ind = int (self.request.get("ind"))

            tbd_key = ndb.Key('TaskBoard', url_ID)
            tbd_obj = tbd_key.get()

            task_obj = Task()
            for i in tbd_obj.tk_key:
                if i.get().key.id() == t_ID:
                    datetimeobj = datetime.now()
                    task_obj = i.get()
                    i.get().status = True
                    i.get().word_status = "completed"
                    i.get().date_task_completed = datetimeobj.strftime(
                        "%d-%m-%Y")
                    i.get().time_task_completed = datetimeobj.strftime(
                        "%I:%M:%S %p")
                    task_obj.put()
                    break

            #self.redirect('/')
            self.redirect('/view_each_tb?ID=' + str(url_ID))

        elif self.request.get('button') == 'completed':
            url_ID = self.request.get("f_id")
            url_ID = long(url_ID)
            t_ID = self.request.get("t_id")
            t_ID = long(t_ID)

            index = int(self.request.get('index')) - 1

            #ind = int (self.request.get("ind"))

            tbd_key = ndb.Key('TaskBoard', url_ID)
            tbd_obj = tbd_key.get()

            task_obj = Task()
            for i in tbd_obj.tk_key:
                if i.get().key.id() == t_ID:
                    task_obj = i.get()
                    i.get().status = False
                    i.get().word_status = "not completed"
                    i.get().date_task_completed = ""
                    i.get().time_task_completed = ""
                    task_obj.put()
                    break

            #self.redirect('/')
            self.redirect('/view_each_tb?ID=' + str(url_ID))

        elif self.request.get('button') == 'Delete':
            url_ID = self.request.get("f_id")
            url_ID = long(url_ID)
            t_ID = self.request.get("t_id")
            t_ID = long(t_ID)

            index = int(self.request.get('index')) - 1

            #ind = int (self.request.get("ind"))

            tbd_key = ndb.Key('TaskBoard', url_ID)
            tbd_obj = tbd_key.get()

            task_key = ndb.Key('Task', t_ID)
            task_obj = task_key.get()

            del task_obj.title
            del task_obj.assigned_user
            del task_obj.due_date
            del task_obj.date_task_completed
            del task_obj.time_task_completed
            del task_obj.status
            del task_obj.word_status
            del task_obj.creator
            #task_obj.put()

            tbd_obj.tk_key.remove(task_key)

            tbd_obj.put()

            message = "Task deleted"

            self.redirect('/view_each_tb?ID=' + str(url_ID))

        else:
            self.redirect('/view_each_tb?ID=' + str(url_ID))
Example #19
0
    def get(self):
        self.response.headers['Content-Typ'] = 'text/html'

        # gets current user
        user = users.get_current_user()

        # gets id passed in the url
        id = self.request.get('id')

        #selection if no id is in url
        if id == '':
            #redirects to view taskboard page
            self.redirect('/viewtaskboard')

        else:

            # gets TaskBoard
            taskboard = TaskBoard.get_by_id(int(id))

            #task stats
            n_tasks = len(taskboard.tasks)
            n_ctasks = 0
            n_atasks = 0
            n_ctaskst = 0
            #calculate stats
            for i in taskboard.tasks:
                if i.completion == True:
                    n_ctasks += 1
                    today = datetime.date(datetime.now())
                    if datetime.date(i.completion_date) == today:
                        n_ctaskst += 1
                else:
                    n_atasks += 1

            # selection statement for user
            if user:

                #get user key
                user_key = ndb.Key('MyUser', user.user_id())
                #gets user
                myuser = user_key.get()

                #initializes permisiion
                permission = False

                taskboards_created_keys = myuser.taskboards_created

                #loops through taskboards created by user to find if user created current taskboard
                for i in taskboards_created_keys:
                    if i == taskboard.key:
                        permission = True

                #querys data store to find all users
                q = MyUser.query().fetch()

                # values to be rendered to the createtaskboard.html page
                template_values = {
                    'user': user,
                    'taskboard': taskboard,
                    'permission': permission,
                    'q': q,
                    'n_tasks': n_tasks,
                    'n_ctasks': n_ctasks,
                    'n_atasks': n_atasks,
                    'n_ctaskst': n_ctaskst
                }

                template = JINJA_ENVIRONMENT.get_template('taskboards.html')
                self.response.write(template.render(template_values))
            else:
                #if no user redirect back to home page
                self.redirect('/')
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'

        # pull the current user from the Request
        user = users.get_current_user()
        tb_list = []
        tb_id_list = []
        tb_userslist = []
        invited_list = []

        user = users.get_current_user()

        if user == None:
            url_string = 'login'
            url = users.create_login_url(self.request.uri)
            template_values = {
                'url_string': url_string,
                'url': url,
                'login_url': users.create_login_url(self.request.uri)
            }

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

        url_string = 'logout'
        url = users.create_logout_url(self.request.uri)

        id = user.user_id()
        myuser_key = ndb.Key('MyUser', id)
        myuser = myuser_key.get()

        print(myuser.tb_key)

        for n in myuser.tb_key:
            tboard = n.get()
            #if tboard == None:
            #tboard = TaskBoard()
            #tboard.put()

            logging.info("Debug message")
            print(n)
            logging.info("END")

            #tb_list.append(tboard)
            #tb_id_list.append(tboard.key.id())

        query = MyUser.query(
            ndb.AND(MyUser.email_address != myuser.email_address))

        #for n in query:
        #logging.info("START message")
        #print(n.email_address)
        #logging.info("End message")

        #for n in myuser.tb_key:
        #logging.info("Debug message")
        #print(n.get().tbd_name)
        #logging.info("END")
        #tb_userslist.append(n.get().tbd_name)

        #for n in myuser.invited_tb_list:
        #TaskBoard = n.get()
        #invited_list.append(TaskBoard)
        #invited_list.append(n.get().tbd_name)

        template_values = {
            'myuser': myuser,
            'user': user,
            #'tb_list' : tb_list,
            #'tboard' : tboard,
            'url_string': url_string,
            'url': url,
        }

        # pull the template file and ask jinja to render
        # it with the given template values
        template = JINJA_ENVIRONMENT.get_template('viewtaskboard.html')
        self.response.write(template.render(template_values))
Example #21
0
    def get(self):

        self.response.headers["Content-Type"] = "text/html"
        user = Services().get_current_user()
        myuser = None
        tweets = None
        edittweet = None

        if user:

            url = users.create_logout_url(self.request.uri)
            myuser_key = ndb.Key("MyUser", Services().get_current_user_id())
            myuser = myuser_key.get()

            if myuser == None:
                myuser = Services().create_user(user_id=user.user_id())

            user_name = self.request.GET.get("user_name")
            bio_text = self.request.GET.get("bio_text")

            if user_name != None and user_name != "" and bio_text != None and bio_text != "":

                user_query = MyUser.query(
                    MyUser.user_name == user_name).fetch()

                if len(user_query) > 0:
                    self.redirect("/")
                    return

                myuser.user_name = user_name
                myuser.bio_text = bio_text
                myuser.put()

            tweets = Tweet.query().order(-Tweet.time)
            search_type = self.request.GET.get("query_type")

            if search_type == "user" or search_type == "post":

                search_text = self.request.GET.get("search_text")

                if len(search_text) > 0:

                    if search_type == "user":
                        tweets = Services().search_by_user(text=search_text)
                    else:
                        tweets = Services().search_by_tweet(text=search_text)

            elif search_type == "Delete" or search_type == "Edit":

                query_type = self.request.GET.get("query_type")
                tweet_id = self.request.GET.get("tweet_id")

                if query_type == "Edit":
                    edittweet = Services().get_tweet(tweet_id=tweet_id)
                    tweets = Services().get_all_user_tweets()

                else:
                    Services().delete_tweet(tweet_id=tweet_id)
                    tweets = Services().get_all_user_tweets()

            else:
                tweets = Services().get_all_user_tweets()

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

        template_values = {
            "url": url,
            "myuser": myuser,
            "tweets": tweets,
            "edittweet": edittweet,
            "upload_url": blobstore.create_upload_url('/upload_photo')
        }

        template = JINJA_ENVIRONMENT.get_template("main.html")
        self.response.write(template.render(template_values))
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'

        user = users.get_current_user()
        myuser = ndb.Key('MyUser', user.user_id()).get()
        firstTime = myuser.username == None
        database = None
        if (not firstTime):
            database = ndb.Key('MyUserDatabase', myuser.username).get()
        warning_text = ''
        warning = False

        if (firstTime):
            if self.request.get('button') == 'Update':

                username = self.request.get('users_username').lower()
                name = self.request.get('users_name').lower()
                profile = self.request.get('users_profile').lower()

                query = MyUser.query(MyUser.username == username).fetch()
                warning = True
                if (username == ' none ' or username == ''
                        or username == None):
                    warning_text = 'Enter a valid username'
                elif (query != [] and query != None):
                    warning_text = 'This username is already taken'
                elif (name == ' none ' or name == '' or name == None):
                    warning_text = 'Please enter a valid name'
                elif (profile == ' none ' or profile == '' or profile == None):
                    warning_text = 'Please enter a valid profile'
                elif (len(profile) > 280):
                    warning_text = 'Max limit of profile is 280 characters'
                else:
                    warning = False
                    myuser.username = username
                    new_database = MyUserDatabase(id=username,
                                                  username=username,
                                                  profile=profile,
                                                  name=name)
                    myuser.put()
                    new_database.put()
                    self.redirect('/')

            elif self.request.get('button') == 'Cancel':
                warning = True
                warning_text = 'Please enter your details as it\'s your first time'

        else:
            if (self.request.get('button') == 'Update'):
                database = ndb.Key('MyUserDatabase', myuser.username).get()
                database.profile = self.request.get('users_profile')
                database.name = self.request.get('users_name')
                database.put()
                self.redirect('/')
            elif (self.request.get('button') == 'Cancel'):
                self.redirect('/')

        template_values = {
            'firstTime': firstTime,
            'database': database,
            'myuser': myuser,
            'warning': warning,
            'warning_text': warning_text,
            'none': ''
        }

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

        self.response.headers["Content-Type"] = "text/html"
        user = Definitions().get_current_user()
        myuser = None
        tweets = None
        edit_tweet = None

        if user:

            url = users.create_logout_url(self.request.uri)
            myuser_key = ndb.Key("MyUser", Definitions().get_current_user_id())
            myuser = myuser_key.get()
            user_name = self.request.GET.get("user_name")
            bio = self.request.GET.get("bio")

            if myuser == None:
                myuser = Definitions().create_user(user_id=user.user_id(),
                                                   email_address=user.email())

            if user_name != None and user_name != "" and bio != None and bio != "":

                user_query = MyUser.query(
                    MyUser.user_name == user_name).fetch()

                if len(user_query) > 0:
                    self.redirect("/")
                    return

                myuser.user_name = user_name
                myuser.bio = bio
                myuser.put()

            tweets = Tweet.query().order(-Tweet.time)
            search = self.request.GET.get("query")

            if search == "user" or search == "post":

                search_text = self.request.GET.get("search_text")

                if len(search_text) > 0:

                    if search == "user":
                        tweets = Definitions().search_by_user(text=search_text)
                    else:
                        tweets = Definitions().search_by_tweet(
                            text=search_text)

            elif search == "Delete" or search == "Edit":

                query = self.request.GET.get("query")
                tweet_id = self.request.GET.get("tweet_id")

                if query == "Edit":
                    edit_tweet = Definitions().get_tweet(tweet_id=tweet_id)
                else:
                    Definitions().delete_tweet(tweet_id=tweet_id)

            else:
                tweets = []
                for tweet in Tweet.query().order(-Tweet.time).fetch():
                    if tweet.user_id in myuser.following or tweet.user_id == myuser.key.id(
                    ):
                        tweets.append(tweet)

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

        template_values = {
            "url": url,
            "myuser": myuser,
            "edit_tweet": edit_tweet,
            "tweets": tweets,
            "upload_url": blobstore.create_upload_url('/upload_photo')
        }

        template = JINJA_ENVIRONMENT.get_template("main.html")
        self.response.write(template.render(template_values))
Example #24
0
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        action = self.request.get('button')
        user = users.get_current_user()
        if action == 'SignUp':
            name = self.request.get('name')
            dateofbirth = self.request.get('dateofbirth')
            bio = self.request.get('bio')

            stweets = UserTweets.query().fetch()

            myuser_key = ndb.Key('MyUser', user.user_id())
            myuser = myuser_key.get()
            myuser = MyUser(id=user.user_id(),
                            name=name,
                            dateofbirth=datetime.strptime(
                                dateofbirth, '%Y-%m-%d').date(),
                            bio=bio,
                            followers=[],
                            following=[])
            myuser.put()
            usertweets_key = ndb.Key('UserTweets', name)
            gettweets = usertweets_key.get()
            self.redirect('/')
        elif self.request.get('button') == 'Search':
            temp = []
            count = []

            result = self.request.get('Search')

            user = users.get_current_user()
            myuser_key = ndb.Key('MyUser', user.user_id())
            myuser = myuser_key.get()

            if result == '':
                self.redirect('/')
            else:
                name_search = MyUser.query(MyUser.name == result).fetch()
                search_tweet = UserTweets.query().fetch()

                if len(name_search) > 0 or len(search_tweet) > 0:

                    for tweet in search_tweet:
                        for i in tweet.tweets:
                            temp.append(i)
                    for i in range(len(temp)):
                        temp2 = temp[i].split(" ")
                        for j in temp2:
                            if (j in result):
                                search_tweet.append(temp[i])
                                break

                    template_values = {
                        'search_tweet': search_tweet,
                        'name_search': name_search
                    }
                    template = JINJA_ENVIRONMENT.get_template(
                        'twitterhome.html')
                    self.response.write(template.render(template_values))

        elif self.request.get('button') == 'Tweet':
            tweets = self.request.get('tweets')

            user = users.get_current_user()
            myuser_key = ndb.Key('MyUser', user.user_id())
            myuser = myuser_key.get()
            new_tweet = UserTweets(name=myuser.name, tweets=tweets)
            myuser.usertweets.append(new_tweet)
            myuser.put()
            new_tweet.put()
            self.redirect('/')
        elif self.request.get('button') == 'Delete tweet':
            index = int(self.request.get('index'))
            user = users.get_current_user()
            myuser_key = ndb.Key('MyUser', user.user_id())
            myuser = myuser_key.get()
            del myuser.usertweets[index]
            myuser.put()
            self.redirect('/')