def before_save(self, xfer): xfer.is_new = (self.item.id is None) if xfer.getparam('autocreate', 0) == 1: self.item.send_email_param = (xfer.request.META.get( 'HTTP_REFERER', xfer.request.build_absolute_uri()), xfer.language) self.item.season = Season.current_season() if self.item.adherent_id is None: current_contact = Individual.objects.get( user=xfer.request.user) current_contact = current_contact.get_final_child() self.item.adherent = Adherent(id=current_contact.pk) self.item.adherent.save(new_num=True) self.item.adherent.__dict__.update(current_contact.__dict__) self.item.adherent.save() self.item.adherent_id = self.item.adherent.id if self.item.subscriptiontype.duration == 0: # periodic season = self.item.season self.item.begin_date = season.begin_date self.item.end_date = season.end_date elif self.item.subscriptiontype.duration == 1: # periodic periodid = xfer.getparam('period', 0) period = Period.objects.get(id=periodid) self.item.begin_date = period.begin_date self.item.end_date = period.end_date elif self.item.subscriptiontype.duration == 2: # monthly month_num = xfer.getparam('month', '') self.item.begin_date = convert_date(month_num + '-01') self.item.end_date = same_day_months_after(self.item.begin_date, 1) - timedelta(days=1) elif self.item.subscriptiontype.duration == 3: # calendar self.item.begin_date = convert_date(xfer.getparam( 'begin_date', '')) self.item.end_date = same_day_months_after(self.item.begin_date, 12) - timedelta(days=1)
def create_adherent(firstname, lastname, birthday): new_adh = Adherent() new_adh.firstname = firstname new_adh.lastname = lastname new_adh.address = "rue de la liberté" new_adh.postal_code = "97250" new_adh.city = "LE PRECHEUR" new_adh.country = "MARTINIQUE" new_adh.tel2 = "02-78-45-12-95" new_adh.email = "*****@*****.**" % (firstname, lastname) new_adh.birthday = birthday new_adh.save() return new_adh