def get(self):
        user = users.get_current_user()
        if not user:
            return self.redirect('/admin/index')
        page = self.request.get('page')
        zoomFlg = self.request.get('zoomFlg')
        searchLabel = self.request.get('searchLabel')

        try:
            page = int(page) - 1
        except:
            page = 0
        if searchLabel != "":
            datas = Picture.gql("WHERE label =:1", searchLabel)
        else:
            datas = Picture.all()

        paginator = ObjectPaginator(datas, PAGE)
        if page >= paginator.pages:
            page = paginator.pages - 1
        params = {
            "datas": paginator.get_page(page),
            "pages": range(1, paginator.pages + 1),
            "page": page + 1,
            'zoomFlg': zoomFlg,
            'searchLabel': searchLabel
        }
        fpath = os.path.join(os.path.dirname(__file__),
                             'template/admin/picture', 'list.html')
        html = template.render(fpath, params)
        self.response.out.write(html)

        return
Пример #2
0
    def get(self):
        user = users.get_current_user()
        if user is None:
            return self.redirect('/index')
        else:
            logout_link = users.create_logout_url(PROTOCOLHTTP + DOMAIN +
                                                  "/index")
        page = self.request.get('page')
        zoomFlg = self.request.get('zoomFlg')
        searchLabel = self.request.get('searchLabel')
        picturHandlerePage = self.request.get('picturHandlerePage')
        delFlg = self.request.get('delFlg')

        cookie = SimpleCookie(os.environ.get('HTTP_COOKIE', ''))
        if delFlg != "1":
            if searchLabel != "":
                cookie['picturHandlerePage'] = ""
                cookie['searchLabel'] = searchLabel.encode('utf-8')
                cookie['searchLabel']['expires'] = 3600
                print cookie.output()
            else:
                if cookie.has_key('searchLabel'):
                    searchLabel = cookie['searchLabel'].value.decode('utf-8')
        else:
            searchLabel = ""
            picturHandlerePage = ""
            cookie['searchLabel'] = ""
            cookie['picturHandlerePage'] = ""
            print cookie.output()

        #############PICTURE#######################

        if picturHandlerePage == '':
            if cookie.has_key('picturHandlerePage'):
                picturHandlerePage = cookie['picturHandlerePage'].value.decode(
                    'utf-8')
        else:
            cookie['picturHandlerePage'] = picturHandlerePage.encode('utf-8')
            cookie['picturHandlerePage']['expires'] = 3600
            print cookie.output()
        try:
            picturHandlerePage = int(picturHandlerePage) - 1
        except:
            picturHandlerePage = 0

        email = user.email()
        userData = db.GqlQuery("SELECT * FROM User WHERE email='" + email +
                               "'")
        for user in userData:
            userid = user.key().id()
        userDatas = User.get_by_id(long(userid))
        userPictureDatas = userDatas.picture_set

        datas = list()
        keyList = list()
        for PictureData in userPictureDatas:
            keyList.append(PictureData.key().id())
        if searchLabel != "":
            PictureDatas = Picture.gql("WHERE label =:1", searchLabel)
            for PictureData in PictureDatas:
                if PictureData.key().id() in keyList:
                    datas.append(PictureData)
        else:
            for upd in userPictureDatas:
                datas.append(upd)
        datas.sort(key=operator.attrgetter('registerDate'))
        datas.reverse()

        pictureCount = len(datas)
        pagerFlg = 0
        if pictureCount > PAGE:
            pagerFlg = 1

        lastPage = int(math.ceil(float(pictureCount) / PAGE))
        if picturHandlerePage > lastPage:
            picturHandlerePage = lastPage
        #pager
        #now page picturepage+1
        #last page paginator.pages+1
        page1 = 1
        if picturHandlerePage + 1 > 2:
            page1 = picturHandlerePage + 1 - 1
        elif picturHandlerePage + 1 > 3:
            page1 = picturHandlerePage + 1 - 2
        if picturHandlerePage + 1 == lastPage + 1:
            page1 = page1 - 3
        elif picturHandlerePage == lastPage + 1:
            page1 = page1 - 2

        if page1 < 2:
            page1 = 2

        pages = range(page1 - 1, lastPage + 1)

        paginator = ObjectPaginator(datas, PAGE)
        if picturHandlerePage >= paginator.pages:
            picturHandlerePage = paginator.pages - 1
        if user:
            loginFlg = 1

        params = {
            "datas": paginator.get_page(picturHandlerePage),
            "pages": pages,
            "page": picturHandlerePage + 1,
            "prev": picturHandlerePage,
            "next": picturHandlerePage + 2,
            "pagerFlg": pagerFlg,
            "lastpage": lastPage,
            'zoomFlg': zoomFlg,
            'searchLabel': searchLabel,
            'loginFlg': loginFlg,
            'logout_link': logout_link
        }

        fpath = os.path.join(os.path.dirname(__file__),
                             'template/user/picture', 'list.html')
        html = template.render(fpath, params)
        self.response.out.write(html)

        return