diff --git a/breathecode/admissions/views.py b/breathecode/admissions/views.py index 2ade4738e..e742b80e6 100644 --- a/breathecode/admissions/views.py +++ b/breathecode/admissions/views.py @@ -593,7 +593,7 @@ def get(self, request, format=None, cohort_id=None, user_id=None, academy_id=Non if users is not None: items = items.filter(user__id__in=users.split(',')) - items = items.order_by(request.GET.get('sort', '-role')) + items = items.order_by(request.GET.get('sort', '-created_at')) except Exception as e: raise ValidationException(str(e), 400) diff --git a/breathecode/marketing/actions.py b/breathecode/marketing/actions.py index 694b46b43..87f3e47bc 100644 --- a/breathecode/marketing/actions.py +++ b/breathecode/marketing/actions.py @@ -136,7 +136,7 @@ def validate_email(email, lang): 'El correo electrónico que haz especificado parece inválido, por favor corrige tu correo electronico', slug='invalid-email')) - if 'score' in data and data['score'] < 50: + if 'score' in data and data['score'] < 0.60: raise ValidationException(translation( lang, en= diff --git a/breathecode/mentorship/serializers.py b/breathecode/mentorship/serializers.py index b4a3d3b2c..148bc87db 100644 --- a/breathecode/mentorship/serializers.py +++ b/breathecode/mentorship/serializers.py @@ -1,4 +1,5 @@ import serpy +from breathecode.payments.models import Consumable from breathecode.utils import ValidationException from .models import MentorshipSession, MentorshipService, MentorProfile, MentorshipBill import breathecode.mentorship.actions as actions @@ -724,10 +725,15 @@ def validate(self, data): mentee = None if 'mentee' in data: - if data['mentee'] and isinstance(data['mentee'], str) and not data['mentee'].isnumeric(): - mentee = CohortUser.objects.filter(email=data['mentee']).first() + if not data['mentee'].isnumeric(): + mentee = Consumable.objects.filter( + mentorship_service_set__mentorship_services__id=data['service'], + user__email=data['mentee']).first() + else: - mentee = CohortUser.objects.filter(user__id=data['mentee']).first() + mentee = Consumable.objects.filter( + mentorship_service_set__mentorship_services__id=data['service'], + user__id=data['mentee']).first() if mentee is None: raise ValidationException(translation( diff --git a/breathecode/mentorship/tests/urls/tests_academy_session.py b/breathecode/mentorship/tests/urls/tests_academy_session.py index 04453d8e4..21c16eae6 100644 --- a/breathecode/mentorship/tests/urls/tests_academy_session.py +++ b/breathecode/mentorship/tests/urls/tests_academy_session.py @@ -1204,9 +1204,10 @@ def test__post__creating_a_element__mentor_and_mentee_can_be_same_person(self): role=1, capability='crud_mentorship_session', mentor_profile=1, - cohort_user=1, + consumable=1, mentorship_bill=1, mentorship_service=1, + mentorship_service_set=1, profile_academy=1) self.bc.request.set_headers(academy=1) @@ -1254,14 +1255,15 @@ def test__post__creating_a_element__mentor_and_mentee_can_be_same_person(self): @patch('breathecode.admissions.signals.student_edu_status_updated.send', MagicMock()) def test__post__creating_a_element__passing_all_the_fields(self): utc_now = timezone.now() - cohort_user = {'user_id': 2, 'cohort_id': 1} + consumable = {'user_id': 2} model = self.bc.database.create(user=2, role=1, capability='crud_mentorship_session', mentor_profile=1, - cohort_user=cohort_user, + consumable=consumable, mentorship_bill=1, mentorship_service=1, + mentorship_service_set=1, profile_academy=1) self.bc.request.set_headers(academy=1) diff --git a/breathecode/provisioning/management/commands/sync_assignments.py b/breathecode/provisioning/management/commands/sync_assignments.py new file mode 100644 index 000000000..9292bb1c9 --- /dev/null +++ b/breathecode/provisioning/management/commands/sync_assignments.py @@ -0,0 +1,88 @@ +import os, requests, sys, pytz +from datetime import datetime +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User +from ...models import Task +from ...actions import sync_student_tasks +from breathecode.admissions.models import CohortUser +from django.db.models import Count + +HOST = os.environ.get('OLD_BREATHECODE_API') +DATETIME_FORMAT = '%Y-%m-%d' + + +class Command(BaseCommand): + help = 'Sync academies from old breathecode' + + def add_arguments(self, parser): + parser.add_argument('entity', type=str) + parser.add_argument( + '--cohorts', + type=str, + default=None, + help='Cohorts slugs to sync', + ) + parser.add_argument( + '--students', + type=str, + default=None, + help='Cohorts slugs to sync', + ) + parser.add_argument('--limit', + action='store', + dest='limit', + type=int, + default=0, + help='How many to import') + + def handle(self, *args, **options): + try: + func = getattr(self, options['entity'], 'entity_not_found') + except TypeError: + print(f'Sync method for {options["entity"]} no Found!') + func(options) + + def tasks(self, options): + + limit = False + total = 0 + if 'limit' in options and options['limit']: + limit = options['limit'] + + if options['students'] is not None: + emails = options['students'].split(',') + for email in emails: + total += 1 + if limit and limit > 0 and total > limit: + self.stdout.write( + self.style.SUCCESS( + f'Stopped at {total} because there was a limit on the command arguments')) + return + + user = User.objects.filter(email=email).first() + if user is None: + raise CommandError(f'Student {email} not found new API') + + sync_student_tasks(user) + else: + users = CohortUser.objects.filter(role='STUDENT').values('user').annotate(dcount=Count('user')) + self.stdout.write(self.style.NOTICE(f'Analyzing {users.count()} cohort users')) + for u in users: + if limit and limit > 0 and total > limit: + self.stdout.write( + self.style.SUCCESS( + f'Stopped at {total} because there was a limit on the command arguments')) + return + + user = User.objects.get(id=u['user']) + if user.task_set.count() == 0: + self.stdout.write(self.style.SUCCESS(f'Fetching tasks for student {user.email}')) + else: + self.stdout.write(self.style.NOTICE(f'Tasks already fetched for {user.email}')) + continue + + total += 1 + try: + sync_student_tasks(user) + except Exception as e: + self.stdout.write(self.style.NOTICE(f'Error synching student stasks for {user.email}')) diff --git a/breathecode/registry/actions.py b/breathecode/registry/actions.py index 6f661c90f..edfa234ca 100644 --- a/breathecode/registry/actions.py +++ b/breathecode/registry/actions.py @@ -65,7 +65,10 @@ def generate_external_readme(a): if not a.external: return False - readme = get_template('external.md') + if a.lang == 'us': + readme = get_template('external.md') + else: + readme = get_template(f'external.{a.lang}.md') a.set_readme(readme.render(AssetBigSerializer(a).data)) a.save() return True diff --git a/breathecode/registry/templates/external.es.md b/breathecode/registry/templates/external.es.md new file mode 100644 index 000000000..764e77962 --- /dev/null +++ b/breathecode/registry/templates/external.es.md @@ -0,0 +1,5 @@ +Encontramos un recurso muy bueno afuera de 4Geeks para practicar esta habilidad. + +Por favor [haz click aquí para abrirlo en una nueva ventana]({{ url }}). + +{{ description }}