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/manual-billing
  • Loading branch information
jefer94 committed Aug 20, 2024
2 parents c5a1c34 + 797458c commit dbf3444
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 53 deletions.
6 changes: 4 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ ports:
tasks:
- command: redis-server
- init: |
python -m scripts.install
pyenv global 3.12.2 &&
python -m scripts.install &&
gp sync-done deps
command: pipenv run celery
command: pyenv global 3.12.2 && pipenv run celery
- init: gp sync-await deps
command: >
pyenv global 3.12.2 &&
(psql -U gitpod -c 'CREATE DATABASE breathecode;' || true) &&
(psql -U gitpod -c 'CREATE EXTENSION unaccent;' -d breathecode || true) &&
pipenv run migrate &&
Expand Down
19 changes: 2 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,8 @@
</a>

<a href="https://github.com/breatheco-de/apiv2/actions/workflows/dockerhub.yml">
<img src="https://github.com/breatheco-de/apiv2/actions/workflows/dockerhub.yml/badge.svg"
alt="Docker Hub">
</a>

<a href="https://github.com/breatheco-de/apiv2/actions/workflows/linter.yml">
<img src="https://github.com/breatheco-de/apiv2/actions/workflows/linter.yml/badge.svg"
alt="Linter">
</a>

<a href="https://github.com/breatheco-de/apiv2/actions/workflows/test.yml">
<img src="https://github.com/breatheco-de/apiv2/actions/workflows/test.yml/badge.svg"
alt="Test">
</a>

<a href="https://github.com/breatheco-de/apiv2/actions/workflows/github-pages.yml">
<img src="https://github.com/breatheco-de/apiv2/actions/workflows/github-pages.yml/badge.svg"
alt="Test">
<img src="https://github.com/breatheco-de/apiv2/actions/workflows/checks.yml/badge.svg"
alt="Checks">
</a>
</p>

Expand Down
11 changes: 6 additions & 5 deletions breathecode/admissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.contrib.auth.models import AnonymousUser, User
from django.db.models import FloatField, Max, Q, Value
from django.utils import timezone
from slugify import slugify
from rest_framework import status
from rest_framework.decorators import permission_classes
from rest_framework.exceptions import ParseError, PermissionDenied, ValidationError
Expand Down Expand Up @@ -188,7 +189,7 @@ def get_public_syllabus(request, id=None):

like = request.GET.get("like", None)
if like is not None:
items = items.filter(Q(name__icontains=like) | Q(slug__icontains=like))
items = items.filter(Q(name__icontains=like) | Q(slug__icontains=slugify(like)))

serializer = GetSyllabusSmallSerializer(items, many=True)
return Response(serializer.data)
Expand Down Expand Up @@ -271,7 +272,7 @@ def get(self, request, id=None):

syllabus_slug_like = request.GET.get("syllabus_slug_like", "")
if syllabus_slug_like:
items = items.filter(syllabus_version__syllabus__slug__icontains=syllabus_slug_like)
items = items.filter(syllabus_version__syllabus__slug__icontains=slugify(syllabus_slug_like))

plan = request.GET.get("plan", "")
if plan == "true":
Expand Down Expand Up @@ -1144,7 +1145,7 @@ def get(self, request, cohort_id=None, academy_id=None):

like = request.GET.get("like", None)
if like is not None:
items = items.filter(Q(name__icontains=like) | Q(slug__icontains=like))
items = items.filter(Q(name__icontains=like) | Q(slug__icontains=slugify(like)))

items = handler.queryset(items)
serializer = GetCohortSerializer(items, many=True)
Expand Down Expand Up @@ -1202,7 +1203,7 @@ def get(self, request, cohort_id=None, academy_id=None):

like = request.GET.get("like", None)
if like is not None:
items = items.filter(Q(name__icontains=like) | Q(slug__icontains=like))
items = items.filter(Q(name__icontains=like) | Q(slug__icontains=slugify(like)))

items = handler.queryset(items)
serializer = GetCohortSerializer(items, many=True)
Expand Down Expand Up @@ -1514,7 +1515,7 @@ def get(self, request, syllabus_id=None, syllabus_slug=None, academy_id=None):

like = request.GET.get("like", None)
if like is not None:
items = items.filter(Q(name__icontains=like) | Q(slug__icontains=like))
items = items.filter(Q(name__icontains=like) | Q(slug__icontains=slugify(like)))

items = handler.queryset(items)
serializer = GetSyllabusSerializer(items, many=True)
Expand Down
5 changes: 2 additions & 3 deletions breathecode/assignments/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hashlib
import logging
import os

