This file contains hidden or 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 json | |
from datetime import datetime, timedelta | |
# Function to generate sensor data | |
def generate_sensor_data(num_rows: int): | |
sensor_data = [] | |
base_time = datetime(2024, 7, 1, 0, 0) | |
for i in range(num_rows): |
This file contains hidden or 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
# mylibrary/library.py | |
class Library: | |
def subscribe(self, topic): | |
# checks to see if already subscribed | |
if topic in self.topics: | |
raise AssertionError("Topic is already subscribed too") | |
def wrapper(handler): |
This file contains hidden or 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.contrib.auth.decorators import user_passes_test | |
from django.core.exceptions import PermissionDenied | |
def restrict_access_to_groups(groups: list, raise_exception: bool = False): | |
""" | |
Decorator for views that requires the user to be part of a group, | |
if they are not the user is not allowed into the page. | |
If the raise_exception parameter is given the PermissionDenied exception | |
is raised returning a 403 status code |
This file contains hidden or 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 functools import wraps | |
def login_not_required(view_func): | |
def wrapped(*args, **kwargs): | |
return view_func(*args, **kwargs) | |
wrapped.login_required = False | |
return wraps(view_func)(wrapped) |
This file contains hidden or 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.http import HttpResponseRedirect | |
from django.conf import settings | |
class LoginRequiredMiddleware: | |
def __init__(self, get_response): | |
self.get_response = get_response | |
def __call__(self, request): |
This file contains hidden or 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.conf import settings | |
from django.http import HttpResponseRedirect | |
class AnglerFish: | |
def __init__(self, get_response): | |
self.get_response = get_response | |
def __call__(self, request): | |
if any(url in request.path for url in settings.ANGLER_LIGHTS): |
This file contains hidden or 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
const toml = require("toml"); | |
const fs = require("fs"); | |
const path = require("path"); | |
const inDirectory = path.join(__dirname, "..", "content", "posts"); | |
const outDirectory = path.join(__dirname, "..", "static", "assets", "js"); | |
class Index { | |
filePathQueue = []; | |
indexes = []; |
This file contains hidden or 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 .utils import CustomerTypes | |
class CustomerView(DetailView): | |
... | |
def get_context_data(self, **kwargs): | |
... | |
if self.get_object().type == CustomerTypes.PROSPECT: | |
context["ad"] = Ad.objects.get(target=CustomerTypes.PROSPECT) | |
... | |
This file contains hidden or 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 enum import IntEnum | |
class CustomerTypes(IntEnum): | |
PROSPECT = 1 | |
LEAD = 2 | |
CUSTOMER = 3 | |
@classmethod | |
def choices(cls): | |
return [(key.value, key.name) for key in cls] |
This file contains hidden or 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 .utils import CustomerTypes | |
class Customer(models.Model): | |
... | |
type = models.IntegerField(choices=CustomerTypes.choices(), default=CustomerTypes.PROSPECT) | |
... | |
def get_customer_type_label(self): | |
return CustomerTypes(self.type).name.title() |
NewerOlder