Exemple #1
0
    def get (self):
        tool_user, db_user = ADayThere.tool_user ()

        if not ADayThere.admin_user (db_user):
            self.response.status = 401
            self.response.write ("Unauthorized")
            return

        adaythere = ADayThere ()
        adaythere.add_meta_tags ([
            { "charset":"UTF-8" },
            { "http-equiv":"X-UA-Compatible", "content":"IE=edge" },
            { "name":"viewport", "content":"initial-scale=1"}
        ])

        adaythere.add_links ([
            { "rel":"stylesheet", "href":"css/bootstrap.css" },
            { "rel":"stylesheet", "href":"css/adaythere.css" }
        ])
        
        adaythere.add_script_tags_for_body ([
            { "src":"js/jquery-1.11.0-beta2.js" },
            { "src":"js/angular/angular.min.js" },
            { "src":"js/angular/angular-route.min.js" },
            { "src":"js/ui-bootstrap-tpls-0.10.0.min.js" },
            { "src":"js/adaythere.js" }
        ])

        
        adaythere.open_element ("header", {"id":"page_header"})
        adaythere.open_element ("h1", {"id":"page_heading"}, "A Day There - Administration Page")
        adaythere.close_element ("h1")
        adaythere.open_element ("nav")
        adaythere.append_to_element ("")
        adaythere.close_element ("nav")
        adaythere.close_element ("header")

        adaythere.open_element ("section", {"ng-controller":"adminCtrl", "style":"width:600px;margin:0px auto;"})

        adaythere.open_element ("div", {"id":"admin_profile_div"})

        type = self.request.get ('type', default_value=None)

        if type is not None:
            if type == 'profiles':
                self.get_profile_form (adaythere)
            elif type == 'days':
                self.get_days_form (adaythere)

        adaythere.close_element ("div")

        adaythere.close_element ("section")

        adaythere.open_element ("footer", {"id":"page_footer"})
        adaythere.open_element ("p", None, "© 2014 SoftSprocket")
        adaythere.close_element ("p")
        adaythere.close_element ("footer")

        self.response.status = 200
        self.response.write (adaythere.get ())
Exemple #2
0
    def get (self):
        
        tool_user, db_user = ADayThere.tool_user ()

        if not tool_user or not ADayThere.admin_user (db_user):
            self.response.status = 401 
            self.response.write ("Unauthorized")
            return

        query = User.query ()
        if 'name' in self.request.GET.keys ():
            name = self.request.GET['name']
            if name != '':
                query = query.filter (User.name == name) 

        if 'email' in self.request.GET.keys ():
            email = self.request.GET['email']
            if email != '':
                query = query.filter (User.email == email)

        if 'user_id' in self.request.GET.keys ():    
            uid = self.request.GET['user_id']
            if uid != '':
                query = query.filter (User.user_id == uid)


        limit = self.request.get ('limit', None)
        if limit is None:
            limit = ProfilesHandler.max_limit

        cursor = ndb.Cursor (urlsafe=self.request.get ('cursor'))

        users, cursor, more = query.fetch_page (int (limit), start_cursor=cursor)

        users_arr = []

        for each in users:
            u = self.__build_user (each)
            users_arr.append (u)

        safe_cursor = ''
        if cursor:
            safe_cursor = cursor.urlsafe ()

        resp_obj = {
            "users": users_arr,
            "cursor": safe_cursor,
            "more": more
        }

        resp = json.dumps (resp_obj)
        self.response.write (resp)
Exemple #3
0
    def get (self):
        
        tool_user, db_user = ADayThere.tool_user ()

        if not ADayThere.admin_user (db_user):
            self.response.status = 401
            self.response.write ("Unauthorized")
            return

        query = Day.query ()
        if 'name' in self.request.GET.keys ():
            name = self.request.GET['name']
            if name != '':
                query = query.filter (Day.name == name) 

        if 'title' in self.request.GET.keys ():
            title = self.request.GET['title']
            if title != '':
                query = query.filter (Day.title == title)

        if 'locale' in self.request.GET.keys ():    
            locale = self.request.GET['locale']
            if locale != '':
                query = query.filter (Day.full_locality == locale)

        limit = self.request.get ('limit', None)
        if limit is None:
            limit = DaysHandler.max_limit

        cursor = ndb.Cursor (urlsafe=self.request.get ('cursor'))

        days, cursor, more = query.fetch_page (int (limit), start_cursor=cursor)

        days_arr = []

        for each in days:
            d = self.__build_day (each)
            days_arr.append (d)

        safe_cursor = ''
        if cursor:
            safe_cursor = cursor.urlsafe ()

        resp_obj = {
            "days": days_arr,
            "cursor": safe_cursor,
            "more": more
        }

        resp = json.dumps (resp_obj)
        self.response.write (resp)
Exemple #4
0
    def __init__(self, db_user):
        admin_menu = ""

        tool_user, holder = ADayThere.tool_user()

        if ADayThere.admin_user(db_user):
            admin_menu = """
                <li class="dropdown" ng-controller="adminCtrl">
                    <a href="/admin" class="dropdown-toggle">
                        Admin
                    </a>
                    <ul class="dropdown-menu adt-nav-menu-button">
                        <a href="/admin?type=profiles">profiles</a>
                        <a href="/admin?type=days">days</a>
                    </ul>
                </li>
            """

        self.html = """
            <li class="dropdown" ng-controller="loginCtrl">
                <a href ng-click="googlelogout()" class="dropdown-toggle">
                    Logout
                </a>
            </li>
            <li class="dropdown" ng-controller="profileCtrl">
                <a href class="dropdown-toggle" id="profile_ctrl_menu_toggle">
                    {0}
                </a>
                <ul id="tool_user_related_menu" class="dropdown-menu adt-nav-menu-button">
        """.format(
            db_user.name
        )

        if tool_user:
            self.html += LoggedInNavView.tool_user_menus()
        else:
            self.html += LoggedInNavView.non_tool_user_menus()

        self.html += """
                </ul>
            </li>
                {0}
                {1}
                {2}
            <a href popover-placement="bottom" popover-trigger="mouseenter" popover="Click links to see drop down menus">?</a>
        """.format(
            get_help_menu(), get_contact_menu(), admin_menu
        )
Exemple #5
0
    def post (self):
        
        tool_user, db_user = ADayThere.tool_user ()

        if not ADayThere.admin_user (db_user):
            self.response.status = 401 
            self.response.write ("Unauthorized")
            return

        sent_day = json.loads (self.request.body)
    
        day_query = Day.query_user_title (sent_day['userid'], sent_day['title'])
        day = day_query.get ()
        if day is None:
            self.response.status = 404
            self.response.write ("Not Found")
            return

        day.key.delete ()

        self.response.status = 200
        self.response.write ("OK")
Exemple #6
0
    def post (self):
        
        tool_user, db_user = ADayThere.tool_user ()

        if not tool_user or not ADayThere.admin_user (db_user):
            self.response.status = 401 
            self.response.write ("Unauthorized")
            return

        user = json.loads (self.request.body)
        record = User.query_user_id (user['user_id'])
        
        if 'type' not in self.request.GET.keys ():
            self.response.status = 400
        else:
            tp = self.request.GET['type']
            if tp == 'ban':
                record.banned = user['banned']
                record.put ()
                self.response.status = 200
            else:
                self.response.status = 400