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 serializers | |
from django.contrib.auth import password_validation | |
class PasswordField(serializers.CharField): | |
def __init__(self, *args, **kwargs): | |
kwargs['write_only'] = True | |
kwargs['style'] = {'input_type': 'password'} | |
self.validate_password = kwargs.pop('validate_password', True) |
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
function processServerError(error, fields) { | |
const fieldErrors = {}; | |
let otherErrors = []; | |
if (typeof error === 'object') { | |
for (const field of fields) { | |
const value = error[field]; | |
if (value) { | |
if (value.constructor === {}.constructor) { | |
Object.keys(value).forEach(key => { | |
fieldErrors[`${field}.${key}`] = value[key]; |
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.request import Request | |
class RequestMaybeInitializedMixin(object): | |
def initialize_request(self, request, *args, **kwargs): | |
drf_request = super( | |
RequestMaybeInitializedMixin, self).initialize_request( | |
request, *args, **kwargs) |
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 import Func, F, Value | |
from images.models import Image | |
Image.objects.all().update(original_filename=Func(F('file'), Value('^.*\/(.*)$'), Value('\\1'), function='regexp_replace')) |
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
const fs = require('fs') | |
const urlLib = require('url') | |
function domainsFromHar(filePath) { | |
const rawData = fs.readFileSync(filePath) | |
const json = rawData && JSON.parse(rawData) | |
const { log } = json || {} | |
if (!log) return | |
const { pages, entries } = log |
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
const fs = require("fs"); | |
const rawData = fs.readFileSync("plan.json"); | |
const data = JSON.parse(rawData); | |
const changes = data.resource_changes.filter( | |
(c) => | |
c.change.actions.indexOf("create") !== -1 && | |
c.type.startsWith("aws_s3_bucket_") |