Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow all features to work in development #267

Draft
wants to merge 2 commits into
base: upgrade-django
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ COPY backend /src/backend/
COPY ext /src/ext/
COPY Makefile /src/

ENV SEARCHDB_PATH /xappydb
ENV PYTHONIOENCODING utf-8:ignore
RUN /etc/init.d/redis-server start && \
make reindex statsporn && \
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ global_scss_components = $(wildcard global/static/css/*/*.scss)
mission_dirs = $(subst missions/shared,,$(wildcard missions/*))
PYTHON ?= python3
SASS ?= pyscss
SEARCHDB_PATH ?= /xappydb

# Dev Django runserver variables
dev_webserver_ip ?= 0.0.0.0
Expand All @@ -22,13 +23,15 @@ collectstatic: productioncss statsporn
DJANGOENV=live $(PYTHON) -m website.manage collectstatic --noinput --ignore=*.scss
DJANGOENV=live $(PYTHON) -m global.manage collectstatic --noinput --ignore=*.scss

reindex: $(indexer)
rm -rf xappydb
reindex: $(SEARCHDB_PATH)

$(SEARCHDB_PATH): missions/*/transcripts/* missions/shared/glossary/* backend/indexer.py
rm -rf $(SEARCHDB_PATH)
$(PYTHON) -m backend.indexer

statsporn: $(mission_dirs:%=%/images/stats/graph_0.png)

missions/%/images/stats/graph_0.png: missions/%/transcripts/*
missions/%/images/stats/graph_0.png: missions/%/transcripts/* backend/stats_porn_assets/* backend/stats_porn.py
$(PYTHON) -m backend.stats_porn $*

productioncss: $(website_css_targets) $(global_css_targets)
Expand Down
6 changes: 2 additions & 4 deletions backend/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

from backend.parser import TranscriptParser, MetaParser
from backend.api import Act, KeyScene, Character, Glossary, LogLine
from backend.util import redis_connection, seconds_to_timestamp
from backend.util import redis_connection, seconds_to_timestamp, get_search_indexer_connection

search_db = xappy.IndexerConnection(
os.path.join(os.path.dirname(__file__), '..', 'xappydb'),
)
search_db = get_search_indexer_connection()

def mission_time_to_timestamp(mission_time):
"""Takes a mission time string (XX:XX:XX:XX) and converts it to a number of seconds"""
Expand Down
12 changes: 12 additions & 0 deletions backend/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import math
import os
import redis
import xappy

def seconds_to_timestamp(seconds):
abss = abs(seconds)
Expand Down Expand Up @@ -28,3 +29,14 @@ def timestamp_to_seconds(timestamp):
os.environ.get("REDIS_URL", "redis://localhost:6379"),
decode_responses=True
)

searchdb_location = os.getenv(
'SEARCHDB_PATH',
os.path.join(os.path.dirname(__file__), '..', 'xappydb')
)

def get_search_indexer_connection(path=searchdb_location):
return xappy.IndexerConnection(path)

def get_search_connection(path=searchdb_location):
return xappy.SearchConnection(path)
10 changes: 2 additions & 8 deletions global/apps/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from django.urls import reverse
from django.conf import settings
from django.utils.safestring import mark_safe
import xappy
import xapian
import redis
from backend.api import LogLine, Character
from backend.util import get_search_connection

PAGESIZE = 20

Expand Down Expand Up @@ -39,13 +39,7 @@ def get_context_data(self):
}

# Get the results from Xapian
db = xappy.SearchConnection(
os.path.join(
settings.SITE_ROOT,
'..',
"xappydb",
),
)
db = get_search_connection()
query = db.query_parse(
q,
default_op=db.OP_OR,
Expand Down
11 changes: 2 additions & 9 deletions website/apps/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
from django.urls import reverse
from django.conf import settings
from django.utils.safestring import mark_safe
import xappy
import xapian
import redis
from backend.api import LogLine, Character
from backend.util import timestamp_to_seconds
from backend.util import timestamp_to_seconds, get_search_connection
from common.views import MemorialMixin

PAGESIZE = 20
Expand Down Expand Up @@ -43,13 +42,7 @@ def get_context_data(self):
}

# Get the results from Xapian
db = xappy.SearchConnection(
os.path.join(
settings.SITE_ROOT,
'..',
"xappydb",
),
)
db = get_search_connection()
db.set_weighting_scheme(
xapian.BM25Weight(
1, # k1
Expand Down
4 changes: 4 additions & 0 deletions website/configs/development/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
from local_settings import *
except ImportError:
pass

STATICFILES_DIRS += [
"/home/spacelog/assets/website"
]