Ejemplo n.º 1
0
    def get(self):

        # keep non-admin users away
        if not users.is_current_user_admin():
            self.redirect("/")

        # if user is an admin
        # render support page
        if users.is_current_user_admin():

            # get counselor, if new, then insert
            counselor = Counselor.get_or_insert(str(users.get_current_user().user_id()))

            # set default counselor name to user's nickname
            if not counselor.name:
                counselor.name = users.get_current_user().nickname()

            # update user status to 1 - ready for work!
            counselor.status = 1
            counselor.put()

            template_vars = {
                "app_name": settings.APP_NAME,
                "counselor": counselor,
                "logout_url": "/logout",
                "where": "Support",
            }

            self._output_template("support.html", **template_vars)
Ejemplo n.º 2
0
    def get(self):

        # keep non-admin users away
        if not users.is_current_user_admin():
            self.redirect('/')

        # if user is an admin
        # render support page
        if users.is_current_user_admin():

            # get counselor, if new, then insert
            counselor = Counselor.get_or_insert(
                str(users.get_current_user().user_id()))

            # set default counselor name to user's nickname
            if not counselor.name:
                counselor.name = users.get_current_user().nickname()

            # update user status to 1 - ready for work!
            counselor.status = 1
            counselor.put()

            template_vars = {
                'app_name': settings.APP_NAME,
                'counselor': counselor,
                'logout_url': '/logout',
                'where': 'Support'
            }

            self._output_template('support.html', **template_vars)
Ejemplo n.º 3
0
    def get(self):
        counselor = Counselor.get_by_key_name(str(self.request.get("key")))

        if counselor.avatar:
            self.response.headers["Content-Type"] = "image/jpg"
            self.response.out.write(counselor.avatar)
        else:
            self.response.headers["Content-Type"] = "image/jpg"
            self.response.out.write(urlfetch.Fetch("https://second-friend.appspot.com/static/img/avatar.jpg").content)
Ejemplo n.º 4
0
 def get(self):
     uuid = self.request.get('channel') #self.request.get('uuid')
     channel = self.request.get('channel')
     
     # check if the kid channel already has an assigned counselor
     counselors = Counselor.all()
     counselors.filter('status >', 0)
     counselors.filter('channels IN', [channel])
     counselors = counselors.fetch(1)
             
     if len(counselors):
         logging.info('already assigned')
         
         counselor = counselors[0]
         
         # publish the counselor profile
         info = pubnub.publish({
             #'channel' : 'kid-'+ kid,
             'channel': channel,
             'message' : {
                 'type': 'system',
                 'timestamp': '',
                 'payload': {
                     'action': 'counselor',
                     'avatar': 'https://second-friend.appspot.com/counselor/avatar?key='+ counselor.key().name(),
                     'name': counselor.name,
                     'id': counselor.key().name(),
                 }
             }
         })
         
         self.response.headers['Access-Control-Allow-Origin'] = '*'
         self.response.set_status(200)
         self.response.out.write('already assigned')
         return
         
     # add to task queue
     taskqueue.add(queue_name = 'QueueRoute', url = '/route/assign', params = { 
         'uuid': uuid, 
         'channel': channel,
     }, method = 'GET', )
     
     # publish a message
     info = pubnub.publish({
         #'channel' : 'kid-'+ channel,
         'channel': channel,
         'message' : {
             'type': 'status',
             'sender': 'SecondFriend',
             'timestamp': '',
             'payload': 'Hello! You will be assigned to a counselor shortly.',
         }
     })
     
     self.response.headers['Access-Control-Allow-Origin'] = '*'
     self.response.set_status(202)
     self.response.out.write('queued')
Ejemplo n.º 5
0
 def get(self):
     # update user status to 0
     counselor = Counselor.get_by_key_name(str(users.get_current_user().user_id()))
     
     # set status to 0, unavailable
     if counselor:
         counselor.status = 0
         counselor.put()
     
     self.redirect(users.create_logout_url('/'))  
