Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/breatheco-de/apiv2 i…
Browse files Browse the repository at this point in the history
…nto feat/capy-serializers
  • Loading branch information
jefer94 committed Dec 2, 2024
2 parents 7757e19 + 5b1b2c3 commit 936dc81
Show file tree
Hide file tree
Showing 90 changed files with 2,748 additions and 1,600 deletions.
1,577 changes: 797 additions & 780 deletions Pipfile.lock

Large diffs are not rendered by default.

49 changes: 0 additions & 49 deletions breathecode/admissions/tests/permissions/contexts/tests_academy.py

This file was deleted.

5 changes: 4 additions & 1 deletion breathecode/admissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,9 @@ def get(self, request, syllabus_id, version, academy_id):
# Write the data rows for each day
for day in sorted(syllabus_version.json["days"], key=lambda x: x["position"]):
week_number = math.ceil(cumulative_days / class_days_per_week)
if "technologies" not in day:
day["technologies"] = []

if lang == "es":
writer.writerow(
[
Expand All @@ -1866,7 +1869,7 @@ def get(self, request, syllabus_id, version, academy_id):
day.get("teacher_instructions", ""),
]
)
cumulative_days += day["duration_in_days"]
cumulative_days += day["duration_in_days"] if "duration_in_days" in day else 1
return response


Expand Down
8 changes: 6 additions & 2 deletions breathecode/assessment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,18 @@ def __init__(self, *args, **kwargs):
self._old_status = self.status

def save(self, *args, **kwargs):

is_creating = self.pk is None
if not self.pk:
self.token = binascii.hexlify(os.urandom(20)).decode()

_instance = super().save(*args, **kwargs)

# Answer is being closed
if self.status != self._old_status:
if is_creating or self.status != self._old_status:
signals.userassessment_status_updated.send_robust(instance=self, sender=self.__class__)

return super().save(*args, **kwargs)
return _instance

def get_score(self):

Expand Down
12 changes: 11 additions & 1 deletion breathecode/assessment/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,24 @@ class HookUserAssessmentSerializer(serpy.Serializer):
status_text = serpy.Field()

conversion_info = serpy.Field()
total_score = serpy.Field()
comment = serpy.Field()

started_at = serpy.Field()
finished_at = serpy.Field()

created_at = serpy.Field()

summary = serpy.MethodField()

def get_summary(self, obj):
total_score, last_one = obj.get_score()

last_answer = None
if last_one is not None:
last_answer = AnswerSmallSerializer(last_one).data

return {"last_answer": last_answer, "live_score": total_score}


class PublicUserAssessmentSerializer(serpy.Serializer):
id = serpy.Field()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def fill_whitelist(self):
asset.readme_url,
asset.intro_video_url,
asset.solution_video_url,
asset.template_url,
]
for url in [x for x in options if x]:
match = self.github_url_pattern.search(url)
Expand Down
9 changes: 8 additions & 1 deletion breathecode/authenticate/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from task_manager.django.actions import schedule_task

import breathecode.notify.actions as notify_actions
from breathecode.admissions.models import Academy, Cohort
from breathecode.admissions.models import Academy, Cohort, CohortUser
from breathecode.authenticate.actions import get_app_url, get_user_settings
from breathecode.authenticate.tasks import verify_user_invite_email
from breathecode.events.models import Event
Expand Down Expand Up @@ -952,6 +952,13 @@ def create(self, validated_data):
)
profile_academy.save()

for c in cohort:
CohortUser.objects.create(
cohort=c,
role="STUDENT",
user=user,
)

notify_actions.send_email_message(
"academy_invite",
email,
Expand Down
Empty file.
Empty file.
50 changes: 0 additions & 50 deletions breathecode/authenticate/tests/permissions/contexts/tests_user.py

This file was deleted.

5 changes: 3 additions & 2 deletions breathecode/authenticate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,8 @@ def save_github_token(request):
else:
logger.error("Failed user registration on rigobot")

return HttpResponseRedirect(redirect_to=url + "?token=" + token.key)
redirect_url = set_query_parameter(url, "token", token.key)
return HttpResponseRedirect(redirect_to=redirect_url)

else:
raise APIException("Error from github")
Expand Down Expand Up @@ -1842,7 +1843,7 @@ def render_invite(request, token, member_id=None):
),
slug="invite-not-found",
)

