Total Complexity | 3 |
Total Lines | 23 |
Duplicated Lines | 100 % |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | # Copyright 2013 Mathias WOLFF |
||
25 | View Code Duplication | class FSIntegerField(models.CharField): |
|
|
|||
26 | """ |
||
27 | A field that will accept FreeSWITCH config file variables, or integers. |
||
28 | |||
29 | Stores as string. |
||
30 | """ |
||
31 | default_validators = [validators.validate_freeswitch_integer] |
||
32 | default_error_messages = { |
||
33 | 'invalid': _('This value must be an integer or a FreeSWITCH variable.'), |
||
34 | } |
||
35 | description = _("Integer or FreeSWITCH variable") |
||
36 | |||
37 | def __init__(self, *args, **kwargs): |
||
38 | kwargs['max_length'] = kwargs.get('max_length', 64) |
||
39 | super(FSIntegerField, self).__init__(*args, **kwargs) |
||
40 | |||
41 | def to_python(self, value): |
||
42 | try: |
||
43 | value = smart_unicode(int(value)) |
||
44 | except (TypeError, ValueError): |
||
45 | pass |
||
46 | validators.validate_freeswitch_integer(value) |
||
47 | return value |
||
48 | |||
67 | super(FSIPAddressField, self).__init__(*args, **kwargs) |