Skip to content

Commit

Permalink
Merge pull request breatheco-de#1399 from tommygonzaleza/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
tommygonzaleza authored Jun 25, 2024
2 parents 1b7f6c1 + 25b35ee commit fd31ddd
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 118 deletions.
31 changes: 15 additions & 16 deletions breathecode/assessment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,28 @@
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView
from breathecode.utils import (
APIViewExtensions,
GenerateLookupsMixin,
)

from breathecode.authenticate.actions import get_user_language
from breathecode.utils import capable_of
from breathecode.utils import APIViewExtensions, GenerateLookupsMixin, capable_of
from breathecode.utils.i18n import translation
from capyc.rest_framework.exceptions import ValidationException

from .models import Assessment, AssessmentThreshold, Option, Question, UserAssessment, Answer, AssessmentLayout
from .models import Answer, Assessment, AssessmentLayout, AssessmentThreshold, Option, Question, UserAssessment
from .serializers import (
AnswerSerializer,
AnswerSmallSerializer,
AssessmentPUTSerializer,
GetAssessmentBigSerializer,
GetAssessmentLayoutSerializer,
GetAssessmentSerializer,
GetAssessmentThresholdSerializer,
OptionSerializer,
QuestionSerializer,
GetAssessmentLayoutSerializer,
SmallUserAssessmentSerializer,
GetUserAssessmentSerializer,
OptionSerializer,
PostUserAssessmentSerializer,
PUTUserAssessmentSerializer,
AnswerSerializer,
AnswerSmallSerializer,
PublicUserAssessmentSerializer,
PUTUserAssessmentSerializer,
QuestionSerializer,
SmallUserAssessmentSerializer,
)


Expand Down Expand Up @@ -406,12 +402,15 @@ def get(self, request, assessment_slug, threshold_id=None):
lookup['academy__id'] = int(param)
else:
lookup['academy__slug'] = param
else:
lookup['academy__isnull'] = True

if 'tag' in self.request.GET:
param = self.request.GET.get('tags')
lookup['tags__icontains'] = param

if param != 'all':
lookup['tags__icontains'] = param
else:
lookup['academy__isnull'] = True
lookup['tags__in'] = ['', None]

items = items.filter(**lookup).order_by('-created_at')

Expand Down
6 changes: 3 additions & 3 deletions breathecode/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ def __exit__(self, *args, **kwargs):
data[i] = []

if len(data[i]) >= 2:
data[i].sort(key=lambda x: x['created_at'])
data[i].sort(key=lambda x: x['created_at'].replace(tzinfo=UTC))

if datetime.now(UTC) - data[i][-1]['created_at'] < delta:
if datetime.now(UTC) - data[i][-1]['created_at'].replace(tzinfo=UTC) < delta:
available[i] = False
data[i] = data[i][-2:]
else:
available[i] = True
data[i] = data[i][-1:]

