Skip to content

Commit

Permalink
Merge pull request #2 from iamhks/master
Browse files Browse the repository at this point in the history
Activity Creation Revamp (unstructuredstudio#731)
  • Loading branch information
iamhks authored Sep 9, 2023
2 parents 4ac6b5a + baf7051 commit f4eba11
Show file tree
Hide file tree
Showing 68 changed files with 3,988 additions and 535 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2 on 2023-08-28 03:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('projects', '0010_alter_project_category'),
('activities', '0008_auto_20220829_1530'),
]

operations = [
migrations.AddField(
model_name='activity',
name='class_grade',
field=models.CharField(blank=True, max_length=50),
),
migrations.AddField(
model_name='activity',
name='introduction',
field=models.CharField(blank=True, max_length=10000),
),
migrations.RemoveField(
model_name='activity',
name='category',
),
migrations.AddField(
model_name='activity',
name='category',
field=models.ManyToManyField(blank=True, null=True, related_name='activities', to='projects.Category'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2 on 2023-08-28 05:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('activities', '0009_auto_20230828_0339'),
]

operations = [
migrations.RemoveField(
model_name='activitymakingstep',
name='image',
),
migrations.AddField(
model_name='activitymakingstep',
name='image',
field=models.ManyToManyField(blank=True, null=True, to='activities.Image'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2 on 2023-08-28 09:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('activities', '0010_auto_20230828_0520'),
]

operations = [
migrations.AddField(
model_name='activitymakingstep',
name='title',
field=models.TextField(max_length=500, null=True),
),
migrations.AlterField(
model_name='activitymakingstep',
name='image',
field=models.ManyToManyField(blank=True, to='activities.Image'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2 on 2023-08-28 09:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('projects', '0010_alter_project_category'),
('activities', '0011_auto_20230828_0940'),
]

operations = [
migrations.AlterField(
model_name='activity',
name='category',
field=models.ManyToManyField(blank=True, related_name='activities', to='projects.Category'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2023-08-31 19:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('activities', '0012_alter_activity_category'),
]

operations = [
migrations.AlterField(
model_name='activity',
name='materials_used',
field=models.TextField(max_length=5000, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2023-08-31 19:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('activities', '0013_alter_activity_materials_used'),
]

operations = [
migrations.AlterField(
model_name='activity',
name='materials_used',
field=models.TextField(blank=True, max_length=5000),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2023-08-31 19:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('activities', '0014_alter_activity_materials_used'),
]

operations = [
migrations.AlterField(
model_name='activity',
name='learning_goals',
field=models.TextField(blank=True, max_length=10000, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2 on 2023-08-31 19:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('activities', '0015_alter_activity_learning_goals'),
]

operations = [
migrations.AlterField(
model_name='activity',
name='facilitation_tips',
field=models.TextField(blank=True, max_length=10000, null=True),
),
migrations.AlterField(
model_name='activity',
name='motivation',
field=models.TextField(blank=True, max_length=10000, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2023-08-31 19:55

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('activities', '0016_auto_20230831_1954'),
]

operations = [
migrations.AlterField(
model_name='activity',
name='materials_used',
field=models.TextField(blank=True, max_length=5000, null=True),
),
]
24 changes: 11 additions & 13 deletions zubhub_backend/zubhub/activities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ class Activity(models.Model):
creators = models.ManyToManyField(Creator,
related_name="activities_created")
title = models.CharField(max_length=500)
learning_goals = models.TextField(max_length=10000, blank=True)
facilitation_tips = models.TextField(max_length=10000, blank=True)
motivation = models.TextField(max_length=10000, blank=True)
category = models.ForeignKey(Category,
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name="activities")
category = models.ManyToManyField("projects.Category",blank=True, related_name="activities")
introduction = models.CharField(max_length=10000,blank=True)
class_grade = models.CharField(max_length=50, blank=True)

learning_goals = models.TextField(max_length=10000, blank=True, null=True)
facilitation_tips = models.TextField(max_length=10000, blank=True, null=True)
motivation = models.TextField(max_length=10000, blank=True, null=True)
video = models.URLField(max_length=1000, blank=True, null=True)
materials_used = models.TextField(max_length=5000)
materials_used = models.TextField(max_length=5000, blank=True, null=True)
materials_used_image = models.ForeignKey(Image,
on_delete=models.SET_NULL,
null=True,
Expand Down Expand Up @@ -127,10 +126,9 @@ class ActivityMakingStep(models.Model):
null=True,
related_name="making_steps",
blank=True)
image = models.ForeignKey(Image,
on_delete=models.CASCADE,
null=True,
blank=True)

title = models.TextField(max_length=500,null=True)
image = models.ManyToManyField(Image,blank=True)
description = models.TextField(max_length=10000, blank=True)
step_order = models.IntegerField()

Expand Down
25 changes: 21 additions & 4 deletions zubhub_backend/zubhub/activities/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class Meta:


class ActivityMakingStepSerializer(serializers.ModelSerializer):
image = ImageSerializer(required=False, allow_null=True)
image = ImageSerializer(required=False, allow_null=True, many=True )
step_order = serializers.IntegerField()

class Meta:
model = ActivityMakingStep
fields = [
"image", "description", "step_order"
"image", "description", "step_order", "title"
]


Expand All @@ -70,7 +70,7 @@ class ActivitySerializer(serializers.ModelSerializer):
images = ActivityImageSerializer(
many=True, required=False, source="activity_images")
category = serializers.SlugRelatedField(
slug_field="name", queryset=Category.objects.all(), required=False)
slug_field="name", queryset=Category.objects.all(), many=True, required=False)
created_on = serializers.DateTimeField(read_only=True)
views_count = serializers.IntegerField(read_only=True)
saved_count = serializers.IntegerField(read_only=True)
Expand All @@ -88,6 +88,8 @@ class Meta:
"inspired_projects",
"creators",
"title",
"introduction",
"class_grade",
"motivation",
"images",
"video",
Expand Down Expand Up @@ -119,8 +121,13 @@ def create(self, validated_data):
making_steps = validated_data.pop('making_steps', None)

inspiring_examples = validated_data.pop('inspiring_examples', None)
category = validated_data.pop('category',None)

activity = Activity.objects.create(**validated_data)

if(category):
activity.category.set(category)

if making_steps:
create_making_steps(activity, making_steps)
if inspiring_examples:
Expand Down Expand Up @@ -177,10 +184,20 @@ def update(self, activity, validated_data):
update_inspiring_examples(
activity, validated_data.pop('inspiring_examples'))
activity.title = validated_data.get('title')

if validated_data.get('introduction'):
activity.introduction = validated_data.get('introduction')

activity.motivation = validated_data.get('motivation')
activity.facilitation_tips = validated_data.get('facilitation_tips')
activity.learning_goals = validated_data.get('learning_goals')
activity.materials_used = validated_data.get('materials_used')

if validated_data.get('publish'):
activity.publish = validated_data.get('publish')

if validated_data.get('materials_used'):
activity.materials_used = validated_data.get('materials_used')

activity.video = validated_data.get('video')
activity.save()
return activity
4 changes: 2 additions & 2 deletions zubhub_backend/zubhub/activities/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
path('<uuid:pk>/update/', ActivityUpdateAPIView.as_view(), name='update'),
path('<uuid:pk>/delete/', ActivityDeleteAPIView.as_view(), name='delete'),
path('<uuid:pk>/toggle-save/', ToggleSaveAPIView.as_view(), name='save'),
path('<uuid:pk>/toggle-publish/', togglePublishActivityAPIView.as_view(), name='publish')

path('<uuid:pk>/toggle-publish/', togglePublishActivityAPIView.as_view(), name='publish'),
path('<uuid:pk>/', ActivityDetailsAPIView.as_view(), name='detail_activity')
]
19 changes: 14 additions & 5 deletions zubhub_backend/zubhub/activities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ def create_inspiring_artist(inspiring_artist_data):


def create_making_steps(activity, making_steps):
for step in making_steps:
if(step.get('image')):
saved_image = Image.objects.create(**step['image'])
step['image'] = saved_image
ActivityMakingStep.objects.create(activity=activity, **step)
for step_data in making_steps:
step_images_data = step_data.pop('image', []) # Extract and remove the 'image' key

# Create the ActivityMakingStep instance
step = ActivityMakingStep.objects.create(activity=activity, **step_data)

# Create or retrieve Image instances and associate them with the step
step_images = []
for image_info in step_images_data:
image = Image.objects.create(**image_info)
step_images.append(image)

# Associate the Image instances with the step using the set() method
step.image.set(step_images)


def create_inspiring_examples(activity, inspiring_examples):
Expand Down
Loading

0 comments on commit f4eba11

Please sign in to comment.