Skip to content

Commit

Permalink
Merge pull request #1116 from breatheco-de/main
Browse files Browse the repository at this point in the history
sync back to dev
  • Loading branch information
alesanchezr authored Oct 10, 2023
2 parents 577e771 + c064502 commit 79c7a9f
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 9 deletions.
3 changes: 2 additions & 1 deletion breathecode/assignments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ def validate(self, data):
return data

def update(self, instance, validated_data):
if 'opened_at' in validated_data and validated_data['opened_at'] > instance.opened_at:
if 'opened_at' in validated_data and (instance.opened_at is None
or validated_data['opened_at'] > instance.opened_at):
tasks_activity.add_activity.delay(self.context['request'].user.id,
'read_assignment',
related_type='assignments.Task',
Expand Down
12 changes: 7 additions & 5 deletions breathecode/assignments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,14 @@ def post(self, request, user_id=None):
},
many=True)
if serializer.is_valid():
serializer.save()
tasks = serializer.save()
# tasks.teacher_task_notification.delay(serializer.data['id'])
tasks_activity.add_activity.delay(request.user.id,
'open_syllabus_module',
related_type='assignments.Task',
related_id=serializer.id)
for t in tasks:
tasks_activity.add_activity.delay(request.user.id,
'open_syllabus_module',
related_type='assignments.Task',
related_id=t.id)

return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Expand Down
4 changes: 2 additions & 2 deletions breathecode/events/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class EventTypeAdmin(admin.ModelAdmin):
# Register your models here.
@admin.register(EventCheckin)
class EventCheckinAdmin(admin.ModelAdmin):
list_display = ('id', 'email', 'attendee', 'event', 'status', 'created_at', 'attended_at')
list_filter = ['status']
list_display = ('id', 'email', 'attendee', 'event', 'status', 'created_at', 'attended_at', 'utm_source')
list_filter = ['status', 'utm_source', 'utm_medium']
search_fields = ['email', 'event__title', 'event__slug']
raw_id_fields = ['event', 'attendee']

Expand Down
33 changes: 33 additions & 0 deletions breathecode/events/migrations/0055_auto_20231009_2240.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2.21 on 2023-10-09 22:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('events', '0054_alter_event_uuid'),
]

operations = [
migrations.AddField(
model_name='eventcheckin',
name='utm_campaign',
field=models.CharField(blank=True, default=None, max_length=70, null=True),
),
migrations.AddField(
model_name='eventcheckin',
name='utm_medium',
field=models.CharField(blank=True, default=None, max_length=70, null=True),
),
migrations.AddField(
model_name='eventcheckin',
name='utm_source',
field=models.CharField(blank=True, default=None, max_length=70, null=True),
),
migrations.AddField(
model_name='eventcheckin',
name='utm_url',
field=models.CharField(blank=True, default=None, max_length=2000, null=True),
),
]
5 changes: 5 additions & 0 deletions breathecode/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ def __init__(self, *args, **kwargs):
event = models.ForeignKey(Event, on_delete=models.CASCADE)
status = models.CharField(max_length=9, choices=CHECKIN_STATUS, default=PENDING)

utm_medium = models.CharField(max_length=70, blank=True, null=True, default=None)
utm_campaign = models.CharField(max_length=70, blank=True, null=True, default=None)
utm_source = models.CharField(max_length=70, blank=True, null=True, default=None)
utm_url = models.CharField(max_length=2000, null=True, default=None, blank=True)

created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False)
attended_at = models.DateTimeField(null=True, default=None, blank=True)
Expand Down
6 changes: 5 additions & 1 deletion breathecode/events/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ class EventHookCheckinSerializer(serpy.Serializer):
id = serpy.Field()
email = serpy.Field()
status = serpy.Field()
utm_url = serpy.Field()
utm_source = serpy.Field()
utm_campaign = serpy.Field()
utm_medium = serpy.Field()
created_at = serpy.Field()
attended_at = serpy.Field()
attendee = UserSerializer(required=False)
Expand Down Expand Up @@ -614,7 +618,7 @@ def validate(self, data):
def create(self, validated_data):
event_checkin = super().create(validated_data)

tasks_activity.add_activity.delay(event_checkin.attendee,
tasks_activity.add_activity.delay(event_checkin.attendee.id,
'event_checkin_created',
related_type='events.EventCheckin',
related_id=event_checkin.id)
Expand Down
20 changes: 20 additions & 0 deletions breathecode/events/tests/urls/tests_eventbrite_webhook_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ def test_eventbrite_webhook_without_active_campaign_academy(self):
'email': '[email protected]',
'event_id': 1,
'id': 1,
'utm_campaign': None,
'utm_medium': None,
'utm_source': None,
'utm_url': None,
'status': 'PENDING',
'attended_at': None
}])
Expand Down Expand Up @@ -263,6 +267,10 @@ def test_eventbrite_webhook_without_automation(self):
self.assertEqual(self.all_event_checkin_dict(), [{
'attendee_id': None,
'email': '[email protected]',
'utm_campaign': None,
'utm_medium': None,
'utm_source': None,
'utm_url': None,
'event_id': 1,
'id': 1,
'status': 'PENDING',
Expand Down Expand Up @@ -321,6 +329,10 @@ def test_eventbrite_webhook_without_lang(self):

self.assertEqual(self.all_event_checkin_dict(), [{
'attendee_id': 1,
'utm_campaign': None,
'utm_medium': None,
'utm_source': None,
'utm_url': None,
'email': '[email protected]',
'event_id': 1,
'id': 1,
Expand Down Expand Up @@ -417,6 +429,10 @@ def test_eventbrite_webhook_without_lang__active_campaign_belong_to_other_academ

self.assertEqual(self.all_event_checkin_dict(), [{
'attendee_id': 1,
'utm_campaign': None,
'utm_medium': None,
'utm_source': None,
'utm_url': None,
'email': '[email protected]',
'event_id': 1,
'id': 1,
Expand Down Expand Up @@ -514,6 +530,10 @@ def test_eventbrite_webhook(self):

self.assertEqual(self.all_event_checkin_dict(), [{
'attendee_id': 1,
'utm_campaign': None,
'utm_medium': None,
'utm_source': None,
'utm_url': None,
'email': '[email protected]',
'event_id': 1,
'id': 1,
Expand Down
4 changes: 4 additions & 0 deletions breathecode/events/tests/urls/tests_me_event_id_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def event_checkin_serializer(id, event, user):
return {
'attended_at': UTC_NOW,
'attendee_id': user.id,
'utm_campaign': None,
'utm_medium': None,
'utm_source': None,
'utm_url': None,
'email': user.email,
'event_id': event.id,
'id': id,
Expand Down
1 change: 1 addition & 0 deletions breathecode/services/eventbrite/actions/order_placed.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def order_placed(self, webhook, payload: dict):
elif not EventCheckin.objects.filter(email=email, event=local_event, attendee=local_attendee).count():
event_checkin = EventCheckin.objects.filter(email=email, event=local_event).first()
event_checkin.attendee = local_attendee
event_checkin.utm_source = 'eventbrite'
event_checkin.save()

contact = {
Expand Down

0 comments on commit 79c7a9f

Please sign in to comment.