Пример #1
0
 def recent_statuses(self, page=1, startdate=None, enddate=None):
     """Return the statuses for the team."""
     user_ids = [u.id for u in self.users]
     statuses = Status.query.filter(
         Status.user_id.in_(user_ids), Status.reply_to==None).order_by(
         db.desc(Status.created))
     return paginate(statuses, page, startdate, enddate)
Пример #2
0
def index():
    """The home page."""
    return render_template(
        'index.html',
        statuses=paginate(
            Status.query.filter(Status.reply_to==None).order_by(
                db.desc(Status.created)),
            request.args.get('page', 1),
            startdate(request),
            enddate(request)),)
Пример #3
0
def index():
    """The home page."""
    db = get_session(current_app)

    return render_template(
        'status/index.html',
        statuses=paginate(
            db.query(Status).filter_by(reply_to=None).order_by(
                desc(Status.created)), request.args.get('page', 1),
            startdate(request), enddate(request)),
    )
Пример #4
0
def index():
    """The home page."""
    db = get_session(current_app)

    return render_template(
        'status/index.html',
        statuses=paginate(
            db.query(Status).filter_by(reply_to=None).order_by(
                desc(Status.created)),
            request.args.get('page', 1),
            startdate(request),
            enddate(request)),)
Пример #5
0
def status(id):
    """The status page. Shows a single status."""
    db = get_session(current_app)

    statuses = db.query(Status).filter_by(id=id)

    if not statuses.count():
        return page_not_found('Status not found.')

    status = statuses[0]

    return render_template('status/status.html',
                           user=status.user,
                           statuses=paginate(statuses),
                           replies=status.replies(request.args.get('page', 1)))
Пример #6
0
def status(id):
    """The status page. Shows a single status."""
    statuses = Status.query.filter_by(id=id)

    if not statuses.count():
        return page_not_found('Status not found.')

    status = statuses[0]

    return render_template(
        'status.html',
        user=status.user,
        statuses=paginate(statuses),
        replies=status.replies(request.args.get('page', 1))
    )
Пример #7
0
def weekly():
    """The weekly status page."""
    db = get_session(current_app)

    #select id, user_id, created, strftime('%Y%W', created), date(created, 'weekday 1'), content from status order by 4, 2, 3;
    return render_template(
        'status/weekly.html',
        week=request.args.get('week', None),
        statuses=paginate(db.query(Status).filter_by(reply_to=None).order_by(
            desc(WeekColumnClause("created")), Status.user_id,
            desc(Status.created)),
                          request.args.get('page', 1),
                          startdate(request),
                          enddate(request),
                          per_page=100),
    )
Пример #8
0
def weekly():
    """The weekly status page."""
    db = get_session(current_app)

    #select id, user_id, created, strftime('%Y%W', created), date(created, 'weekday 1'), content from status order by 4, 2, 3;
    return render_template(
        'status/weekly.html',
        week=request.args.get('week', None),
        statuses=paginate(
            db.query(Status).filter_by(reply_to=None).order_by(
                desc(WeekColumnClause("created")),
                Status.user_id,
                desc(Status.created)),
            request.args.get('page', 1),
            startdate(request),
            enddate(request),
            per_page=100),)
