Skip to content

Instantly share code, notes, and snippets.

View honmaple's full-sized avatar

honmaple honmaple

View GitHub Profile
@honmaple
honmaple / Restful View Pemission
Created October 12, 2016 02:15
restful形式的权限管理 based on flask
class RestfulBase(object):
decorators = ()
def __call__(self, func):
f = self.method(func)
if self.decorators:
for dec in reversed(self.decorators):
f = dec(f)
return f
@honmaple
honmaple / datetime or time to string
Created September 23, 2016 01:14
python时间或时间戳与字符串转换
#把datetime转成字符串
def datetime_toString(dt):
return dt.strftime("%Y-%m-%d-%H")
#把字符串转成datetime
def string_toDatetime(string):
return datetime.strptime(string, "%Y-%m-%d-%H")
#把字符串转成时间戳形式
def string_toTimestamp(strTime):
@honmaple
honmaple / Get zero datetime
Created September 23, 2016 01:11
得到当天零点时间
today = datetime.datetime.today()
b = datetime.datetime(today.year, today.month, today.day, 0, 0, 0)
print(b)
now = time.time()
midnight = now - (now % 86400) + time.timezone
itime = time.ctime(midnight)
print(itime)
@honmaple
honmaple / paginate.html
Created May 26, 2016 14:29
flask use paginate
{% macro paginate(pagination, endpoint,kw=None) %}
<ul class="pagination" style="margin:0">
{% if pagination.items and pagination.pages > 1 -%}
{%- if pagination.has_prev -%}
{%- if not kw -%}
<li><a href="{{ url_for(endpoint,page=pagination.page-1)}}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
{%- else -%}
<li><a href="{{ url_for(endpoint,page=pagination.page-1,**kw)}}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
{% endif -%}
{%- else %}