Browse code

"list staffers pdf"

Doug Le Tough authored on 09/05/2018 09:20:06
Showing 1 changed files
... ...
@@ -1053,96 +1053,21 @@ def list_users():
1053 1053
     # User is not logged in
1054 1054
     return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
1055 1055
 
1056
-@app.route("/users/pdf", methods=['GET', 'POST'])
1056
+@app.route("/users/print", methods=['GET', 'POST'])
1057 1057
 @check_session
1058 1058
 def print_users():
1059 1059
   """ Print user list """
1060 1060
   message = check_user_info()
1061
-  #~ try:
1062
-  if session['is_admin']:
1063
-    page = str(request.url_rule)
1064
-    menu = get_menu(page)
1065
-    staffers = Tetawebapp_users.query.filter(Tetawebapp_users.is_admin==0, Tetawebapp_users.link_id==None).order_by(Tetawebapp_users.name).all()
1066
-    pdf = cStringIO.StringIO()
1067
-    cols_width = 585
1068
-    doc = SimpleDocTemplate(pdf, pagesize=A4, rightMargin=3,leftMargin=3, topMargin=3,bottomMargin=3)
1069
-    elements = []
1070
-    styles = getSampleStyleSheet()
1071
-    styles.add(ParagraphStyle(name='master_title',
1072
-                              alignment=TA_LEFT,
1073
-                              fontSize=20,
1074
-                              leading=25,
1075
-                              spaceBefore=10,
1076
-                              spaceAfter=10,
1077
-                              ))
1078
-    styles.add(ParagraphStyle(name='day_title',
1079
-                              alignment=TA_LEFT,
1080
-                              backColor=orange,
1081
-                              borderWidth=1,
1082
-                              borderColor=black,
1083
-                              borderPadding=5,
1084
-                              spaceBefore=10,
1085
-                              spaceAfter=10
1086
-                              ))
1087
-    styles.add(ParagraphStyle(name='role_title',
1088
-                              alignment=TA_LEFT,
1089
-                              backColor=lightsalmon,
1090
-                              borderWidth=1,
1091
-                              borderColor=black,
1092
-                              borderPadding=5,
1093
-                              spaceBefore=10,
1094
-                              spaceAfter=10
1095
-                              ))
1096
-    styles.add(ParagraphStyle(name='turn',
1097
-                              alignment=TA_LEFT,
1098
-                              backColor=white,
1099
-                              borderWidth=1,
1100
-                              borderColor=black,
1101
-                              borderPadding=5,
1102
-                              spaceBefore=10,
1103
-                              spaceAfter=0
1104
-                              ))
1105
-    styles.add(ParagraphStyle(name='basic_text',
1106
-                              alignment=TA_LEFT,
1107
-                              spaceBefore=5,
1108
-                              spaceAfter=5
1109
-                              ))
1110
-    styles.add(ParagraphStyle(name='row1',
1111
-                              alignment=TA_LEFT,
1112
-                              backColor=white,
1113
-                              spaceBefore=10,
1114
-                              spaceAfter=10
1115
-                              ))
1116
-    styles.add(ParagraphStyle(name='row2',
1117
-                              alignment=TA_CENTER,
1118
-                              backColor=white,
1119
-                              spaceBefore=10,
1120
-                              spaceAfter=10
1121
-                              ))
1122
-
1123
-    rows = []
1124
-    for staffer in staffers:
1125
-      row = (Paragraph(staffer.name, styles['row2']), Paragraph(staffer.phone, styles['row2']), Paragraph(staffer.diet, styles['row2']))
1126
-      rows.append(row)
1127
-
1128
-    table = Table(rows, colWidths=cols_width, rowHeights=23)
1129
-    table.setStyle(TableStyle( [('GRID', (0,0), (-1,-1), 0.25, colors.black),
1130
-                                  ('ALIGN', (1,1), (-1,-1), 'RIGHT')]))
1131
-    elements.append(table)
1132
-    styles.wordWrap = 'CJK'
1133
-    doc.build(elements)
1134
-    pdf_out = pdf.getvalue()
1135
-    pdf.close()
1136
-    response = app.make_response(pdf_out)
1137
-    response.headers['Content-Disposition'] = "attachment; filename=feuille_staff_thsf.pdf"
1138
-    response.mimetype = 'application/pdf'
1139
-    return response
1140
-  #~ # User is not admin
1141
-    #~ return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
1142
-  #~ except Exception as e:
1143
-    #~ raise e
1144
-    #~ # User is not logged in
1145
-    #~ return render_template('login_or_register.html', message="%s" % e)
1061
+  try:
1062
+    if session['is_admin']:
1063
+      staffers = Tetawebapp_users.query.filter(Tetawebapp_users.is_admin==0, Tetawebapp_users.link_id==None).order_by(Tetawebapp_users.name).all()
1064
+      return render_template('list_users.html', staffers=staffers)
1065
+    # User is not admin
1066
+    return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
1067
+    except Exception as e:
1068
+      raise e
1069
+      # User is not logged in
1070
+      return render_template('login_or_register.html', message="%s" % e)
1146 1071
 
1147 1072
 
1148 1073
 @app.route("/account/<ID>", methods=['GET', 'POST'])