Пример #9
0
    def test_paginate(self):
        """Test the paginate helper function."""
        db = get_session(self.app)

        statuses = []
        with self.app.app_context():
            p = project(save=True)
            u = user(save=True)

            # Create 100 statuses
            for i in range(30):
                statuses.append(status(project=p, user=u,
                                       created=datetime(2012, 5, 25),
                                       save=True))

            for i in range(30):
                statuses.append(status(project=p, user=u,
                                       created=datetime(2012, 6, 25),
                                       save=True))

            for i in range(40):
                statuses.append(status(project=p, user=u,
                                       created=datetime(2012, 7, 25),
                                       save=True))

        s = db.query(Status).order_by(Status.id)

        # Test simple pagination
        page = paginate(s, page=1)

        eq_(page.pages, 5)

        eq_(page.has_prev, False)
        eq_(page.has_next, True)

        page = paginate(s, page=3)
        eq_(page.has_prev, True)
        eq_(page.has_next, True)

        page = paginate(s, page=5)
        eq_(page.has_prev, True)
        eq_(page.has_next, False)

        # Test date filtered pagination
        page = paginate(s, page=1, startdate=datetime(2012, 5, 28))
        eq_(page.pages, 4)

        page = paginate(s, page=1, startdate=datetime(2012, 5, 28),
                        enddate=datetime(2012, 6, 28))
        eq_(page.pages, 2)

        page = paginate(s, page=1, enddate=datetime(2012, 6, 28))
        eq_(page.pages, 3)
Пример #10
0
 def recent_statuses(self, page=1, startdate=None, enddate=None):
     """Return the statuses for the user."""
     statuses = self.statuses.filter(Status.reply_to==None).order_by(
         db.desc(Status.created))
     return paginate(statuses, page, startdate, enddate)
Пример #11
0
    def test_paginate(self):
        """Test the paginate helper function."""
        db = get_session(self.app)

        statuses = []
        with self.app.app_context():
            p = project(save=True)
            u = user(save=True)

            # Create 100 statuses
            for i in range(30):
                statuses.append(
                    status(project=p,
                           user=u,
                           created=datetime(2012, 5, 25),
                           save=True))

            for i in range(30):
                statuses.append(
                    status(project=p,
                           user=u,
                           created=datetime(2012, 6, 25),
                           save=True))

            for i in range(40):
                statuses.append(
                    status(project=p,
                           user=u,
                           created=datetime(2012, 7, 25),
                           save=True))

        s = db.query(Status).order_by(Status.id)

        # Test simple pagination
        page = paginate(s, page=1)

        eq_(page.pages, 5)

        eq_(page.has_prev, False)
        eq_(page.has_next, True)

        page = paginate(s, page=3)
        eq_(page.has_prev, True)
        eq_(page.has_next, True)

        page = paginate(s, page=5)
        eq_(page.has_prev, True)
        eq_(page.has_next, False)

        # Test date filtered pagination
        page = paginate(s, page=1, startdate=datetime(2012, 5, 28))
        eq_(page.pages, 4)

        page = paginate(s,
                        page=1,
                        startdate=datetime(2012, 5, 28),
                        enddate=datetime(2012, 6, 28))
        eq_(page.pages, 2)

        page = paginate(s, page=1, enddate=datetime(2012, 6, 28))
        eq_(page.pages, 3)
Пример #12
0
 def replies(self, page=1):
     db = get_session(current_app)
     replies = db.query(Status).filter_by(reply_to_id=self.id)\
         .order_by(asc(Status.created))
     return paginate(replies, page)
Пример #13
0
 def recent_statuses(self, page=1, startdate=None, enddate=None):
     """Return the statuses for the project."""
     statuses = self.statuses.filter_by(reply_to=None)\
         .order_by(desc(Status.created))
     return paginate(statuses, page, startdate, enddate)
Пример #14
0
 def replies(self, page=1):
     replies = Status.query.filter(Status.reply_to_id==self.id).order_by(
         db.asc(Status.created))
     return paginate(replies, page)
Пример #15
0
 def recent_statuses(self, page=1, startdate=None, enddate=None):
     """Return a single page of the most recent statuses from this user."""
     statuses = self.statuses.filter_by(reply_to=None)\
         .order_by(desc(Status.created))
     return paginate(statuses, page, startdate, enddate)
Пример #16
0
 def recent_statuses(self, page=1, startdate=None, enddate=None):
     """Return a single page of the most recent statuses from this user."""
     statuses = self.statuses.filter_by(reply_to=None)\
         .order_by(desc(Status.created))
     return paginate(statuses, page, startdate, enddate)