Ejemplo n.º 1
0
    def GET(self):
        query = web.input(p=0, curpage=1)
        try:
            curpage = int(query.curpage)  # 当前页
            p = int(query.p)
        except:
            return web.notfound("not found the page")

        if p == 0:
            articles_se = session.query(Article).filter_by(published=True).order_by(Article.addTime.desc())
            articles_count = articles_se.count()

            offset = (curpage - 1) * config.HOME_PAGE_LEN
            p = divmod(articles_count, config.HOME_PAGE_LEN)
            if p[1] > 0:
                pagecount = p[0] + 1
            else:
                pagecount = 1
            articles = articles_se.limit(config.HOME_PAGE_LEN).offset(offset).all()
            pages = util.pages(
                pagecount, curpage, 10, "&".join("%s=%s" % (a, b) for a, b in query.items() if a != "curpage")
            )
            return render_blog.default(locals(), self)
        else:
            article = session.query(Article).filter_by(id=p).first()
            comments = article.comments

            offset = (curpage - 1) * config.COMMENT_PAGE_LEN
            p = divmod(len(comments), config.COMMENT_PAGE_LEN)
            if p[1] > 0:
                pagecount = p[0] + 1
            else:
                pagecount = 1

            comments = comments[offset : offset + config.COMMENT_PAGE_LEN - 1]
            pages = util.pages(
                pagecount,
                curpage,
                10,
                "&".join("%s=%s" % (a, b) for a, b in query.items() if a != "curpage") + "#comment",
            )
            cookie = {
                "author": web.cookies(author="").author,
                "email": web.cookies(email="").email,
                "weburl": web.cookies(weburl="").weburl,
            }
            if article.template:
                return (web.template.frender("templates/%s" % article.template))(locals(), self)
            else:
                return render_blog.article_detail(locals(), self)
Ejemplo n.º 2
0
    def GET(self, f_year):
        query = web.input(curpage=1)
        curpage = query.curpage

        list_title = u"%s年" % (f_year)
        list_description = list_title
        list_keywords = list_title
        articles = (
            session.query(Article)
            .filter("date_format(addTime,'%Y') = '" + f_year + "'")
            .order_by(Article.addTime.desc())
        )

        offset = (curpage - 1) * config.COMMENT_PAGE_LEN
        p = divmod(articles.count(), config.COMMENT_PAGE_LEN)
        if p[1] > 0:
            pagecount = p[0] + 1
        else:
            pagecount = 1
        articles = articles.limit(config.COMMENT_PAGE_LEN).offset(offset).all()
        pages = util.pages(
            pagecount, curpage, 10, "&".join("%s=%s" % (a, b) for a, b in query.items() if a != "curpage") + "#comment"
        )
        cookie = {
            "author": web.cookies(author="").author,
            "email": web.cookies(email="").email,
            "weburl": web.cookies(weburl="").weburl,
        }
        return render_blog.article_list(locals(), self)
Ejemplo n.º 3
0
 def GET(self, slug):
     query = web.input(curpage=1)
     curpage = query.curpage
     if slug:
         article = session.query(Article).filter(Article.slug == slug).first()
         comments = article.comments
         offset = (curpage - 1) * config.COMMENT_PAGE_LEN
         p = divmod(len(comments), config.COMMENT_PAGE_LEN)
         if p[1] > 0:
             pagecount = p[0] + 1
         else:
             pagecount = 1
         comments = comments[offset : offset + config.COMMENT_PAGE_LEN - 1]
         pages = util.pages(
             pagecount,
             curpage,
             10,
             "&".join("%s=%s" % (a, b) for a, b in query.items() if a != "curpage") + "#comment",
         )
         cookie = {
             "author": web.cookies(author="").author,
             "email": web.cookies(email="").email,
             "weburl": web.cookies(weburl="").weburl,
         }
         return render_blog.article_detail(locals(), self)
     else:
         return web.notfound("not found the page")
Ejemplo n.º 4
0
def manage_orders():
    q = g.db.query(Order).order_by(Order.status.asc(), Order.id.desc())
    page_size = 20
    total = q.count()
    start = (int(request.args.get("p", "1")) - 1) * page_size
    orders = q[start:start + page_size]
    pids = pages(total, page_size)
    return render_template("manage_order.html", **locals())
Ejemplo n.º 5
0
def manage_orders():
    q = g.db.query(Order).order_by(Order.status.asc(),Order.id.desc())
    page_size = 20
    total = q.count()
    start = (int(request.args.get("p","1")) - 1) * page_size
    orders = q[start:start+page_size]
    pids = pages(total,page_size)
    return render_template("manage_order.html", **locals())
Ejemplo n.º 6
0
def order_list():
    user = get_user_login(g.current_login_id)
    q = g.db.query(Order).filter(Order.user_id==user.id).order_by(Order.id.desc())
    page_size = 20
    total = q.count()
    start = (int(request.args.get("p","1")) - 1) * page_size
    orders = q[start:start+page_size]
    pids = pages(total,page_size)
    return render_template("orders.html",**locals())
