Skip to content

Instantly share code, notes, and snippets.

View ricardosasilva's full-sized avatar

Ricardo Almeida Silva ricardosasilva

View GitHub Profile
@ricardosasilva
ricardosasilva / forms.py
Created September 9, 2020 21:45
Exemplo Compressor - Cristofer
class CompressorForm(forms.ModelForm):
class Meta:
model = Compressor
exclude = ['unidade', ]
def __init__(self, unidade, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['regime_de_atuacao'].queryset = Regime.objects.filter(unidade=unidade) # Filtra os valores exibidos no campo
@ricardosasilva
ricardosasilva / get_credentials.py
Last active January 18, 2019 15:38
Download Vault credentials recursively as JSON
"""
Get Vault credentials recursively as json.
Requirements: requests lib. Run pip to install it:
$ pip install requests
To run this command:
$ python get_credentials.py <initial url> <token>
@ricardosasilva
ricardosasilva / elasticsearch_custom_backend.py
Last active August 29, 2015 14:09
Custom Haystack Elasticsearch backend with function_score and percolator support
from haystack.backends.elasticsearch_backend import ElasticsearchSearchQuery, ElasticsearchSearchBackend, \
ElasticsearchSearchEngine
from haystack.query import SearchQuerySet
from haystack.constants import DEFAULT_ALIAS, DJANGO_CT
from django.conf import settings
from haystack.utils import get_model_ct
# Snagged this a LOT of this from: https://github.com/josephdrose/django-haystack
This is an example how to perform multi-select faceting in ElasticSearch.
Selecting multiple values from the same facet will result in an OR filter between each of the values:
(facet1.value1 OR facet1.value2)
Faceting on more than one facet will result in an AND filter between each facet:
(facet1.value1 OR facet1.value2) AND (facet2.value1)
I have chosen to update the counts for each facet the selected value DOES NOT belong to since we are performing an AND between each facet. I have included an example that shows how to keep the counts if you don't want to do this (filter0.sh).