Esempio n. 1
0
def load_news(start_date: datetime.datetime = None,
              end_date: datetime.datetime = None,
              max_items: int = sys.maxsize) -> List[Container]:
    if start_date is None:
        start_date = dtutil.ts2dt(0)
    if end_date is None:
        end_date = dtutil.now()
    sql = """
        SELECT
            id,
            `date`,
            title,
            url
        FROM
            news_item
        WHERE
            `date` >= %s
        AND
            `date` <= %s
        ORDER BY
            `date` DESC
        LIMIT
            %s
    """
    results = [
        Container(r) for r in db().select(
            sql, [dtutil.dt2ts(start_date),
                  dtutil.dt2ts(end_date), max_items])
    ]
    for result in results:
        result.date = dtutil.ts2dt(result.date)
        result.form_date = dtutil.form_date(result.date, dtutil.WOTC_TZ)
        result.display_date = dtutil.display_date(result.date)
        result.type = 'site-news'
    return results
Esempio n. 2
0
def load_news(start_date=0, end_date=sys.maxsize, max_items=sys.maxsize):
    sql = """
        SELECT
            id,
            `date`,
            title,
            body
        FROM
            news_item
        WHERE
            `date` >= %s
        AND
            `date` <= %s
        ORDER BY
            `date` DESC
        LIMIT
            %s
    """
    results = [
        Container(r)
        for r in db().execute(sql, [start_date, end_date, max_items])
    ]
    for result in results:
        result.date = dtutil.ts2dt(result.date)
        result.form_date = dtutil.form_date(result.date, dtutil.WOTC_TZ)
        result.display_date = dtutil.display_date(result.date)
    return results
Esempio n. 3
0
def edit_news() -> str:
    new_item = Container({
        'form_date':
        dtutil.form_date(dtutil.now(dtutil.WOTC_TZ), dtutil.WOTC_TZ),
        'title':
        '',
        'url':
        ''
    })
    news_items = [new_item] + ns.load_news()
    view = EditNews(news_items)
    return view.page()