This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import generics, status | |
from rest_framework.response import Response | |
from rack.models import RackItem | |
from rack.serializers import RackItemSerializer, NewRackItemSerializer | |
class ListCreateRackItem(generics.ListCreateAPIView): | |
model = RackItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import random | |
import re | |
""" | |
Helps us find the number in between two brackets ie (33) | |
""" | |
def find_between(text, start, end): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import random | |
import re | |
""" | |
Helps us find the number in between two brackets ie (33) | |
""" | |
def find_between(text, start, end): | |
return re.findall(re.escape(start) + "(.*)" + re.escape(end), text)[0].strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class School: | |
def __init__(self, name, location): | |
self.name = name | |
self.location = location | |
class Student: | |
def __init__(self, name, age, school): | |
self.name = name | |
self.age = age |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass, asdict | |
from typing import List | |
from ms_foobar_app.utils.utilities import snake_case_dict_to_camel | |
@dataclass | |
class SmsMessage: | |
phone_numbers: List[str] | |
message: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import BaseCommand | |
from ms_foobar_app.events.event_listener import EventListener | |
class Command(BaseCommand): | |
def handle(self, *args, **options): | |
bus = EventListener() | |
bus.run() | |
bus.subscribe() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ms_foobar_app.events.event_bus_root import EventBus | |
class EventPublisher(EventBus): | |
def __init__(self): | |
super(EventPublisher, self).__init__() | |
def publish(self, subject, data): | |
self.loop.run_until_complete(self.__publish(subject, data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import random | |
from nats.aio.client import Client as NATS | |
from stan.aio.client import Client as STAN | |
import asyncio | |
class EventBus: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import traceback | |
from asgiref.sync import sync_to_async | |
from ms_foobar_app.constants import EventSubjects, QueueGroupName | |
from ms_foobar_app.events.event_bus_root import EventBus | |
from ms_foobar_app.models import User | |
from ms_foobar_app.serializers import UserSerializer | |
from ms_foobar_app.utils.utilities import snake_case_dict_to_camel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.deprecation import MiddlewareMixin | |
# NOTE: This is not best practise, however, api requests from some browser would fail continuous so explains the use | |
# of this. Enhance this CSRF solution if necessary | |
class DisableCsrfCheck(MiddlewareMixin): | |
def process_request(self, req): | |
attr = '_dont_enforce_csrf_checks' | |
if not getattr(req, attr, False): | |
setattr(req, attr, True) |
NewerOlder