Skip to content

Commit

Permalink
Merge pull request breatheco-de#1027 from jefer94/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
jefer94 authored Aug 9, 2023
2 parents dbb58d7 + 6171023 commit 57c62d7
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 9 deletions.
2 changes: 1 addition & 1 deletion breathecode/admissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion breathecode/marketing/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
12 changes: 9 additions & 3 deletions breathecode/mentorship/serializers.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions breathecode/mentorship/tests/urls/tests_academy_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
88 changes: 88 additions & 0 deletions breathecode/provisioning/management/commands/sync_assignments.py
Original file line number Diff line number Diff line change
@@ -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}'))
5 changes: 4 additions & 1 deletion breathecode/registry/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions breathecode/registry/templates/external.es.md
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit 57c62d7

Please sign in to comment.