Ejemplo n.º 1
0
 def create_ideal_style_card(self):
     if self.user.heart < User.REQUIREMENT_GET_IDEAL_HEART:
         raise HeartNotEnoughException()
     self.user.heart = self.user.heart - User.REQUIREMENT_GET_IDEAL_HEART
     self.save()
     if self.user.gender == "M":
         opposite_gender = "F"
     else:
         opposite_gender = "M"
     partner = User.objects.filter(gender=opposite_gender,
                                   school=school,
                                   major=major,
                                   job=job,
                                   personality=personality,
                                   region=region,
                                   height=height,
                                   body_type=body_type,
                                   age=age).first()
     if not partner:
         self.user.heart = self.user.heart + User.REQUIREMENT_GET_IDEAL_HEART
         self.save()
         raise NoPartnerException()
     print(partner)
     1 / 0
     card = Card(user=self.user,
                 partner=partner,
                 introduce_date=date.today())
     card.save()
     return card
Ejemplo n.º 2
0
 def form_valid(self, form):
     user = self.request.user
     myuser = user.myuser
     now = datetime.datetime.now()
     for item in form.cleaned_data['books']:
         book = Book.objects.get(id=item)
         book.is_taken = True
         book.save()
         card = Card(books=book, myuser=myuser, when_giving=now)
         card.save()
         message = u'You take \"%s\" from library' % book.title
         messages.success(self.request, message)
     return super(CardCreateView, self).form_valid(form)
Ejemplo n.º 3
0
    def create(number, month, year, name):
        number = CardService.validate_number(number)
        month = CardService.validate_month(month)
        year = CardService.validate_year(year)
        name = CardService.validate_name(name)

        CardService.validate_date(month, year)
        CardService.check_for_existing(number)

        card = Card(number=number, month=month, year=year, name=name)

        try:
            card.save()
        except IntegrityError:
            raise CardServiceException('Card with such number already exists.')

        return card
Ejemplo n.º 4
0
    def create_next_card(self):
        if self.heart < User.REQUIREMENT_GET_NEXT_HEART:
            raise HeartNotEnoughException()
        self.heart = self.heart - User.REQUIREMENT_GET_NEXT_HEART
        self.save()
        if self.gender == "M":
            opposite_gender = "F"
        else:
            opposite_gender = "M"

        partner = User.objects.filter(gender=opposite_gender).first()
        if not partner:
            self.heart = self.heart + User.REQUIREMENT_GET_NEXT_HEART
            self.save()
            raise NoPartnerException()
        print(partner)
        1 / 0
        card = Card(user=self, partner=partner, introduce_date=date.today())
        card.save()
        return card