Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻

Roberth Solís rbtsolis

👨‍💻
View GitHub Profile
View BaseModel.py
from django.db import models
from simple_history.models import HistoricalRecords
from django.utils.translation import ugettext_lazy as _
class GetOrNoneManager(models.Manager):
"""
Adds get_or_none method to objects
"""
def get_object_or_none(self, default_value=None, *args, **kwargs):
@rbtsolis
rbtsolis / middleware.py
Created May 3, 2018
Django Access the Request or User Object Inside the Models and Signals
View middleware.py
# 1) Create a middlewares/middlewares.py file and copy this:
import threading
class RequestMiddleware:
def __init__(self, get_response, thread_local=threading.local()):
self.get_response = get_response
self.thread_local = thread_local
# One-time configuration and initialization.
View .env
APP_NAME='Hotel El Pueblo'
APP_ENV=local
APP_KEY=base64:y2eRdQynPR8l6vJUlNsO+1IiMUTB45ZdVjiFDi8v2SU=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
@rbtsolis
rbtsolis / language.py
Created Oct 13, 2017 — forked from beaufour/language.py
Django Middleware to choose language based on subdomain
View language.py
import logging
from django.utils import translation
class SubdomainLanguageMiddleware(object):
"""
Set the language for the site based on the subdomain the request
is being served on. For example, serving on 'fr.domain.com' would
make the language French (fr).
View stylus-linux.js
var fs = require('fs'),
path = require('path'),
child_process = require('child_process');
function watchStyles(sourcefile, destinationfolder) {
var Stylus = child_process.spawn('stylus', ['-c','-u','nib','-w', sourcefile, '--out', destinationfolder]);
Stylus.stdout.pipe(process.stdout); // notifications: watching, compiled, generated.
View stylus-win.js
var fs = require('fs'),
path = require('path');
function watchStyles(sourcefile, destinationfolder) {
var exec = require('child_process').exec;
var cmd = `stylus -c -u nib -w ${sourcefile} -o ${destinationfolder}`;
exec(cmd, function(error, stdout, stderr) {
if (stdout) {
console.log(stdout);
@rbtsolis
rbtsolis / index.blade.php
Last active Aug 10, 2017
Index View of Students Inveravel
View index.blade.php
@extends('layouts.master')
@section('title')
Students
@stop
@section('page_header')
Students
@stop
View stylus-compile.js
var fs = require('fs'),
path = require('path'),
child_process = require('child_process');
function watchStyles(sourcefile, destinationfolder) {
var Stylus = child_process.spawn('stylus', ['-c','-u', 'nib','-w', sourcefile, '--out', destinationfolder]);
Stylus.stdout.pipe(process.stdout); // notifications: watching, compiled, generated.
You can’t perform that action at this time.