return render_message(
request, "Invitation not found or it was already accepted" + callback_msg, academy=academy
)
Expand Down
1 change: 1 addition & 0 deletions breathecode/commons/tests/signals/tests_update_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def test_model_cache__many_to_one(cache_cls, value):
CohortCache,
set(
[
marketing_models.Course,
payments_models.CohortSet,
payments_models.PlanFinancing,
payments_models.Subscription,
Expand Down
24 changes: 24 additions & 0 deletions breathecode/events/migrations/0060_eventtype_technologies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.1.2 on 2024-11-18 15:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("events", "0059_event_asset_slug"),
]

operations = [
migrations.AddField(
model_name="eventtype",
name="technologies",
field=models.CharField(
blank=True,
default=None,
help_text="Add comma-separated list of technologies",
max_length=200,
null=True,
),
),
]
21 changes: 21 additions & 0 deletions breathecode/events/migrations/0061_event_is_public.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.1.2 on 2024-11-25 17:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("events", "0060_eventtype_technologies"),
]

operations = [
migrations.AddField(
model_name="event",
name="is_public",
field=models.BooleanField(
default=True,
help_text="If true, then it will be shown in cards and the workshop's landing page. Otherwise it will be hidden.",
),
),
]
11 changes: 11 additions & 0 deletions breathecode/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class EventType(models.Model):
default=True, help_text="Other academies are allowed to create events of this type"
)

technologies = models.CharField(
max_length=200, null=True, default=None, blank=True, help_text="Add comma-separated list of technologies"
)

created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False)

Expand Down Expand Up @@ -272,6 +276,13 @@ def __init__(self, *args, **kwargs):
created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False)

is_public = models.BooleanField(
default=True,
blank=False,
null=False,
help_text="If true, then it will be shown in cards and the workshop's landing page. Otherwise it will be hidden.",
)

def __str__(self):
return self.title or "No title"

Expand Down
4 changes: 4 additions & 0 deletions breathecode/events/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class EventTypeSmallSerializer(serpy.Serializer):
id = serpy.Field()
slug = serpy.Field()
name = serpy.Field()
technologies = serpy.Field()


class EventTypeSerializer(EventTypeSmallSerializer):
Expand Down Expand Up @@ -189,6 +190,7 @@ class EventSmallSerializer(EventTinySerializer):
host_user = UserBigSerializer(required=False)
author = UserSerializer(required=False)
asset = serpy.MethodField()
is_public = serpy.Field()

def get_asset(self, obj):
if obj.asset_slug is not None:
Expand Down Expand Up @@ -244,6 +246,7 @@ class EventSmallSerializerNoAcademy(serpy.Serializer):
eventbrite_sync_status = serpy.Field()
eventbrite_sync_description = serpy.Field()
tags = serpy.Field()
is_public = serpy.Field()


class EventPublicBigSerializer(EventSmallSerializer):
Expand Down Expand Up @@ -295,6 +298,7 @@ class AcademyEventSmallSerializer(serpy.Serializer):
author = UserSerializer(required=False)
free_for_all = serpy.Field()
asset = serpy.MethodField()
is_public = serpy.Field()

def get_asset(self, obj):
if obj.asset_slug is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def test_update_or_create_event__with_academy(self):
"asset_slug": None,
"free_for_all": False,
"uuid": uuid,
"is_public": True,
}

self.assertEqual(self.bc.database.list_of("events.Event"), [kwargs])
Expand Down Expand Up @@ -292,6 +293,7 @@ def test_update_or_create_event__with_event(self):
"asset_slug": None,
"free_for_all": False,
"uuid": uuid,
"is_public": True,
}

self.assertEqual(self.bc.database.list_of("events.Event"), [kwargs])
9 changes: 6 additions & 3 deletions breathecode/events/tests/mixins/new_events_tests_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
"""

import os

from django.urls import reverse_lazy
from rest_framework.test import APITestCase

from breathecode.tests.mixins import (
GenerateModelsMixin,
BreathecodeMixin,
CacheMixin,
DatetimeMixin,
GenerateModelsMixin,
GenerateQueriesMixin,
HeadersMixin,
DatetimeMixin,
ICallMixin,
BreathecodeMixin,
)


Expand Down Expand Up @@ -78,6 +80,7 @@ def check_all_academy_events(self, models=None):
"sync_with_eventbrite": model["event"].sync_with_eventbrite,
"eventbrite_sync_description": model["event"].eventbrite_sync_description,
"eventbrite_sync_status": model["event"].eventbrite_sync_status,
"is_public": model["event"].is_public,
}
for model in models
]
Expand Down
Empty file.
Empty file.
Loading

0 comments on commit 936dc81

Please sign in to comment.