NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.
If you are not into long explanations, see [Paolo Bergantino’s answer][2].
NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.
If you are not into long explanations, see [Paolo Bergantino’s answer][2].
| with open(path + '/' + filename + '.csv', 'w',encoding='ISO_8859-1') as f: | |
| f.write("class;temps;nom;cat;sexe;club\n") | |
| for r in result_tab: | |
| rw=r[:] | |
| f.write(';'.join(map(lambda x: str(x),rw))+'\n') | |
| f.close() | |
| return 'pdf_files/' + filename + '.csv' |
| <form1> | |
| <input radio item2> Item 1 | |
| <form item1> | |
| ... | |
| <submit form item1> | |
| </form item1> | |
| <input radio item2> Item 2 | |
| <form item2> | |
| ... | |
| <submit form item2> |
| class TimeNew: | |
| def __init__(self,hms): | |
| self.time = timedelta(hours=hms[0],minutes=hms[1],seconds=hms[2]) | |
| def __str__(self): | |
| s=self.time.total_seconds() | |
| if int(s//3600) == 0: | |
| return "{}'{}''".format(int(s % 3600 // 60),int(s % 60)) | |
| else: | |
| return "{:02}h{}'{}''".format(int(s//3600),int(s % 3600 //60),int(s % 60)) |
| def remove_race(request,race_ID,race_type): | |
| # TODO: add race_name into session['races'] | |
| if request.session.get('races') and utils.index_shortlist_in_list([race_ID,race_type],request.session['races']) | |
| request.session['races'].remove([race_ID,race_type],request.session['races']) | |
| request.session.modified = True | |
| else: | |
| error_msg_url = "La course n'appartient pas à votre liste!" | |
| error_msg_url = utils.index_shortlist_in_list([race_ID,race_type],request.session['races']) | |
| error_msg_url = repr(race_ID)+':'+repr(race_type)+'::'+','.join(['['+a[1]+','+a[0]+']' for a in request.session['races']]) | |
| return render(request,'index.html',{'error_msg_url':error_msg_url,'racelist':request.session.get('races')}) |
| def create_columns_record(): | |
| cursor,connexion=db_initiate() | |
| yearnow= datetime.datetime.now().year | |
| yearlist = [yearnow - i for i in range(4)]*3 | |
| racetypes=['10k','21k','42k'] | |
| test_record= 'record_10k'+str(yearnow) | |
| cursor.execute("SELECT column_name FROM information_schema.columns WHERE table_name='runners' and column_name=%s;",(test_record,)) |
| import psycopg2 | |
| import convertFFA2kikourou | |
| def db_initiate(host="localhost",dbname="XXX",user="XXX",password="XXX"): | |
| conn=psycopg2.connect(host="localhost",dbname="XXX", user="XXX", | |
| password="XXX") | |
| cur = conn.cursor() | |
| return cur,conn | |
| def db_finish(cursor,connexion): |
| Project | |
| | | |
| |----- django-project | |
| |--- django-project | |
| |---- urls.py | |
| |---- views.py | |
| | | |
| |----- mymodule | |
| |--- __init__.py | |
| |--- module.py |