Skip to content

Instantly share code, notes, and snippets.

@chris-ramon
chris-ramon / class_form.py
Last active December 11, 2015 23:18
class form django
class ManufacturerProductionDetailForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_show_errors = True
self.helper.form_tag = False
self.update_base_fields_label()
self.update_type_transport_field_choices(*args, **kwargs)
super(ManufacturerProductionDetailForm, self).__init__(*args, **kwargs)
@chris-ramon
chris-ramon / gitignore.sh
Created March 3, 2013 21:25
basic gitignore
# Ignore the default SQLite database.
/db/*.sqlite3
# Ignore idea files
/.idea
/wordsmark.iml
# Ignore DS_Store files
.DS_Store
@chris-ramon
chris-ramon / testing.py
Last active December 14, 2015 20:49
django testing, mocks + message framework
def test_when_email_exist(self):
from django.contrib.messages.storage.fallback import FallbackStorage
from mock import MagicMock
user_data = {
'email': 'manufacturer_test@gmail.com'
}
with self.assertNumQueries(1):
User.objects.create(**user_data)
User.get_roles = MagicMock(return_value=['MANUFACTURER'])
from selenium import webdriver
def select_from_chosen(driver, id, value):
chosen = driver.find_element_by_id(id + '_chzn')
results = chosen.find_elements_by_css_selector(".chzn-results li")
found = False
for result in results:
if result.text == value:
@chris-ramon
chris-ramon / search_mixin.py
Created April 11, 2013 20:38
SearchMixin for django framework.
# Helper functions
def dict_strip_unicode_keys(uni_dict):
"""
Converts a dict of unicode keys into a dict of ascii keys.
Useful for converting a dict to a kwarg-able format.
"""
data = {}
@chris-ramon
chris-ramon / search_mixin.py
Last active December 16, 2015 04:49
SearchMixin example.
class ProductListView(LoginRequiredMixin, SearchFormMixin, ListView):
model = Product
search_form_class = ProductFiltersForm
template_name = 'panel/products/list.html'
context_object_name = 'product_list'
paginate_by = settings.PANEL_PAGE_SIZE
filtering = {
'manufacturer': SearchFormMixin.ALL,
'category': SearchFormMixin.ALL,
}
curationApp.directive('rpDisplayCategories', ['$compile', function($compile) {
return {
restrict: 'A',
replace: true,
templateUrl: curation_template_urls.category_select,
link: function(scope, element, attrs) {
// element is a select tag
element.bind('change', function() {
debugger;
var parent_category_id = element.val();
@chris-ramon
chris-ramon / simulation.php
Last active December 17, 2015 12:49
systems simulation
class GNA {
// b = 26
const M = 67108864;
// M y C PESI
const C = 3;
// K = 1
const A = 5;
public function get_randoms($Xo=100, $total_randoms=10){
// Retorna un arreglo de numeros aleatorios
@chris-ramon
chris-ramon / Persistence.php
Created May 26, 2013 23:09
persistence mongodb shopping cart sample
<?php
class Persistence {
private static $_instance=null;
private $_conexion;
public static function getImagen($id)
{
$mongo = new Mongo();
@chris-ramon
chris-ramon / tw.css
Created June 12, 2013 17:38
tw bootstrap CSS
/* ALLOWS HAVE MULTUPLIE THUMBNAILS */
.row-fluid ul.thumbnails li.span12 + li { margin-left : 0px; }
.row-fluid ul.thumbnails li.span6:nth-child(2n + 3) { margin-left : 0px; }
.row-fluid ul.thumbnails li.span4:nth-child(3n + 4) { margin-left : 0px; }
.row-fluid ul.thumbnails li.span3:nth-child(4n + 5) { margin-left : 0px; }