diff --git a/app/settings.py b/app/settings.py index 00befba..07931fd 100644 --- a/app/settings.py +++ b/app/settings.py @@ -16,7 +16,6 @@ from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent - # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ @@ -126,3 +125,6 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" AUTH_USER_MODEL = "core.User" LOGIN_REDIRECT_URL = "/" + + +from app.local_settings import * # noqa diff --git a/app/urls.py b/app/urls.py index 77dbe3e..c810a03 100644 --- a/app/urls.py +++ b/app/urls.py @@ -16,8 +16,8 @@ Including another URLconf from django.contrib import admin from django.urls import include, path -from core.views import Home, Profile, Signup from core.ui.views.drilldown import Drilldown +from core.views import Home, Profile, Signup urlpatterns = [ path("", Home.as_view(), name="home"), diff --git a/core/models.py b/core/models.py index 4cdf95b..4de0e93 100644 --- a/core/models.py +++ b/core/models.py @@ -25,5 +25,7 @@ class User(AbstractUser): plans = models.ManyToManyField(Plan, blank=True) def has_plan(self, plan): + if not self.paid: # We can't have any plans if we haven't paid + return False plan_list = [plan.name for plan in self.plans.all()] return plan in plan_list diff --git a/core/static/style.css b/core/static/style.css index b20149c..a5c3708 100644 --- a/core/static/style.css +++ b/core/static/style.css @@ -114,6 +114,11 @@ h5 { padding-top: 12px; padding-bottom: 3px; } +.search-box { + display: flex; + width: 100%; + height: 100%; +} .profile-info p { align-items: left; justify-content: left; diff --git a/core/templates/base.html b/core/templates/base.html index 09d1968..6c49dee 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -8,7 +8,7 @@ Pathogen - {{ request.path_info }} - + {# #}
@@ -28,7 +28,7 @@ {% if user.is_authenticated %}
  • Profile
  • {% endif %} - {% if user.plan == "drilldown" and user.paid %} + {% if user.paid %}
  • Drilldown
  • {% endif %} {% if not user.is_authenticated %} diff --git a/core/templates/registration/signup.html b/core/templates/registration/signup.html index 7827a70..2ecfc02 100644 --- a/core/templates/registration/signup.html +++ b/core/templates/registration/signup.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% load static %} +{% load static %} {% load crispy_forms_tags %} {% block content %} diff --git a/core/templates/ui/drilldown.html b/core/templates/ui/drilldown.html index 27487c4..8eb1754 100644 --- a/core/templates/ui/drilldown.html +++ b/core/templates/ui/drilldown.html @@ -1,25 +1,30 @@ {% extends "base.html" %} +{% load static %} {% block content %} -

    Welcome to search, {{ name }}!

    +

    Welcome to search, {{ user.first_name }}!

    -
    -
    -
    -

    PROFILE INFO

    -
    -
    - {% if user.seti %} - {% if user.plan == None %} - {% include 'checkout.html' %} +
    +
    +
    +
    + {% if query is not None %} +

    Searching for {{ query }}

    {% else %} -
    - +

    Search our database

    + {% endif %} +
    +
    + {% if query is None %} + +
    + {% csrf_token %} + + +
    {% endif %} - {% else %} - - {% endif %} +
    diff --git a/core/ui/views/drilldown.py b/core/ui/views/drilldown.py index 2716ebe..db11a87 100644 --- a/core/ui/views/drilldown.py +++ b/core/ui/views/drilldown.py @@ -1,12 +1,28 @@ from django.contrib.auth.mixins import LoginRequiredMixin -from django.views import View from django.shortcuts import render +from django.views import View + +from core.lib.opensearch import initialise_opensearch, run_main_query + +client = initialise_opensearch() class Drilldown(LoginRequiredMixin, View): template_name = "ui/drilldown.html" - def get(self, request, *args, **kwargs): + def get(self, request): if not request.user.has_plan("drilldown"): return render(request, "denied.html") - return render(request, self.template_name) \ No newline at end of file + return render(request, self.template_name) + + def post(self, request): + if not request.user.has_plan("drilldown"): + return render(request, "denied.html") + if "query" in request.POST: + query = request.POST["query"] + results = run_main_query(client, query) + print("RESULTS", results) + context = {"query": query} + print("CONTEXT", context) + return render(request, self.template_name, context) + return render(request, self.template_name) diff --git a/core/views.py b/core/views.py index ffde810..03a99ad 100644 --- a/core/views.py +++ b/core/views.py @@ -9,20 +9,17 @@ from core.forms import NewUserForm # Create your views here - - - class Home(View): template_name = "index.html" - def get(self, request, *args, **kwargs): + def get(self, request): return render(request, self.template_name) class Profile(LoginRequiredMixin, View): template_name = "profile.html" - def get(self, request, *args, **kwargs): + def get(self, request): return render(request, self.template_name) diff --git a/requirements.txt b/requirements.txt index 47838a2..e5a3b30 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ django pre-commit +django-crispy-forms +opensearch-py \ No newline at end of file