elif len(data[i]) == 1:
if datetime.now(UTC) - data[i][0]['created_at'] < delta:
if datetime.now(UTC) - data[i][0]['created_at'].replace(tzinfo=UTC) < delta:
available[i] = False
else:
available[i] = True
Expand Down
195 changes: 96 additions & 99 deletions breathecode/mentorship/fixtures/dev_data.json
Original file line number Diff line number Diff line change
@@ -1,102 +1,99 @@
[
{
"model": "mentorship.mentorshipservice",
"pk": 1,
"fields": {
"slug": "geekpal",
"name": "GeekPal 1-1 Coding Mentorship",
"logo_url": null,
"description": "1-1 Mentoring technical session using the GeekPal service.",
"duration": "01:00:00",
"max_duration": "02:00:00",
"missed_meeting_duration": "00:10:00",
"status": "ACTIVE",
"language": "en",
"allow_mentee_to_extend": true,
"allow_mentors_to_extend": true,
"academy": 1,
"created_at": "2022-10-13T14:20:47.106Z",
"updated_at": "2022-10-13T14:20:47.106Z"
}
},
{
"model": "mentorship.mentorprofile",
"pk": 1,
"fields": {
"name": null,
"slug": "Joe",
"price_per_hour": 8.0,
"one_line_bio": "",
"bio": "",
"academy": 1,
"timezone": "America/New_York",
"online_meeting_url": "https://whereby.com/joedoe",
"token": "cad0c7787bfb147994590b449a2edb19720fbfb4",
"booking_url": "https://calendly.com/joedoe/4geeks",
"status": "ACTIVE",
"email": "[email protected]",
"user": 7,
"created_at": "2022-10-13T14:22:18.656Z",
"updated_at": "2022-10-13T14:22:18.656Z",
"rating": null,
"services": [
1
],
"syllabus": [
1
]
}
},
{
"model": "mentorship.mentorshipbill",
"pk": 1,
"fields": {
"status": "DUE",
"status_mesage": "",
"total_duration_in_minutes": 0.0,
"total_duration_in_hours": 0.0,
"total_price": 0.0,
"overtime_minutes": 0.0,
"academy": 1,
"started_at": "2022-10-13T14:24:11Z",
"ended_at": "2022-10-18T14:24:13Z",
"reviewer": 1,
"mentor": 1,
"paid_at": null,
"created_at": "2022-10-13T14:24:20.900Z",
"updated_at": "2022-10-13T14:24:20.900Z"
}
},
{
"model": "mentorship.mentorshipsession",
"pk": 1,
"fields": {
"name": "kBxxBTTrgapJjZeB21B3",
"is_online": true,
"latitude": null,
"longitude": null,
"mentor": 1,
"service": 1,
"mentee": 8,
"online_meeting_url": "https://4geeks.daily.co/kBxxBTTrgapJjZeB21B3",
"online_recording_url": null,
"status": "COMPLETED",
"status_message": "",
"allow_billing": true,
"bill": null,
"suggested_accounted_duration": null,
"accounted_duration": null,
"agenda": "",
"summary": "It was a great meeting where I helped Mary with all her questions about javascript",
"starts_at": "2022-10-13T14:23:27Z",
"ends_at": "2022-10-13T15:23:28Z",
"started_at": "2022-10-13T14:23:32Z",
"ended_at": "2022-10-13T15:23:34Z",
"mentor_joined_at": "2022-10-13T14:23:38Z",
"mentor_left_at": "2022-10-13T15:23:40Z",
"mentee_left_at": "2022-10-13T15:23:43Z",
"created_at": "2022-10-13T14:23:45.719Z",
"updated_at": "2022-10-13T14:23:45.719Z"
}
{
"model": "mentorship.mentorshipservice",
"pk": 1,
"fields": {
"slug": "geekpal",
"name": "GeekPal 1-1 Coding Mentorship",
"logo_url": null,
"description": "1-1 Mentoring technical session using the GeekPal service.",
"duration": "01:00:00",
"max_duration": "02:00:00",
"missed_meeting_duration": "00:10:00",
"video_provider": "DAILY",
"status": "ACTIVE",
"language": "en",
"allow_mentee_to_extend": true,
"allow_mentors_to_extend": true,
"academy": 1,
"created_at": "2022-10-13T14:20:47.106Z",
"updated_at": "2022-10-13T14:20:47.106Z"
}
},
{
"model": "mentorship.mentorprofile",
"pk": 1,
"fields": {
"name": null,
"slug": "Joe",
"price_per_hour": 8.0,
"one_line_bio": "",
"bio": "",
"academy": 1,
"timezone": "America/New_York",
"online_meeting_url": "https://whereby.com/joedoe",
"token": "cad0c7787bfb147994590b449a2edb19720fbfb4",
"booking_url": "https://calendly.com/joedoe/4geeks",
"status": "ACTIVE",
"email": "[email protected]",
"user": 7,
"created_at": "2022-10-13T14:22:18.656Z",
"updated_at": "2022-10-13T14:22:18.656Z",
"rating": null,
"services": [1],
"syllabus": [1]
}
},
{
"model": "mentorship.mentorshipbill",
"pk": 1,
"fields": {
"status": "DUE",
"status_mesage": "",
"total_duration_in_minutes": 0.0,
"total_duration_in_hours": 0.0,
"total_price": 0.0,
"overtime_minutes": 0.0,
"academy": 1,
"started_at": "2022-10-13T14:24:11Z",
"ended_at": "2022-10-18T14:24:13Z",
"reviewer": 1,
"mentor": 1,
"paid_at": null,
"created_at": "2022-10-13T14:24:20.900Z",
"updated_at": "2022-10-13T14:24:20.900Z"
}
},
{
"model": "mentorship.mentorshipsession",
"pk": 1,
"fields": {
"name": "kBxxBTTrgapJjZeB21B3",
"is_online": true,
"latitude": null,
"longitude": null,
"mentor": 1,
"service": 1,
"mentee": 8,
"online_meeting_url": "https://4geeks.daily.co/kBxxBTTrgapJjZeB21B3",
"online_recording_url": null,
"status": "COMPLETED",
"status_message": "",
"allow_billing": true,
"bill": null,
"suggested_accounted_duration": null,
"accounted_duration": null,
"agenda": "",
"summary": "It was a great meeting where I helped Mary with all her questions about javascript",
"starts_at": "2022-10-13T14:23:27Z",
"ends_at": "2022-10-13T15:23:28Z",
"started_at": "2022-10-13T14:23:32Z",
"ended_at": "2022-10-13T15:23:34Z",
"mentor_joined_at": "2022-10-13T14:23:38Z",
"mentor_left_at": "2022-10-13T15:23:40Z",
"mentee_left_at": "2022-10-13T15:23:43Z",
"created_at": "2022-10-13T14:23:45.719Z",
"updated_at": "2022-10-13T14:23:45.719Z"
}
}
]
9 changes: 9 additions & 0 deletions breathecode/payments/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
ServiceTranslation,
Subscription,
SubscriptionServiceItem,
PaymentMethod,
)

