40
40
import PoleLog
41
41
import string
42
42
43
+ from dateutil .relativedelta import relativedelta
44
+ from dateutil .rrule import MONTHLY , rrule , WEEKLY
45
+
43
46
44
47
def load_pole_translations (DIR ):
45
48
gettext .bindtextdomain (APP , DIR )
@@ -1977,8 +1980,12 @@ def make_pwd_hash(pwd):
1977
1980
return phash .hexdigest ()
1978
1981
1979
1982
1980
- def sql_like (texto ):
1981
- return '%{}%' .format ('%' .join (texto .split ()))
1983
+ def sql_like (value ):
1984
+ return '%{}%' .format ('%' .join (value .split ()))
1985
+
1986
+
1987
+ def sql_in (values ):
1988
+ return ', ' .join ([':id%d' % x for x in xrange (len (values ))])
1982
1989
1983
1990
1984
1991
def truncate (value ):
@@ -1996,6 +2003,51 @@ def get_name_of_month(today, date):
1996
2003
return name
1997
2004
1998
2005
1999
- def get_danfe_path (rootdir , access_key , today , emit_date ):
2006
+ def get_danfe_path (rootdir , key , today , emit_date ):
2000
2007
subfolder = get_name_of_month (today , emit_date )
2001
- return os .path .join (rootdir , subfolder , 'PDF' , access_key + '.pdf' )
2008
+ return os .path .join (rootdir , subfolder , 'PDF' , key + '.pdf' )
2009
+
2010
+
2011
+ def first_day (date ):
2012
+ return convert_and_format (date , datetime .date , MONTH )[0 ]
2013
+
2014
+ WEEKINDEX = {'SEG' : 0 , 'TER' : 1 , 'QUA' : 2 , 'QUI' : 3 , 'SEX' : 4 , 'SAB' : 5 , 'DOM' : 6 }
2015
+
2016
+
2017
+ def due_date (dtstart , days ):
2018
+ return [dtstart + relativedelta (days = day ) for day in days ]
2019
+
2020
+
2021
+ def due_date_to_nearest_monthday (dtstart , days , monthday ):
2022
+ return [min (rrule (MONTHLY ,
2023
+ bymonthday = monthday ,
2024
+ dtstart = day - relativedelta (days = 30 ),
2025
+ until = day + relativedelta (days = 30 )),
2026
+ key = lambda x : abs (x - day ))
2027
+ for day in due_date (dtstart , days )]
2028
+
2029
+
2030
+ def due_date_to_nearest_weekday (dtstart , days , weekdays ):
2031
+ return [min (rrule (WEEKLY ,
2032
+ byweekday = [WEEKINDEX .get (d , 0 ) for d in weekdays ],
2033
+ dtstart = day - relativedelta (weeks = 1 ),
2034
+ until = day + relativedelta (weeks = 1 )),
2035
+ key = lambda x : abs (x - day ))
2036
+ for day in due_date (dtstart , days )]
2037
+
2038
+
2039
+ def due_date_to_next_weekday (dtstart , days , weekdays ):
2040
+ return [rrule (WEEKLY ,
2041
+ byweekday = [WEEKINDEX .get (d , 0 ) for d in weekdays ],
2042
+ count = 1 ,
2043
+ dtstart = day )[0 ]
2044
+ for day in due_date (dtstart , days )]
2045
+
2046
+
2047
+ def slug (text ):
2048
+ text = normalize (text ).lower ()
2049
+ return re .sub (r'\W+' , '-' , text )
2050
+
2051
+
2052
+ def normalize (text ):
2053
+ return unicodedata .normalize ('NFKD' , text .decode ('utf-8' )).encode ('ascii' , 'ignore' )
0 commit comments