| Total Lines | 19 |
| Duplicated Lines | 100 % |
| Changes | 0 | ||
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 | # coding: utf8 |
||
| 32 | View Code Duplication | class SparkleVersionSerializer(serializers.HyperlinkedModelSerializer): |
|
|
|
|||
| 33 | is_enabled = serializers.BooleanField(default=True, required=False) |
||
| 34 | app = serializers.PrimaryKeyRelatedField(queryset=Application.objects.all()) |
||
| 35 | channel = serializers.PrimaryKeyRelatedField(queryset=Channel.objects.all()) |
||
| 36 | version = serializers.CharField() |
||
| 37 | short_version = serializers.CharField(required=False) |
||
| 38 | |||
| 39 | class Meta: |
||
| 40 | model = SparkleVersion |
||
| 41 | fields = ('id', 'is_enabled', 'is_critical', 'app', 'channel', 'version', 'short_version', |
||
| 42 | 'release_notes', 'file', 'file_size', 'dsa_signature', |
||
| 43 | 'created', 'modified') |
||
| 44 | read_only_fields = ('created', 'modified') |
||
| 45 | |||
| 46 | def create(self, validated_data): |
||
| 47 | if not validated_data.get('file_size'): |
||
| 48 | file = validated_data['file'] |
||
| 49 | validated_data['file_size'] = file.size |
||
| 50 | return super(SparkleVersionSerializer, self).create(validated_data) |
||
| 51 |