Ejemplo n.º 6
0
    def get(self):
        uuid = self.request.get('channel') #self.request.get('uuid')
        channel = self.request.get('channel')
        purge = self.request.get('purge') # Counselor.key().name()
        
        counselor = False
        if purge:
            counselor = Counselor.get_by_key_name(purge)
        else:
            counselors = Counselor.all()
            #counselors.filter('status >', 0)
            #counselors.filter('channels IN', [channel])
            counselors = counselors.fetch(10)
        
        
            for c in counselors:
                if channel in c.channels:
                    counselor = c
                    break

        if counselor:
            if not purge and channel in counselor.channels:
                counselor.channels.remove(channel)
            
            if purge:
                counselor.channels = []
                
            counselor.put()
        
            # publish the command
            info = pubnub.publish({
                'channel' : 'counselor-'+ counselor.key().name(),
                'message' : {
                    'action': 'purge' if purge else 'remove',
                    'uuid': uuid,
                    'channel' : channel
                }
            })
        
        self.response.headers['Access-Control-Allow-Origin'] = '*'
        self.response.set_status(200)
        self.response.out.write('removed')
Ejemplo n.º 7
0
    def get(self):
        uuid = self.request.get('channel')  #self.request.get('uuid')
        channel = self.request.get('channel')
        purge = self.request.get('purge')  # Counselor.key().name()

        counselor = False
        if purge:
            counselor = Counselor.get_by_key_name(purge)
        else:
            counselors = Counselor.all()
            #counselors.filter('status >', 0)
            #counselors.filter('channels IN', [channel])
            counselors = counselors.fetch(10)

            for c in counselors:
                if channel in c.channels:
                    counselor = c
                    break

        if counselor:
            if not purge and channel in counselor.channels:
                counselor.channels.remove(channel)

            if purge:
                counselor.channels = []

            counselor.put()

            # publish the command
            info = pubnub.publish({
                'channel':
                'counselor-' + counselor.key().name(),
                'message': {
                    'action': 'purge' if purge else 'remove',
                    'uuid': uuid,
                    'channel': channel
                }
            })

        self.response.headers['Access-Control-Allow-Origin'] = '*'
        self.response.set_status(200)
        self.response.out.write('removed')
Ejemplo n.º 8
0
    def get(self):
        # update user status to 0
        counselor = Counselor.get_by_key_name(
            str(users.get_current_user().user_id()))

        # set status to 0, unavailable
        if counselor:
            counselor.status = 0
            counselor.put()

        self.redirect(users.create_logout_url('/'))
Ejemplo n.º 9
0
    def post(self):
        counselor = Counselor.get_or_insert(str(users.get_current_user().user_id()))

        if self.request.get("avatar"):
            counselor.avatar = db.Blob(images.resize(self.request.get("avatar"), 90, 90))

        counselor.name = self.request.get("name")
        counselor.expertises = self.request.POST.getall("expertises")
        counselor.put()

        self.redirect("/counselor/edit?saved=1")
Ejemplo n.º 10
0
    def get(self):
        counselor = Counselor.get_by_key_name(str(self.request.get('key')))

        if counselor.avatar:
            self.response.headers['Content-Type'] = "image/jpg"
            self.response.out.write(counselor.avatar)
        else:
            self.response.headers['Content-Type'] = "image/jpg"
            self.response.out.write(
                urlfetch.Fetch(
                    'https://second-friend.appspot.com/static/img/avatar.jpg').
                content)
Ejemplo n.º 11
0
    def post(self):
        counselor = Counselor.get_or_insert(
            str(users.get_current_user().user_id()))

        if self.request.get('avatar'):
            counselor.avatar = db.Blob(
                images.resize(self.request.get('avatar'), 90, 90))

        counselor.name = self.request.get('name')
        counselor.expertises = self.request.POST.getall('expertises')
        counselor.put()

        self.redirect('/counselor/edit?saved=1')
Ejemplo n.º 12
0
    def get(self):

        # if user is not logged in yet
        # show the welcome page
        if not users.get_current_user():
            # welcome page
            template_vars = {'where': 'Index', 'login_url': '/login'}
            self._output_template('welcome.html', **template_vars)
            return

        # user is logged in but not an admin
        # show the unauthorized page
        if not users.is_current_user_admin():
            # unauthorized page
            template_vars = {
                'where': 'Administration',
                'email': users.get_current_user().email(),
                'logout_url': '/logout',
            }
            self._output_template('unauthorized.html', **template_vars)
            return

        # user is an admin - redirect to support page
        # render support page
        if users.is_current_user_admin():

            self.redirect('/support')

            # get counselor, if new, then insert
            counselor = Counselor.get_or_insert(
                str(users.get_current_user().user_id()))

            # set default counselor name
            if not counselor.name:
                counselor.name = users.get_current_user().nickname()

            # update user status to 1
            counselor.status = 1
            counselor.put()

            template_vars = {
                'app_name': settings.APP_NAME,
                'counselor': counselor,
                'logout_url': '/logout',
                'where': 'Support'
            }

            self._output_template('support.html', **template_vars)