Ejemplo n.º 7
0
def order_list():
    user = get_user_login(g.current_login_id)
    q = g.db.query(Order).filter(Order.user_id == user.id).order_by(
        Order.id.desc())
    page_size = 20
    total = q.count()
    start = (int(request.args.get("p", "1")) - 1) * page_size
    orders = q[start:start + page_size]
    pids = pages(total, page_size)
    return render_template("orders.html", **locals())
Ejemplo n.º 8
0
    def GET(self):
        query = web.input(curpage=1)
        curpage = int(query.curpage)  # 当前页

        medias_se = session.query(Media).order_by(Media.addTime.desc())
        medias_count = medias_se.count()

        offset = (curpage - 1) * config.DEFAULT_PAGE_LEN
        p = divmod(medias_count, config.DEFAULT_PAGE_LEN)
        if p[1] > 0:
            pagecount = p[0] + 1
        else:
            pagecount = 1
        medias = medias_se.limit(config.DEFAULT_PAGE_LEN).offset(offset).all()
        pages = util.pages(
            pagecount, curpage, 10, "&".join("%s=%s" % (a, b) for a, b in query.items() if a != "curpage")
        )
        return render_manage.manage_media(locals(), self)
Ejemplo n.º 9
0
 async def allshops(self, ctx: commands.Context):
     """
     Shows all shops for the server
     """
     await ctx.message.delete()
     all_gen = [(shop.name, shop.items, shop.user_id) for shop in self.shops
                if shop.guild_id == ctx.guild.id]
     if not all_gen:
         await ctx.send(
             embed=discord.Embed(title="No shops set", colour=0xFF0000))
         return
     await (BotEmbedPaginator(
         ctx,
         pages(numbered([
             f"Name: {tup[0]} | Items: {tup[1]} | Owner: {ctx.guild.get_member(tup[2]).display_name}"
             for tup in all_gen
         ]),
               n=10,
               title=f'Coordinates for {ctx.guild.name}'))).run()
Ejemplo n.º 10
0
 async def nearme(self,
                  ctx: commands.Context,
                  x: int,
                  z: int,
                  distance: int = 100):
     """
     Returns the coords and name of people near your base
     **e.g**:`$nearme <x> <z> <distance>`
     __<distance> defaults to 100__
     """
     await ctx.message.delete()
     people_gen = [
         (ucrd.base_coords, ) for ucrd in self.usercoords
         if ucrd.guild_id == ctx.guild.id and ucrd.user_id != ctx.author.id
     ]
     int_people_coords = []
     for tup in people_gen:
         int_people_coords.append(tuple(tup[0].split('/')))
     matched_coords = []
     for tup in int_people_coords:
         if await calculate_distance(x, z, int(tup[0]), int(
                 tup[1])) <= distance:
             matched_coords.append(f'{tup[0]}/{tup[1]}/{tup[2]}')
     match_gen = [(ucoords.user_id, ucoords.base_coords, ucoords.name)
                  for ucoords in self.usercoords
                  if ucoords.guild_id == ctx.guild.id
                  and ucoords.base_coords in matched_coords]
     if not match_gen:
         await ctx.send(
             embed=discord.Embed(title='No coords found', colour=0xFF0000))
         return
     await (BotEmbedPaginator(
         ctx,
         pages(
             numbered([
                 f"User: {ctx.guild.get_member(tup[0]).display_name}\n"
                 f"Coords: {tup[1]} | Name: {tup[2]}" for tup in match_gen
             ]),
             n=10,
             title=
             f"People near your coords {x}/{z}\nCoords are in format x/z/y")
     )).run()
Ejemplo n.º 11
0
 async def allcoords(self, ctx: commands.Context):
     """
     Returns a list of the coords from all users
     """
     await ctx.message.delete()
     embed_error = discord.Embed(title='No coords set', colour=0xFF0000)
     allcoords_gen = [(ucoords.user_id, ucoords.base_coords, ucoords.name)
                      for ucoords in self.usercoords
                      if ucoords.guild_id == ctx.guild.id]
     if not allcoords_gen:
         await ctx.send(embed=embed_error)
         return
     await (BotEmbedPaginator(
         ctx,
         pages(numbered([
             f"{ctx.guild.get_member(tup[0]).display_name}: {tup[1] + ' / ' + tup[2]}"
             for tup in allcoords_gen
         ]),
               n=10,
               title=f'Coordinates for {ctx.guild.name}'))).run()
