Skip to content

Commit

Permalink
Merge pull request #99 from Go-In/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
monthol8th authored Oct 1, 2017
2 parents 97dfb22 + 792ad0f commit 715f6ef
Show file tree
Hide file tree
Showing 30 changed files with 5,592 additions and 178 deletions.
13 changes: 12 additions & 1 deletion go_coup/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
'index.apps.IndexConfig',
'usermanage.apps.UsermanageConfig',
'storemanage.apps.StoremanageConfig',
'customermanage.apps.CustomermanageConfig'
'customermanage.apps.CustomermanageConfig',
'haystack',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -107,6 +109,15 @@
},
]

# Haystack connect with elasticsearch

HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch2_backend.Elasticsearch2SearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
},
}

# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
Expand Down
14 changes: 14 additions & 0 deletions index/search_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from haystack import indexes

from storemanage.models import Ticket


class ProductIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
name = indexes.CharField(model_attr='name')

def get_model(self):
return Ticket

def index_queryset(self, using=None):
return self.get_model().objects.all()
1 change: 1 addition & 0 deletions index/templates/search/indexes/storemanage/ticket_text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ object.name }}
41 changes: 41 additions & 0 deletions index/templates/search/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% include 'components/header.html' %}

{% block content %}
<h2>Search</h2>

<form method="get" action=".">
<table>
{{ form.as_table }}
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" value="Search">
</td>
</tr>
</table>

{% if query %}
<h3>Results</h3>

{% for result in page.object_list %}
<p>
<a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
</p>
{% empty %}
<p>No results found.</p>
{% endfor %}

{% if page.has_previous or page.has_next %}
<div>
{% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
|
{% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
</div>
{% endif %}
{% else %}
{# Show some example queries to run, maybe query syntax, something else? #}
{% endif %}
</form>
{% endblock %}

{% include 'components/footer.html' %}
5 changes: 4 additions & 1 deletion index/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import url
from django.conf.urls import url, include
from django.contrib import admin

from . import views
Expand All @@ -8,4 +8,7 @@
url(r'^$', views.index, name='index'),
url(r'^detail/(?P<ticket_id>[0-9]+)/$', views.detail, name='detail'),
url(r'^cart/$', views.cart, name='cart'),
url(r'^catalog/$', views.catalog, name='catalog'),
# url(r'^search/', include('haystack.urls')),
url(r'^search-demo/$', views.searchDemo, name='search-demo'),
]
34 changes: 31 additions & 3 deletions index/views.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,52 @@
from django.shortcuts import render
from django.shortcuts import render, redirect
from storemanage.models import Ticket

from django.http import JsonResponse

# Create your views here.
def index(request):
tickets = Ticket.objects.all()
tickets = Ticket.objects.filter(available=True)
return render(request, 'index/index.html', {
'tickets': tickets
})

def detail(request, ticket_id):
success = request.session.get('success')
if success:
request.session['success'] = False
ticket = Ticket.objects.get(pk=ticket_id)
if ticket.available == False:
return redirect('index:index')
return render(request, 'index/detail.html', {
'ticket' : ticket
'ticket' : ticket,
'success': success
})

def cart(request):
data = request.GET
if 'cart' not in data:
return redirect('index:index')
items = data['cart'].split(',') if data['cart'] else []
tickets = Ticket.objects.filter(pk__in=items)
return render(request, 'index/cart.html', {
'tickets': tickets
})

def catalog(request):
tickets = Ticket.objects.filter(available=True)
return render(request, 'index/catalog.html', {
'tickets': tickets
})

def search(request):
return render(request, 'index/search.html')

def searchDemo(request):
data = request.POST
name = data['search_name']
tickets = Ticket.objects.filter(name__search=name)
for i in tickets:
print(i.detail)
return render(request, 'index/search-demo.html', {
'tickets' : tickets
})
2 changes: 2 additions & 0 deletions market/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import transaction
from django.shortcuts import render, get_object_or_404, redirect
from storemanage.models import Currency, Ticket
from index.views import detail
from usermanage.models import Store
from customermanage.models import Wallet, Coupon
from django.contrib.auth.decorators import login_required, user_passes_test, permission_required
Expand Down Expand Up @@ -35,6 +36,7 @@ def purchase(request):
ticket.save()
coupon = Coupon(user = user, ticket = ticket)
coupon.save()
request.session['success'] = True
return redirect('index:detail',ticket_id = ticket_id)

def checkout(request):
Expand Down
Loading

0 comments on commit 715f6ef

Please sign in to comment.