from slugify import slugify
from adrf.views import APIView
from asgiref.sync import sync_to_async
from circuitbreaker import CircuitBreakerError
Expand All @@ -15,7 +15,6 @@
from rest_framework.decorators import api_view
from rest_framework.exceptions import PermissionDenied
from rest_framework.response import Response
from slugify import slugify

import breathecode.activity.tasks as tasks_activity
import breathecode.assignments.tasks as tasks
Expand Down Expand Up @@ -474,7 +473,7 @@ def get(self, request, cohort_id, academy_id):

like = request.GET.get("like", None)
if like is not None and like != "undefined" and like != "":
items = items.filter(Q(associated_slug__icontains=like) | Q(title__icontains=like))
items = items.filter(Q(associated_slug__icontains=slugify(like)) | Q(title__icontains=like))

# tasks from users that belong to these cohort
student = request.GET.get("student", None)
Expand Down
59 changes: 59 additions & 0 deletions breathecode/events/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,29 @@ def get_related_resources():

def process_i_owe_you(i_owe_them: QuerySet[AbstractIOweYou]):
for i_owe_you in i_owe_them:
print("get in", i_owe_you)
if (
i_owe_you.selected_cohort_set
and i_owe_you.selected_cohort_set.cohorts.first().academy
and i_owe_you.selected_cohort_set.cohorts.first().academy not in academies
):
print(4, i_owe_you.selected_cohort_set.cohorts.first().academy)
academies.append(i_owe_you.selected_cohort_set.cohorts.first().academy)

if i_owe_you.selected_cohort_set and i_owe_you.selected_cohort_set.cohorts.first() not in cohorts:
print(5, i_owe_you.selected_cohort_set.cohorts.first())
cohorts.append(i_owe_you.selected_cohort_set.cohorts.first())

