Browse Source

Some fixes for organisation part
handle user removing from an event

tr4ck3ur 2 years ago
parent
commit
8e9dff3a07
5 changed files with 42 additions and 6 deletions
  1. 2 1
      jm2l/__init__.py
  2. 1 1
      jm2l/helpers.py
  3. 1 1
      jm2l/models.py
  4. 2 2
      jm2l/templates/edit_event.mako
  5. 36 1
      jm2l/views.py

+ 2 - 1
jm2l/__init__.py

@@ -135,8 +135,9 @@ def main(global_config, **settings):
135 135
     ## Events
136 136
     config.add_route('event', '/event/{year:\d+}/{event_id:([\w-]+)?}')
137 137
     config.add_route('link_event_user', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/link_user')
138
+    config.add_route('delete_link_u', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/delete_link_user')
138 139
     config.add_route('link_event_tiers', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/link_tiers')
139
-    config.add_route('delete_link', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/delete_link')
140
+    config.add_route('delete_link_t', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/delete_link_tiers')
140 141
     config.add_route('edit_event', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}{sep:/*}{event_id:([\w-]+)?}')
141 142
     config.add_route('delete_event', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}{sep:/*}{event_id:([\w-]+)?}/delete')
142 143
     

+ 1 - 1
jm2l/helpers.py

@@ -132,7 +132,7 @@ class Orga_helpers(DummySejour):
132 132
 
133 133
     def IsChecked(self, nb):
134 134
         nb = 2**nb
135
-        if self.Sejour:
135
+        if self.Sejour and self.Sejour.orga_part:
136 136
             if self.Sejour.orga_part & nb == nb:
137 137
                 return "checked=\"checked\""
138 138
             else:

+ 1 - 1
jm2l/models.py

@@ -566,7 +566,7 @@ class Sejour(Base):
566 566
     repas_allerg  = Column(Unicode(100))
567 567
     repas_contr   = Column(Unicode(100))
568 568
     orga_part     = Column(Integer, default=0)
569
-    #travel_detail = Column(UnicodeText)
569
+    travel_detail = Column(UnicodeText)
570 570
     created       = Column(DateTime, default=datetime.datetime.now)
571 571
     last_change   = Column(DateTime, default=datetime.datetime.now)
572 572
     

+ 2 - 2
jm2l/templates/edit_event.mako

@@ -110,7 +110,7 @@ DicForm = {
110 110
     % endif
111 111
 
112 112
 <%def name="callback_Del_Summary(Entity)"> \
113
-	<a class="btn btn-danger btn-mini pull-right" type="button" href="delete_link?tid=${Entity.uid}&uid=${event.uid}">
113
+	<a class="btn btn-danger btn-mini pull-right" type="button" href="delete_link_tiers?tid=${Entity.uid}&uid=${event.uid}">
114 114
 		<i class="icon-remove icon-white"></i>
115 115
 	</a>
116 116
 </%def>
@@ -170,7 +170,7 @@ DicForm = {
170 170
                         (${iterv.pseudo})
171 171
                     %endif
172 172
                 % if iterv!=request.user:
173
-				<a class="btn btn-danger btn-mini" type="button" href="delete_interv?uid=${iterv.uid}&eid=${event.uid}">
173
+				<a class="btn btn-danger btn-mini" type="button" href="delete_link_user?uid=${iterv.uid}&eid=${event.uid}">
174 174
 					<i class="icon-remove icon-white"></i>
175 175
 				</a>
176 176
 				%endif

+ 36 - 1
jm2l/views.py

@@ -1218,7 +1218,42 @@ def link_event_tiers(request):
1218 1218
     return HTTPFound(location=request.route_url('edit_event', sep='/',
1219 1219
         year=str(year), intervention=intervention, event_id=str(TargetEvent.uid), _anchor="Tiers"))
1220 1220
 
1221
-@view_config(route_name='delete_link')
1221
+@view_config(route_name='delete_link_u')
1222
+def delete_link_event_user(request):
1223
+    """ Create user if not exist, add it to current event """
1224
+    if request.user is None:
1225
+        # Don't answer to users that aren't logged
1226
+        raise HTTPForbidden(u'Vous devez vous identifier pour obtenir une réponse.')
1227
+    year = int(request.matchdict.get('year', -1))
1228
+    intervention = request.matchdict.get('intervention', None)
1229
+    
1230
+    TargetEvent = Event.by_id( request.params.get('eid') )
1231
+    Exist = User.by_id( request.params.get('uid') )
1232
+    if not Exist:
1233
+        request.session.flash(('error',u"Une erreur s'est produite lors de votre suppression !"))
1234
+        return HTTPFound(location=request.route_url('edit_event', sep='/',
1235
+            year=str(year), intervention=intervention, event_id=str(TargetEvent.uid)))
1236
+    else:
1237
+        TargetUser = Exist
1238
+
1239
+    Matching = DBSession.query(User_Event)\
1240
+            .filter(User_Event.year_uid==year)\
1241
+            .filter(User_Event.user_uid==TargetUser.uid)\
1242
+            .filter(User_Event.event_uid==TargetEvent.uid)\
1243
+            .all()
1244
+
1245
+    if len(Matching)==0:
1246
+        request.session.flash(('error',u"Une erreur s'est produite lors de la suppression !"))
1247
+    else:
1248
+        for item in Matching:
1249
+            DBSession.delete(item)
1250
+            
1251
+    return HTTPFound(location=request.route_url('edit_event', sep='/',
1252
+        year=str(year), intervention=intervention, event_id=str(TargetEvent.uid), _anchor="Tiers"))
1253
+
1254
+
1255
+
1256
+@view_config(route_name='delete_link_t')
1222 1257
 def delete_link_event_tiers(request):
1223 1258
     """ Create user if not exist, add it to current event """
1224 1259
     if request.user is None: