diff --git a/zubhub_backend/zubhub/projects/models.py b/zubhub_backend/zubhub/projects/models.py index 3ddf9c569..f7efe67ed 100644 --- a/zubhub_backend/zubhub/projects/models.py +++ b/zubhub_backend/zubhub/projects/models.py @@ -18,7 +18,7 @@ class Project(models.Model): title = models.CharField(max_length=1000) description = models.CharField(max_length=10000, blank=True, null=True) video = models.URLField(max_length=1000, blank=True, null=True) - materials_used = models.CharField(max_length=10000) + materials_used = models.CharField(max_length=5000) views = models.ManyToManyField( Creator, blank=True, related_name="projects_viewed") views_count = models.IntegerField(blank=True, default=0) diff --git a/zubhub_backend/zubhub/projects/serializers.py b/zubhub_backend/zubhub/projects/serializers.py index e0bacc93b..b60192385 100644 --- a/zubhub_backend/zubhub/projects/serializers.py +++ b/zubhub_backend/zubhub/projects/serializers.py @@ -1,3 +1,4 @@ +from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers from django.contrib.auth import get_user_model from creators.serializers import CreatorSerializer @@ -40,8 +41,9 @@ class ProjectSerializer(serializers.ModelSerializer): saved_by = serializers.SlugRelatedField( many=True, slug_field='id', read_only=True) comments = CommentSerializer(many=True, read_only=True) - images = ImageSerializer(many=True) + images = ImageSerializer(many=True, required=False) created_on = serializers.DateTimeField(read_only=True) + views_count = serializers.IntegerField(read_only=True) class Meta: model = Project @@ -60,6 +62,18 @@ class Meta: "created_on", ] + def validate_video(self, video): + if(video == "" and len(self.initial_data.get("images")) == 0): + raise serializers.ValidationError( + _("you must provide either image(s) or video url")) + return video + + def validate_images(self, images): + if(len(images) == 0 and len(self.initial_data["video"]) == 0): + raise serializers.ValidationError( + _("you must provide either image(s) or video url")) + return images + def create(self, validated_data): images_data = validated_data.pop('images') project = Project.objects.create(**validated_data) diff --git a/zubhub_frontend/zubhub/src/components/pages/profile/Profile.jsx b/zubhub_frontend/zubhub/src/components/pages/profile/Profile.jsx index 5d423c3ab..ed76af345 100644 --- a/zubhub_frontend/zubhub/src/components/pages/profile/Profile.jsx +++ b/zubhub_frontend/zubhub/src/components/pages/profile/Profile.jsx @@ -374,37 +374,15 @@ class Profile extends Component { {this.props.auth.username === profile.username ? ( - <> - - - - - - + ) : ( @@ -570,7 +593,6 @@ class CreateProject extends Component { this.props.touched["video"] && this.props.errors["video"] } - helperText={this.props.errors["video"]} > - {this.props.errors["video"]} + {this.props.touched["video"] && + this.props.errors["video"]} @@ -600,6 +623,10 @@ class CreateProject extends Component { size="small" fullWidth margin="small" + error={ + this.props.touched["materials_used"] && + this.props.errors["materials_used"] + } > + this.props.setFieldTouched("materials_used") + } + onChange={this.handleAddMaterialFieldChange} + onBlur={() => + this.props.validateField("materials_used") + } /> - {this.props.errors["materials_used"]} + {this.props.touched["materials_used"] && + this.props.errors["materials_used"]} @@ -655,7 +689,7 @@ class CreateProject extends Component { @@ -666,56 +700,13 @@ class CreateProject extends Component { variant="contained" size="large" className={classes.primaryButton} - onClick={this.create_project} + onClick={this.init_project} > Create Project - - - Add New Material - - - - - New Material - - - - - - - - - - ) : ( + ) : project.images.length > 0 ? ( {project.title} - )} + ) : null} - ) : ( + ) : project.images.length > 0 ? ( {project.title} - )} + ) : null}