class Course(Shippable): name_genitive = models.CharField(_('Genitive name'), max_length=255, help_text='«мастер-класса о TDD». К примеру для записей.') clickmeeting_room_url = models.URLField(_('Clickmeeting room URL'), null=True, blank=True, help_text=_('If set, every user who purcashes this course gets invited')) zoomus_webinar_id = models.CharField(_('Zoom.us webinar ID'), max_length=255, null=True, blank=True, help_text=_('If set, every user who purcashes this course gets invited')) welcome_letter_template_id = models.CharField(_('Welcome letter template id'), max_length=255, blank=True, null=True, help_text=_('Will be sent upon purchase if set')) gift_welcome_letter_template_id = models.CharField(_('Special welcome letter template id for gifts'), max_length=255, blank=True, null=True, help_text=_('If not set, common welcome letter will be used')) mailchimp_list_id = models.CharField(_('Mailchimp audience id'), max_length=32, blank=True, null=True, help_text=_('Get it from audience settings')) class Meta: ordering = ['-id'] verbose_name = _('Course') verbose_name_plural = _('Courses') db_table = 'courses_course' def get_purchased_users(self) -> Iterable[User]: return User.objects.filter( id__in=apps.get_model('orders.Order').objects.filter(course=self).paid().values_list('user_id'), ) def send_email_to_all_purchased_users(self, template_id: str): for user in self.get_purchased_users().iterator(): send_mail.delay( to=user.email, template_id=template_id, )
class Shippable(TimestampedModel): """Add this to every shippable item""" name = models.CharField(max_length=255) name_receipt = models.CharField( _('Name for receipts'), max_length=255, help_text= '«посещение мастер-класса по TDD» или «Доступ к записи курсов кройки и шитья»' ) full_name = models.CharField( _('Full name for letters'), max_length=255, help_text= 'Билет на мастер-класс о TDD или «запись курсов кройки и шитья»', ) slug = models.SlugField() price = models.DecimalField(max_digits=8, decimal_places=2) old_price = models.DecimalField(max_digits=8, decimal_places=2, blank=True, null=True) tinkoff_credit_promo_code = models.CharField( _('Fixed promo code for tinkoff credit'), max_length=64, blank=True, help_text=_('Used in tinkoff credit only')) class Meta: abstract = True def get_price_display(self): return format_price(self.price) def get_old_price_display(self): return format_price(self.old_price) def get_formatted_price_display(self): return format_old_price(self.old_price, self.price) def ship(self, to: User, order: Optional[Order] = None): return ShippingFactory.ship(self, to=to, order=order) def get_price(self, promocode=None) -> Decimal: promocode = apps.get_model('orders.PromoCode').objects.get_or_nothing( name=promocode) if promocode is not None: return promocode.apply(self.price) return self.price def get_template_id(self): """Get custom per-item template_id""" if not hasattr(self, 'template_id'): return if self.template_id is not None and len(self.template_id): return self.template_id
class Branch(Timestamped, AppModel): location = GeometryField( geography=True, blank=True, null=True, ) name = models.CharField( max_length=255, db_index=True, ) facade = models.ImageField( blank=True, upload_to=RandomPath('branches/facades'), ) objects = BranchQueryset.as_manager() class Meta: ordering = ['-id'] indexes = [ GistIndex(name='branch_name_gist_trgm_index', fields=['name'], opclasses=['gist_trgm_ops']), ] @property def employees_count(self) -> int: if hasattr(self, '_employees_count'): return self._employees_count # type: ignore return self.employees.count()
class Migration(migrations.Migration): dependencies = [ ('models', '0001_initial'), ] operations = [ migrations.CreateModel( name='Interface', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('local_interface', models.CharField(default=b'', max_length=30)), ('remote_interface', models.CharField(default=b'', max_length=30, null=True)), ('status', models.CharField(choices=[ (app.models.models.Status(b'Down'), b'Down'), (app.models.models.Status(b'Shutdown'), b'Shutdown'), (app.models.models.Status(b'Up'), b'Up') ], default=app.models.models.Status(b'Down'), max_length=50)), ('connected_interface', models.CharField(default=b'', max_length=30)), ('connected_router', models.CharField(default=b'', max_length=30)), ('card', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='card', to='models.Card')), ], ), ]
class CreditNotification(TimestampedModel): """Notification for credit order by TinkoffCredit""" STATUSES_CHOICES = ( ('approved', _('Approved')), ('rejected', _('Rejected')), ('canceled', _('Canceled')), ('signed', _('Signed')), ) order_id = models.IntegerField() status = models.CharField(max_length=32, choices=STATUSES_CHOICES) bank_created = models.DateTimeField() first_payment = models.DecimalField(max_digits=10, decimal_places=2) order_amount = models.DecimalField(max_digits=10, decimal_places=2) credit_amount = models.DecimalField(max_digits=10, decimal_places=2) product = models.CharField(max_length=128) term = models.IntegerField() monthly_payment = models.DecimalField(max_digits=10, decimal_places=2) phone = models.CharField(max_length=64, null=True, blank=True) first_name = models.CharField(max_length=128, null=True, blank=True) last_name = models.CharField(max_length=128, null=True, blank=True) middle_name = models.CharField(max_length=32, blank=True, null=True) loan_number = models.CharField(max_length=128, blank=True, null=True) email = models.CharField(max_length=128, null=True, blank=True)