Esempio n. 1
0
 def get_success_url(self):
     if settings.APPLICATION_CACHE:
         clean_cache = CleanCache()
         clean_cache.set_cache_result_tag(Commercial.get_commercial_tag())
         clean_cache.set_model(Commercial)
         clean_cache.update_cache_by_id([self.kwargs.get('pk')], CleanCache.MODE_DELETE)
     return reverse('commercial_list')
Esempio n. 2
0
 def save_commercial(self, data):
     try:
         commercial = Commercial()
         commercial.name = data.get('name')
         commercial.brand = Brand.objects.get(pk=data.get('brand'))
         commercial.save()
         if settings.APPLICATION_CACHE:
             clean_cache = CleanCache()
             clean_cache.set_cache_result_tag(Commercial.get_commercial_tag())
             clean_cache.set_model(Commercial)
             clean_cache.update_cache_by_id([commercial.id], CleanCache.MODE_INSERT)
         return commercial, self.SAVE_SUCCESSFUL
     except Exception, e:
         return None, self.SAVE_ERROR
Esempio n. 3
0
 def form_valid(self, form):
     self.object = form.save(commit=False)
     dataPost = self.request.POST
     self.object.save()
     for data in dataPost:
         if 'realized' in data:
             try:
                 realized = datetime.datetime.strptime(dataPost.get(data), '%d/%m/%Y').strftime('%Y-%m-%d')
                 detail = CommercialDateDetail()
                 detail.date = realized
                 self.object.commercial_date_detail_set.add(detail)
             except:
                 pass
     if settings.APPLICATION_CACHE:
         clean_cache = CleanCache()
         clean_cache.set_cache_result_tag(Commercial.get_commercial_tag())
         clean_cache.set_model(Commercial)
         clean_cache.update_cache_by_id([self.object.id], CleanCache.MODE_INSERT)
     return super(CommercialCreateView, self).form_valid(form)