コード例 #1
0
ファイル: Commercial.py プロジェクト: jonathancg90/appSpiral
 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')
コード例 #2
0
ファイル: Commercial.py プロジェクト: jonathancg90/appSpiral
 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
コード例 #3
0
ファイル: Commercial.py プロジェクト: jonathancg90/appSpiral
 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)