def __init__(self, *args, **kwargs): super(GenericForm, self).__init__(*args, **kwargs) backends = get_backend_choices() self.fields['backend'] = ChoiceField( choices=backends, initial=backends[0][0] if len(backends) else '', widget=widgets.HiddenInput, )
def __init__(self, *args, **kwargs): super(GenericForm, self).__init__(*args, **kwargs) backends = get_backend_choices() self.fields['backend'] = ChoiceField( choices = backends, initial= backends[0][0] if len(backends) else '', widget = widgets.HiddenInput, )
def __init__(self, currency, *args, **kwargs): super(PaymentMethodForm, self).__init__(*args, **kwargs) backends = get_backend_choices(currency) self.fields['backend'] = ChoiceField( choices=backends, initial=backends[0][0] if len(backends) else '', label=_("Payment method"), widget=PaymentRadioSelect, )
def __init__(self, currency, *args, **kwargs): super(PaymentMethodForm, self).__init__(*args, **kwargs) backends = get_backend_choices(currency) self.fields['backend'] = ChoiceField( choices = backends, initial= backends[0][0] if len(backends) else '', label = _("Payment method"), widget = PaymentRadioSelect, )
class PaymentMethodForm(forms.Form): """Shows choice field with all active payment backends. You may use it with existing Payment instance to push it through all the remaining logic, getting the link to the next payment step from proceed_to_gateway() method.""" backend = forms.ChoiceField( choices=get_backend_choices(), label=_("Payment method"), ) def __init__(self, *args, **kwargs): self.payment = kwargs.pop('payment', None) super(PaymentMethodForm, self).__init__(*args, **kwargs) def save(self, payment=None): if not payment: payment = self.payment payment.backend = self.cleaned_data['backend'] payment.save()
class Message(models.Model): account = models.ForeignKey(Account) to = models.CharField(max_length=64) body = models.TextField() flash = models.BooleanField(blank=True, default=False) backend = models.CharField(choices=get_backend_choices(), max_length=128) created = models.DateTimeField(auto_now_add=True, blank=True) sended = models.DateTimeField(blank=True, null=True) publish_date = models.DateTimeField(blank=True, null=True, db_index=True) response = models.TextField(blank=True, null=True) def get_connection(self, fail_silently=False): if not self.backend: return self.connection = get_connection(path=self.backend, fail_silently=fail_silently) return self.connection def save(self, *args, **kwargs): super(Message, self).save(*args, **kwargs) if (not self.publish_date or self.publish_date and self.publish_date<=datetime.datetime.now()) and not self.sended: """ Если это новое сообщение, без даты публикации и оно не помечено отосланным """ self.send() def set_body(self): self.body = Template(self.body).render(Context({'account':self.account})) super(Message, self).save() class Meta: ordering = ('-created',) def get_remove_url(self): return "%s?id=%s" % (reverse('sms_delete'), self.id) def send(self, fail_silently=False): """ Sends the sms message """ if not self.to: # Don't bother creating the connection if there's nobody to send to return 0 self.set_body() self.get_connection(False).send_message(self)