diff --git a/zubhub_backend/zubhub/creators/adapter.py b/zubhub_backend/zubhub/creators/adapter.py index aa4d69143..34ed89b16 100644 --- a/zubhub_backend/zubhub/creators/adapter.py +++ b/zubhub_backend/zubhub/creators/adapter.py @@ -38,6 +38,7 @@ def save_user(self, request, user, form, commit=False): creator.bio = data.get('bio') creator.location = location creator.is_active = is_active + creator.tags.set(data.get('creator_tags')) creator.save() Setting(creator=creator, subscribe=data.get("subscribe")).save() diff --git a/zubhub_backend/zubhub/creators/serializers.py b/zubhub_backend/zubhub/creators/serializers.py index 8d58e99e7..7aa1cc8e1 100644 --- a/zubhub_backend/zubhub/creators/serializers.py +++ b/zubhub_backend/zubhub/creators/serializers.py @@ -8,8 +8,7 @@ from django.utils.translation import gettext_lazy as _ import csv from .admin import badges -from .models import CreatorGroup, Creator, CreatorGroupMembership -from .models import Location, PhoneNumber +from .models import CreatorGroup, Creator, CreatorGroupMembership, Location, PhoneNumber, CreatorTag from allauth.account.models import EmailAddress from rest_auth.registration.serializers import RegisterSerializer from rest_auth.serializers import PasswordResetSerializer @@ -199,6 +198,8 @@ class CustomRegisterSerializer(RegisterSerializer): queryset=Location.objects.all()) bio = serializers.CharField(allow_blank=True, default="", max_length=255) subscribe = serializers.BooleanField(default=False) + creator_tags = serializers.SlugRelatedField(slug_field='name', + queryset=CreatorTag.objects.all()) def validate_username(self, username): # Check if the value is a valid email @@ -247,6 +248,14 @@ def validate_location(self, location): raise serializers.ValidationError(_("Location is required")) return location + def validate_creator_tags(self, creator_tags): + if (len(creator_tags) < 1): + raise serializers.ValidationError(_("Creator tags are required")) + for tag in creator_tags: + if not CreatorTag.objects.filter(name=tag).exists(): + raise serializers.ValidationError(_("Invalid creator tag: {}".format(tag))) + return creator_tags + def get_cleaned_data(self): data_dict = super().get_cleaned_data() data_dict['phone'] = self.validated_data.get('phone', '') @@ -254,6 +263,7 @@ def get_cleaned_data(self): data_dict['location'] = self.validated_data.get('location', '') data_dict['bio'] = self.validated_data.get('bio', '') data_dict['subscribe'] = self.validated_data.get('subscribe', '') + data_dict['creator_tags'] = self.validated_data.get('creator_tags', '') return data_dict diff --git a/zubhub_backend/zubhub/creators/views.py b/zubhub_backend/zubhub/creators/views.py index 76c4df953..d16bb32bd 100644 --- a/zubhub_backend/zubhub/creators/views.py +++ b/zubhub_backend/zubhub/creators/views.py @@ -1,5 +1,3 @@ -import csv -from io import StringIO from django.forms import ValidationError from django.utils.translation import ugettext_lazy as _ from notifications.models import Notification @@ -188,6 +186,7 @@ class RegisterCreatorAPIView(RegisterView): "location": "string",\n "bio": "",\n "subscribe": false\n + "creator_tags": "string",\n }\n """ diff --git a/zubhub_frontend/zubhub/package-lock.json b/zubhub_frontend/zubhub/package-lock.json index 3da6c441f..3dc17a544 100644 --- a/zubhub_frontend/zubhub/package-lock.json +++ b/zubhub_frontend/zubhub/package-lock.json @@ -23,6 +23,7 @@ "axios": "^1.5.1", "caniuse-lite": "^1.0.30001543", "classnames": "^2.2.6", + "clsx": "^2.1.0", "compressorjs": "^1.0.7", "dayjs": "^1.11.10", "formik": "^2.2.5", @@ -35,6 +36,7 @@ "lodash": "^4.17.21", "nanoid": "^3.3.1", "pdfmake": "^0.2.7", + "prop-types": "^15.0.0", "quill": "^1.3.7", "react": "^17.0.0", "react-confetti": "^6.1.0", diff --git a/zubhub_frontend/zubhub/src/views/create_project/script.js b/zubhub_frontend/zubhub/src/views/create_project/script.js index c2b367a2c..19e6343e4 100644 --- a/zubhub_frontend/zubhub/src/views/create_project/script.js +++ b/zubhub_frontend/zubhub/src/views/create_project/script.js @@ -693,20 +693,7 @@ export const validationSchema = Yup.object().shape({ // ? false // : true; // }), - materials_used: Yup.string() - .max(10000, 'max') - .test('empty', 'required', value => { - let is_empty = true; - - value && - value.split(',').forEach(material => { - if (material) { - is_empty = false; - } - }); - - return !is_empty; - }), + materials_used: Yup.string().required('required'), category: Yup.string(), // tags: Yup.mixed().test('unsupported', 'unsupported', tags => { // if (tags) {