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
def get_reserved_tickets(self, performance=None): | |
Offer = apps.get_model('events', 'Offer') | |
Order = apps.get_model('events', 'Order') | |
offers = Offer.objects.published().filter( | |
state=1, | |
ticket_price=self, | |
) | |
if performance: | |
offers = offers.filter(performance=performance) | |
pending_tickets = offers.filter(basket__state=0).distinct() \ |
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
import datetime | |
import time | |
from django.conf import settings | |
import elasticsearch_dsl as es | |
from elasticsearch.helpers import bulk | |
from elasticsearch_dsl.connections import connections | |
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 pydoc import locate | |
from django.conf import settings | |
from django.core.management.base import BaseCommand | |
class Command(BaseCommand): | |
def __init__(self): | |
super(Command, self).__init__() |
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
ES_CONNECTIONS = { | |
'default': { | |
'hosts': [http://localhost:9200], | |
} | |
} | |
ES_INDEXES = { | |
'default': [ | |
('users', 'some_app.indexes.Article'), | |
] |
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
import elasticsearch_dsl as es | |
from some_app import abstract_index | |
from some_app.models import Post | |
class Article(abstract_index.DocumentBase): | |
title = es.Text(analyzer='snowball', fields={'raw': es.Keyword()}) | |
body = es.Text(analyzer='snowball') |
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 datetime import datetime | |
from elasticsearch_dsl import Document, Date, Keyword, Text | |
from elasticsearch_dsl.connections import connections | |
# Define a default Elasticsearch client | |
connections.create_connection(hosts=['localhost']) | |
class Article(Document): | |
title = Text(analyzer='snowball', fields={'raw': Keyword()}) | |
body = Text(analyzer='snowball') |
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 elasticsearch import Elasticsearch | |
client = Elasticsearch() | |
response = client.search( | |
index="my-index", | |
body={ | |
"query": { | |
"bool": { | |
"must": [{"match": {"title": "python"}}], | |
"must_not": [{"match": {"description": "beta"}}], |
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 Solution(object): | |
def __init__(self): | |
self.arr = [] | |
def add_product(self, name, locations): | |
self.arr.append((name, locations)) | |
def get_locations(self): | |
data = {} |
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
import datetime | |
import re | |
import urllib | |
from django.conf import settings | |
import requests | |
from lxml import html | |
from .models import Product |