Ejemplo n.º 12
0
    def plotAll(self) :
        print utils.hyphens
        self.setupStyle(self.optStat)

        self.printCanvas("[")
        text1 = self.printTimeStamp()
        text2 = self.printNEventsIn()
        self.flushPage()

        if self.detailedCalculables :
            blocks = filter(None, utils.splitList( self.someOrganizer.formattedCalculablesGraph(), ('','','')))
            for page in utils.pages(blocks,50) :
                text3 = self.printCalculablesDetailed(page)
                self.flushPage()
        else :
            text3 = self.printCalculables(selectImperfect = False)
            self.flushPage()
            text4 = self.printCalculables(selectImperfect = True)
            if text4 or self.printImperfectCalcPageIfEmpty:
                self.flushPage()
            
        nSelectionsPrinted = 0
        selectionsSoFar=[]
        for step in self.someOrganizer.steps :
            if step.isSelector : selectionsSoFar.append(step)
            elif nSelectionsPrinted<len(selectionsSoFar) and not self.compactOutput :
                self.printSteps(selectionsSoFar, printAll = self.compactOutput)
                nSelectionsPrinted = len(selectionsSoFar)
            if (step.name, step.title)==self.linYAfter : self.doLog = False
            for plotName in sorted(step.keys()) :
                if self.compactOutput and plotName not in self.whiteList : continue
                if any( re.match(pattern+'$',plotName) for pattern in self.blackList ): continue
                self.onePlotFunction(step[plotName])

        self.printCanvas("]")
        print self.pdfFileName, 'has been written'
        if self.latexYieldTable : self.printLatexYieldTable()
        print utils.hyphens
Ejemplo n.º 13
0
 async def shops(self, ctx: commands.Context, user: discord.Member = None):
     """
     Let's you see the mentioned user's shops
     **e.g**: `$shops <@user>`
     """
     await ctx.message.delete()
     if not user:
         user = ctx.author
     shops_gen = [
         (shops.name, shops.items) for shops in self.shops
         if shops.user_id == user.id and shops.guild_id == ctx.guild.id
     ]
     if not shops_gen:
         await ctx.send(embed=discord.Embed(
             title=f"{user.display_name} doesn't own any shops",
             colour=0xFF0000))
         return
     await (BotEmbedPaginator(
         ctx,
         pages(numbered(
             [f"Name: {tup[0]}\nItems: {tup[1]}" for tup in shops_gen]),
               n=10,
               title=f"Shops owned by {user.display_name}"))).run()
Ejemplo n.º 14
0
 async def coords(self, ctx: commands.Context, user: discord.Member = None):
     """
     Returns the coords of the user mentioned, if no user is mentioned, returns the author's coords
     **e.g**: `$coords <@user>`
     """
     await ctx.message.delete()
     if not user:
         user = ctx.author
     embed_nocrds = discord.Embed(
         title=f'No coords set for {user.display_name}', colour=0xFF0000)
     gen = [
         (ucoords.base_coords, ucoords.name) for ucoords in self.usercoords
         if ucoords.user_id == user.id and ucoords.guild_id == ctx.guild.id
     ]
     if not gen:
         await ctx.send(embed=embed_nocrds)
         return
     await (BotEmbedPaginator(
         ctx,
         pages(numbered(
             [f"Coords: {tup[0]} | Name: {tup[1]}" for tup in gen]),
               n=10,
               title=f'Coordinates for {user.display_name}'))).run()
Ejemplo n.º 15
0
 async def alladmincoords(self, ctx: commands.Context):
     """
     Returns all the admin coords of the current server
     """
     await ctx.message.delete()
     embed_error = discord.Embed(title='No admin coords set',
                                 colour=0xFF0000)
     alladm_gen = [(adm.name, adm.coords, adm.creator_id)
                   for adm in self.admincoords
                   if adm.guild_id == ctx.guild.id]
     if not alladm_gen:
         await ctx.send(embed=embed_error)
         return
     else:
         await (BotEmbedPaginator(
             ctx,
             pages(numbered([
                 f"{tup[0]}: {tup[1]} | Creator: {ctx.guild.get_member(tup[2]).display_name}"
                 for tup in alladm_gen
             ]),
                   n=10,
                   title=
                   f'Admin coordinates for {ctx.guild.name}\n (name)(x)(z)(y)'
                   ))).run()
Ejemplo n.º 16
0
    def GET(self, f_cate_slug):
        query = web.input(curpage=1)
        curpage = query.curpage

        category = session.query(Categories).filter(Categories.slug == f_cate_slug).first()
        if category:
            list_title = u"分类:%s" % (category.title)
            list_description = list_title
            list_keywords = list_title
        else:
            list_title = u"分类:无此分类"
            list_description = list_title
            list_keywords = list_title

        articles = (
            session.query(Article)
            .filter(Article.categories.any(Categories.slug == f_cate_slug))
            .order_by(Article.addTime.desc())
        )

        offset = (curpage - 1) * config.COMMENT_PAGE_LEN
        p = divmod(articles.count(), config.COMMENT_PAGE_LEN)
        if p[1] > 0:
            pagecount = p[0] + 1
        else:
            pagecount = 1
        articles = articles.limit(config.COMMENT_PAGE_LEN).offset(offset).all()
        pages = util.pages(
            pagecount, curpage, 10, "&".join("%s=%s" % (a, b) for a, b in query.items() if a != "curpage") + "#comment"
        )
        cookie = {
            "author": web.cookies(author="").author,
            "email": web.cookies(email="").email,
            "weburl": web.cookies(weburl="").weburl,
        }
        return render_blog.article_list(locals(), self)