Beispiel #1
0
 def save(self, *args):
     instance = None
     if self.params.key:
         instance = Dolg.get(self.params.key)
     form=DolgForm(data=self.request.POST)
     if form.is_valid():
         od = None
         na = None
         if  form.cleaned_data['Type']=='1':
             na = Person.get(form.cleaned_data['Party'])
             od = self.User
         else:
              od = Person.get(form.cleaned_data['Party'])
              na = self.User
         if instance:
             instance.Note = form.cleaned_data["Note"]
             instance.Kolicina = float(form.cleaned_data["Ammount"])
             instance.Od = od
             instance.Na = na
             instance.DodadenOd = self.User
             instance.put()
         else:
             instance = Dolg.CreateNew(od=od, na=na,
                                       kolicina= form.cleaned_data["Ammount"],
                                       note=form.cleaned_data["Note"],
                                       dodaden_od=self.User, _isAutoInsert=True)
         self.status = 'Dolg is saved'
         try:
             self.send_email(instance, self.get_edit_body(instance, nov=not self.params.key))
             self.status+=' and message is sent'
         except Exception, ex:
             import logging
             logging.error(ex.message)
             self.status+=' but message is not sent. Probably the party does not have an email added in the profile'
         self.redirect(DolgController.get_url())
Beispiel #2
0
 def details(self, *args):
     if self.params.key:
         item = Dolg.get(self.params.key)
         if item:
             form  = DolgForm()
             if item.Od == self.User:
                 form.cleaned_data['Type']=1
                 form.cleaned_data['Party'] = str(item.Na.key())
             else:
                 form.cleaned_data['Type']=0
                 form.cleaned_data['Party'] = str(item.Od.key())
             form.cleaned_data["Note"]=item.Note
             return {'op':'update', 'DolgForm': form}
         else:
             self.status = 'Dolg does not exists'
             self.redirect(DolgController.get_url())
     else:
         self.status = 'Key not provided'
         return {'op':'insert' ,'DolgForm':DolgForm()}