Ejemplo n.º 13
0
    def get(self):
        counselor = Counselor.get_or_insert(
            str(users.get_current_user().user_id()))

        # list of expertises
        _expertises = [
            'Cyberbully', 'Child Rights', 'Sexual Abuse', 'Teen Relationship',
            'Drugs', 'School Stress', 'Parenting'
        ]

        template_vars = {
            'saved': self.request.get('saved'),
            'id': str(users.get_current_user().user_id()),
            'counselor': counselor,
            '_expertises': _expertises
        }

        self._output_template('counselor-edit.html', **template_vars)
Ejemplo n.º 14
0
    def get(self):
        
        # if user is not logged in yet
        # show the welcome page
        if not users.get_current_user():
            # welcome page
            template_vars = {'where': 'Index', 'login_url': '/login'}
            self._output_template('welcome.html', **template_vars)
            return

        # user is logged in but not an admin
        # show the unauthorized page
        if not users.is_current_user_admin():
            # unauthorized page
            template_vars = {'where': 'Administration', 'email': users.get_current_user().email(), 'logout_url': '/logout', }
            self._output_template('unauthorized.html', **template_vars)
            return
            
        # user is an admin - redirect to support page
        # render support page    
        if users.is_current_user_admin():

            self.redirect('/support')

            # get counselor, if new, then insert
            counselor = Counselor.get_or_insert(str(users.get_current_user().user_id()))
        
            # set default counselor name
            if not counselor.name:
                counselor.name = users.get_current_user().nickname()

            # update user status to 1
            counselor.status = 1
            counselor.put()

            template_vars = {
                'app_name': settings.APP_NAME,
                'counselor': counselor,
                'logout_url': '/logout',
                'where': 'Support'
            }

            self._output_template('support.html', **template_vars)
Ejemplo n.º 15
0
    def get(self):
        counselor = Counselor.get_or_insert(str(users.get_current_user().user_id()))

        # list of expertises
        _expertises = [
            "Cyberbully",
            "Child Rights",
            "Sexual Abuse",
            "Teen Relationship",
            "Drugs",
            "School Stress",
            "Parenting",
        ]

        template_vars = {
            "saved": self.request.get("saved"),
            "id": str(users.get_current_user().user_id()),
            "counselor": counselor,
            "_expertises": _expertises,
        }

        self._output_template("counselor-edit.html", **template_vars)
Ejemplo n.º 16
0
    def get(self):
        uuid = self.request.get('channel')  #self.request.get('uuid')
        channel = self.request.get('channel')

        # check available counselors
        counselors = Counselor.all()
        counselors.filter('status >', 0)
        counselors = counselors.fetch(3)

        counselor = counselors[0]

        # assign to counselor with the least channel
        for c in counselors:
            if (len(c.channels) < len(counselor.channels)):
                counselor = c

        # no counselor available
        if not len(counselors):
            logging.info('no counselor available')

            self.response.headers['Access-Control-Allow-Origin'] = '*'
            self.response.set_status(500)
            self.response.out.write('no counselor available')
            return

        # update the counselor model - channels
        if (channel not in counselor.channels):
            counselor.channels.append(channel)
            counselor.put()

        # assign and inform the counselor
        # publish the command for counselor screen
        info = pubnub.publish({
            'channel': 'counselor-' + counselor.key().name(),
            'message': {
                'action': 'create',
                'uuid': uuid,
                'channel': channel
            }
        })

        # publish the counselor profile
        info = pubnub.publish({
            #'channel' : 'kid-'+ kid,
            'channel': channel,
            'message': {
                'type': 'system',
                'timestamp': '',
                'payload': {
                    'action':
                    'counselor',
                    'avatar':
                    'https://second-friend.appspot.com/counselor/avatar?key=' +
                    counselor.key().name(),
                    'name':
                    counselor.name,
                    'id':
                    counselor.key().name(),
                }
            }
        })

        # publish a message
        info = pubnub.publish({
            #'channel' : 'kid-'+ channel,
            'channel': channel,
            'message': {
                'type': 'status',
                'sender': 'SecondFriend',
                'payload': 'You have been assigned a counselor.',
            }
        })

        logging.info(counselor.name)
        logging.info(counselor.key().name())

        self.response.headers['Access-Control-Allow-Origin'] = '*'
        self.response.set_status(200)
        self.response.out.write('assigned')