# Register your models here.
Expand Down Expand Up @@ -370,3 +371,11 @@ class CouponAdmin(admin.ModelAdmin):
'seller__user__last_name'
]
raw_id_fields = ['seller']


@admin.register(PaymentMethod)
class PaymentMethodAdmin(admin.ModelAdmin):
list_display = ('title', 'description', 'academy', 'third_party_link', 'lang')
list_filter = ['academy__name', 'lang']
raw_id_fields = ['academy']
search_fields = ['title', 'academy__name']
37 changes: 37 additions & 0 deletions breathecode/payments/migrations/0047_paymentmethod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 5.0.6 on 2024-06-25 16:38

import breathecode.utils.validators.language
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('admissions', '0064_academy_legal_name'),
('payments', '0046_consumptionsession_operation_code_and_more'),
]

operations = [
migrations.CreateModel(
name='PaymentMethod',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=120)),
('description', models.CharField(help_text='Description of the payment method', max_length=255)),
('third_party_link',
models.URLField(blank=True, default=None, help_text='Link of a third party payment method',
null=True)),
('lang',
models.CharField(help_text='ISO 639-1 language code + ISO 3166-1 alpha-2 country code, e.g. en-US',
max_length=5,
validators=[breathecode.utils.validators.language.validate_language_code])),
('academy',
models.ForeignKey(blank=True,
help_text='Academy owner',
null=True,
on_delete=django.db.models.deletion.CASCADE,
to='admissions.academy')),
],
),
]
16 changes: 16 additions & 0 deletions breathecode/payments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,3 +1648,19 @@ def get_reputation(self):

def __str__(self) -> str:
return f'{self.user.email} -> {self.get_reputation()}'


class PaymentMethod(models.Model):
"""
Different payment methods of each academy have.
"""
academy = models.ForeignKey(Academy, on_delete=models.CASCADE, blank=True, null=True, help_text='Academy owner')
title = models.CharField(max_length=120, null=False, blank=False)
description = models.CharField(max_length=255, help_text='Description of the payment method')
third_party_link = models.URLField(blank=True,
null=True,
default=None,
help_text='Link of a third party payment method')
lang = models.CharField(max_length=5,
validators=[validate_language_code],
help_text='ISO 639-1 language code + ISO 3166-1 alpha-2 country code, e.g. en-US')
11 changes: 11 additions & 0 deletions breathecode/payments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ class GetSubscriptionHookSerializer(GetAbstractIOweYouSerializer):
pay_every = serpy.Field()
pay_every_unit = serpy.Field()


class GetSubscriptionSerializer(GetAbstractIOweYouSerializer):
paid_at = serpy.Field()
is_refundable = serpy.Field()
Expand All @@ -402,6 +403,7 @@ class GetSubscriptionSerializer(GetAbstractIOweYouSerializer):
def get_service_items(self, obj):
return GetServiceItemSerializer(obj.service_items.filter(), many=True).data


class GetBagSerializer(serpy.Serializer):
id = serpy.Field()
service_items = serpy.MethodField()
Expand Down Expand Up @@ -489,3 +491,12 @@ def update(self, instance, validated_data):

instance.save()
return instance


class GetPaymentMethod(serpy.Serializer):
id = serpy.Field()
title = serpy.Field()
lang = serpy.Field()
description = serpy.Field()
third_party_link = serpy.Field()
academy = GetAcademySmallSerializer(required=False, many=False)
Loading

0 comments on commit fd31ddd

Please sign in to comment.