Beispiel #1
0
    def clean_code(self):
        code = self.cleaned_data['code'].lower()

        conflict = None
        sms_codes = all_sms_codes(self.product.domain)
        if code in sms_codes:
            conflict = sms_codes[code]
            if conflict[0] == 'product' and conflict[1]._id == self.product._id:
                conflict = None

        if conflict:
            conflict_name = {
                'product': lambda o: o.name,
                'action': lambda o: o.caption,
                'command': lambda o: o['caption'],
            }[conflict[0]](conflict[1])
            raise forms.ValidationError('sms code not unique (conflicts with %s "%s")' % (conflict[0], conflict_name))

        return code.lower()
Beispiel #2
0
    def clean_code(self):
        code = self.cleaned_data["code"].lower()

        conflict = None
        sms_codes = all_sms_codes(self.product.domain)
        if code in sms_codes:
            conflict = sms_codes[code]
            if conflict[0] == "product" and conflict[1]._id == self.product._id:
                conflict = None

        if conflict:
            conflict_name = {
                "product": lambda o: o.name,
                "action": lambda o: o.caption,
                "command": lambda o: o["caption"],
            }[conflict[0]](conflict[1])
            raise forms.ValidationError('product id not unique (conflicts with %s "%s")' % (conflict[0], conflict_name))

        return code.lower()
Beispiel #3
0
 def other_sms_codes():
     for k, v in all_sms_codes(domain.name).iteritems():
         if v[0] == 'product':
             yield (k, (v[0], v[1].name))
Beispiel #4
0
 def get_other_sms_codes(self):
     for k, v in all_sms_codes(self.domain).iteritems():
         if v[0] == 'product':
             yield (k, (v[0], v[1].name))
Beispiel #5
0
 def other_sms_codes():
     for k, v in all_sms_codes(domain.name).iteritems():
         if v[0] == 'product':
             yield (k, (v[0], v[1].name))