Ejemplo n.º 17
0
    def get(self):
        uuid = self.request.get('channel')  #self.request.get('uuid')
        channel = self.request.get('channel')

        # check if the kid channel already has an assigned counselor
        counselors = Counselor.all()
        counselors.filter('status >', 0)
        counselors.filter('channels IN', [channel])
        counselors = counselors.fetch(1)

        if len(counselors):
            logging.info('already assigned')

            counselor = counselors[0]

            # publish the counselor profile
            info = pubnub.publish({
                #'channel' : 'kid-'+ kid,
                'channel': channel,
                'message': {
                    'type': 'system',
                    'timestamp': '',
                    'payload': {
                        'action':
                        'counselor',
                        'avatar':
                        'https://second-friend.appspot.com/counselor/avatar?key='
                        + counselor.key().name(),
                        'name':
                        counselor.name,
                        'id':
                        counselor.key().name(),
                    }
                }
            })

            self.response.headers['Access-Control-Allow-Origin'] = '*'
            self.response.set_status(200)
            self.response.out.write('already assigned')
            return

        # add to task queue
        taskqueue.add(
            queue_name='QueueRoute',
            url='/route/assign',
            params={
                'uuid': uuid,
                'channel': channel,
            },
            method='GET',
        )

        # publish a message
        info = pubnub.publish({
            #'channel' : 'kid-'+ channel,
            'channel': channel,
            'message': {
                'type': 'status',
                'sender': 'SecondFriend',
                'timestamp': '',
                'payload':
                'Hello! You will be assigned to a counselor shortly.',
            }
        })

        self.response.headers['Access-Control-Allow-Origin'] = '*'
        self.response.set_status(202)
        self.response.out.write('queued')
Ejemplo n.º 18
0
    def get(self):
        uuid = self.request.get('channel') #self.request.get('uuid')
        channel = self.request.get('channel')
        
        # check available counselors
        counselors = Counselor.all()
        counselors.filter('status >', 0)
        counselors = counselors.fetch(3)
        
        counselor = counselors[0]
        
        # assign to counselor with the least channel
        for c in counselors:
            if(len(c.channels) < len(counselor.channels)):
                counselor = c
                        
        # no counselor available
        if not len(counselors):
            logging.info('no counselor available')
            
            self.response.headers['Access-Control-Allow-Origin'] = '*'
            self.response.set_status(500)
            self.response.out.write('no counselor available')
            return

        # update the counselor model - channels
        if (channel not in counselor.channels):
            counselor.channels.append(channel)
            counselor.put()
                    
        # assign and inform the counselor
        # publish the command for counselor screen
        info = pubnub.publish({
            'channel' : 'counselor-'+ counselor.key().name(),
            'message' : {
                'action': 'create',
                'uuid': uuid,
                'channel' : channel
            }
        })

        # publish the counselor profile
        info = pubnub.publish({
            #'channel' : 'kid-'+ kid,
            'channel': channel,
            'message' : {
                'type': 'system',
                'timestamp': '',
                'payload': {
                    'action': 'counselor',
                    'avatar': 'https://second-friend.appspot.com/counselor/avatar?key='+ counselor.key().name(),
                    'name': counselor.name,
                    'id': counselor.key().name(),
                }
            }
        })
        
        # publish a message
        info = pubnub.publish({
            #'channel' : 'kid-'+ channel,
            'channel': channel,
            'message' : {
                'type': 'status',
                'sender': 'SecondFriend',
                'payload': 'You have been assigned a counselor.',
            }
        })
        
        logging.info(counselor.name)
        logging.info(counselor.key().name())

        self.response.headers['Access-Control-Allow-Origin'] = '*'
        self.response.set_status(200)
        self.response.out.write('assigned')