Project

General

Profile

« Previous | Next » 

Revision efe3f40d

Added by Serghei Mihai over 10 years ago

agenda: cookies deletion refactored: taking in account their path.
Deletion of agenda cookies on return on homepage.

Closes #3636

View differences:

calebasse/agenda/views.py
71 71

  
72 72
class AgendaServiceActivityView(TemplateView, cbv.ServiceViewMixin):
73 73
    template_name = 'agenda/service-activity.html'
74
    cookies_to_clear = ['agenda-worker-tabs']
74
    cookies_to_clear = [('agenda-worker-tabs', )]
75 75

  
76 76
    def get_context_data(self, **kwargs):
77 77
        context = super(AgendaServiceActivityView, self).get_context_data(**kwargs)
......
130 130
    template_name = 'agenda/new-appointment.html'
131 131
    success_url = '..'
132 132
    success_msg = u'Rendez-vous enregistré avec succès.'
133
    cookies_to_clear = ['agenda-worker-tabs']
133
    cookies_to_clear = [('agenda-worker-tabs', )]
134 134

  
135 135
    def get_initial(self):
136 136
        initial = super(NewAppointmentView, self).get_initial()
......
203 203
    form_class = NewEventForm
204 204
    template_name = 'agenda/new-event.html'
205 205
    success_url = '..'
206
    cookies_to_clear = ['agenda-worker-tabs']
206
    cookies_to_clear = [('agenda-worker-tabs', )]
207 207

  
208 208
    def get_initial(self):
209 209
        initial = super(NewEventView, self).get_initial()
......
291 291

  
292 292
class AgendaServiceActValidationView(TemplateView):
293 293
    template_name = 'agenda/act-validation.html'
294
    cookies_to_clear = ['agenda-worker-tabs']
294
    cookies_to_clear = [('agenda-worker-tabs', )]
295 295

  
296 296
    def acts_of_the_day(self):
297 297
        acts = list(Act.objects \
......
421 421

  
422 422
class AgendasTherapeutesView(AgendaHomepageView):
423 423
    template_name = 'agenda/agendas-therapeutes.html'
424
    cookies_to_clear = ['agenda-worker-tabs']
424
    cookies_to_clear = [('agenda-worker-tabs', )]
425 425

  
426 426
    def get_context_data(self, **kwargs):
427 427
        context = super(AgendasTherapeutesView, self).get_context_data(**kwargs)
......
626 626
class PeriodicEventsView(cbv.ListView):
627 627
    model = EventWithAct
628 628
    template_name = 'agenda/periodic-events.html'
629
    cookies_to_clear = ['agenda-worker-tabs']
629
    cookies_to_clear = [('agenda-worker-tabs', )]
630 630

  
631 631
    def dispatch(self, request, *args, **kwargs):
632 632
        if 'worker_id' in kwargs:
calebasse/cbv.py
30 30
    service = None
31 31
    date = None
32 32
    popup = False
33
    cookies_to_clear = [ 'agenda-worker-tabs', 'active-resource-agenda' ]
33
    cookies_to_clear = [('agenda-worker-tabs', ), ('active-resource-agenda', )]
34 34

  
35 35
    def clear_cookies(self, response, path):
36 36
        for cookie in self.cookies_to_clear:
37
            response.delete_cookie(cookie,
38
                                   path = '/'.join(path.split('/')[:3])
39
                                   )
37
            cookie_name = cookie[0]
38
            try:
39
                # delete the cookie for provided path
40
                response.delete_cookie(cookie[0], path = cookie[1])
41
            except IndexError:
42
                # if not use the current page path
43
                response.delete_cookie(cookie[0],
44
                                       path = '/'.join(path.split('/')[:3])
45
                                       )
40 46

  
41 47
    def dispatch(self, request, **kwargs):
42 48
        self.popup = request.GET.get('popup')
calebasse/views.py
25 25

  
26 26
class Homepage(TemplateView):
27 27
    template_name='calebasse/homepage.html'
28
    cookies_to_clear = [('agenda-worker-tabs', )]
29

  
30
    def dispatch(self, request, **kwargs):
31
        if 'service' in kwargs:
32
            self.cookies_to_clear = [('agenda-worker-tabs',
33
                                      '/%s/agenda' % kwargs['service'])
34
                                     ]
35
        return super(Homepage, self).dispatch(request, **kwargs)
28 36

  
29 37
    def get_context_data(self, **kwargs):
30 38
        services = Service.objects.values_list('name', 'slug')

Also available in: Unified diff