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 decimal import Decimal | |
import re | |
REGEX = r'^\d\d:\d\d:\d\d \d+ of \d+ (OK|PASS) (.*) \.*\s+\[(PASS|SUCCESS \d+) in (\d+\.\d+)s\]$' | |
def parse_file(file_path: str) -> list[tuple[str, str, Decimal]]: | |
with open(file_path) as f: | |
lines = f.readlines() |
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
commit 5198e31796e2b191a51459441b773fe77b7795fb | |
Author: Pablo Recio <[email protected]> | |
Date: Mon Mar 21 22:01:42 2016 +0000 | |
Class-based views are back to stay | |
diff --git a/pubnamegenerator/urls.py b/pubnamegenerator/urls.py | |
index 92656ee..8525b59 100644 | |
--- a/pubnamegenerator/urls.py | |
+++ b/pubnamegenerator/urls.py |
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.test import RequestFactory, TestCase | |
from myapp.middleware import MyMiddleware | |
class MyMiddlewareTestCase(TestCase): | |
def setUp(self): | |
super(MyMiddlewareTestCase, self).setUp() | |
self.factory = RequestFactory() |
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
if(jQuery) (function($) { | |
$.extend($.fn, { | |
fixContrast: function() { | |
$(this).each(function(element){ | |
var backgroundcolor = $(this).css('background-color'); | |
var rgb = backgroundcolor.replace("rgb(", "").replace(")", "").split(", "); | |
var ratio = Math.round(( | |
(parseInt(rgb[0]) * 299) + | |
(parseInt(rgb[1]) * 587) + |
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 AJAXResponseMixin(object): | |
def get(self, request, *args, **kwargs): | |
response = super(AJAXResponseMixin, self).get(request, *args, **kwargs) | |
if self.request.is_ajax(): | |
return HttpResponse(json.dumps({ | |
'response': response.status_code, | |
'location': response['Location'], | |
# whatever else you want to return | |
}), mimetype='application/json') |
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.db.models.signals import post_save | |
from django.dispatch import receiver | |
# models definition here ... | |
@receiver(post_save, sender=MyModel) | |
def handler_that_saves_a_mymodel_instance(sender, instance, created, **kwargs): | |
# without this check the save() below causes infinite post_save signals | |
if created: | |
instance.some_field = complex_calculation() |