if (
i_owe_you.selected_cohort_set
and i_owe_you.selected_cohort_set.cohorts.first().syllabus_version
and i_owe_you.selected_cohort_set.cohorts.first().syllabus_version.syllabus not in syllabus
):
print(
6,
i_owe_you.selected_cohort_set.cohorts.first().syllabus_version.syllabus,
i_owe_you.selected_cohort_set.cohorts.first().academy,
)
syllabus.append(
{
"syllabus": i_owe_you.selected_cohort_set.cohorts.first().syllabus_version.syllabus,
Expand All @@ -71,17 +79,20 @@ def process_i_owe_you(i_owe_them: QuerySet[AbstractIOweYou]):
)

if i_owe_you.selected_event_type_set and i_owe_you.selected_event_type_set.academy not in academies:
print(7, i_owe_you.selected_event_type_set.academy)
academies.append(i_owe_you.selected_event_type_set.academy)

if (
i_owe_you.selected_mentorship_service_set
and i_owe_you.selected_mentorship_service_set.academy not in academies
):
print(8, i_owe_you.selected_mentorship_service_set.academy)
academies.append(i_owe_you.selected_mentorship_service_set.academy)

if i_owe_you.selected_event_type_set:
for event_type in i_owe_you.selected_event_type_set.event_types.all():
if event_type.id not in ids:
print(9, event_type.id)
ids.append(event_type.id)

syllabus = []
Expand Down Expand Up @@ -110,6 +121,7 @@ def process_i_owe_you(i_owe_them: QuerySet[AbstractIOweYou]):

for cohort_user in cohort_users_with_syllabus:
if cohort_user.cohort.syllabus_version.syllabus not in cohorts:
print(1, cohort_user.cohort.syllabus_version.syllabus, cohort_user.cohort.academy)
syllabus.append(
{
"syllabus": cohort_user.cohort.syllabus_version.syllabus,
Expand All @@ -119,15 +131,62 @@ def process_i_owe_you(i_owe_them: QuerySet[AbstractIOweYou]):

for cohort_user in cohort_users:
if cohort_user.cohort.academy not in cohorts:
print(2, cohort_user.cohort.academy)
academies.append(cohort_user.cohort.academy)

for cohort_user in cohort_users:
if cohort_user.cohort not in cohorts:
print(3, cohort_user.cohort)
cohorts.append(cohort_user.cohort)

process_i_owe_you(subscriptions)
process_i_owe_you(plan_financings)

print(
-11,
[
{
"id": x.id,
"slug": x.slug,
"name": x.name,
}
for x in academies
],
)

print(
-22,
[
{
"id": x.id,
"slug": x.slug,
"name": x.name,
}
for x in cohorts
],
)

print(
-33,
[
{
"syllabus": {
"id": x["syllabus"].id,
"slug": x["syllabus"].slug,
"name": x["syllabus"].name,
},
"academy": {
"id": x["academy"].id,
"slug": x["academy"].slug,
"name": x["academy"].name,
},
}
for x in syllabus
],
)
print(-44, subscriptions)
print(-55, plan_financings)

return academies, cohorts, syllabus, ids

def my_events():
Expand Down
10 changes: 5 additions & 5 deletions breathecode/marketing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import re
from datetime import timedelta
from urllib import parse

from slugify import slugify
import pandas as pd
import pytz
from circuitbreaker import CircuitBreakerError
Expand Down Expand Up @@ -486,7 +486,7 @@ def get(self, request, format=None, academy_id=None):

like = request.GET.get("like", None)
if like is not None:
items = items.filter(slug__icontains=like)
items = items.filter(slug__icontains=slugify(like))

status = request.GET.get("status", None)
if status is not None:
Expand Down Expand Up @@ -550,7 +550,7 @@ def get(self, request, format=None, academy_id=None):

like = request.GET.get("like", None)
if like is not None:
items = items.filter(Q(slug__icontains=like) | Q(name__icontains=like))
items = items.filter(Q(slug__icontains=slugify(like)) | Q(name__icontains=like))

status = request.GET.get("status", None)
if status is not None:
Expand Down Expand Up @@ -635,7 +635,7 @@ def get(self, request, format=None, academy_id=None):

like = request.GET.get("like", None)
if like is not None:
utms = utms.filter(slug__icontains=like)
utms = utms.filter(slug__icontains=slugify(like))

types = request.GET.get("type", None)
if types is not None:
Expand Down Expand Up @@ -969,7 +969,7 @@ def get(self, request, slug=None, academy_id=None):

like = request.GET.get("like", None)
if like is not None:
items = items.filter(slug__icontains=like)
items = items.filter(slug__icontains=slugify(like))

page = self.paginate_queryset(items, request)
serializer = ShortlinkSmallSerializer(page, many=True)
Expand Down
2 changes: 1 addition & 1 deletion breathecode/media/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get(self, request, academy_id=None):

like = request.GET.get("like")
if like:
items = items.filter(Q(name__icontains=like) | Q(slug__icontains=like))
items = items.filter(Q(name__icontains=like) | Q(slug__icontains=slugify(like)))

items = handler.queryset(items)
serializer = GetMediaSerializer(items, many=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ def test_with_mentor_profile__academy_available_as_saas__flag_eq_true__mentee_wi
template_data["URL_BACK"] = "https://4geeks.com/choose-program"
template_data["BUTTON"] = "Get more consumables"
template_data["LINK"] = (
f"https://4geeks.com/checkout?mentorship_service_set={base.mentorship_service_set.slug}&token={base.token.key}"
f"https://4geeks.com/checkout/mentorship/{base.mentorship_service_set.slug}?token={base.token.key}"
)
expected = render("with-consumer-not-enough-consumables", data=template_data, academy=None)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.7 on 2024-07-22 16:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("payments", "0051_service_consumer"),
]

operations = [
migrations.AlterField(
model_name="paymentmethod",
name="description",
field=models.CharField(help_text="Description of the payment method", max_length=480),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ <h5>
{{ consumption.kind.product_name }} ({{ consumption.kind.sku }})
{% if consumption.status_text %}
<small> - </small>
<a onclick="alert('{{consumption.status_text}}')" type="button" class="btn-link">
<a onclick="alert(`{{consumption.status_text}}`)" type="button" class="btn-link">
show errors
</a>
{% endif %}
Expand Down
14 changes: 13 additions & 1 deletion breathecode/registry/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging

import re
import requests
from bs4 import BeautifulSoup

Expand All @@ -9,6 +9,18 @@
logger = logging.getLogger(__name__)


def is_url(value):
url_pattern = re.compile(
r"^(https?://)?" # optional http or https scheme
r"(([A-Za-z0-9-]+\.)+[A-Za-z]{2,})" # domain name
r"(:\d+)?" # optional port
r"(\/[-A-Za-z0-9@:%._\+~#=]*)*" # path
r"(\?[;&A-Za-z0-9%_.~+=-]*)?" # query string
r"(#[-A-Za-z0-9_]*)?$" # fragment locator
)
return re.match(url_pattern, value) is not None


def get_urls_from_html(html_content):
soup = BeautifulSoup(html_content, features="lxml")
urls = []
Expand Down
Loading

0 comments on commit dbf3444

Please sign in to comment.