Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM python:3.7 as backend

RUN apt-get update -qq \
&& apt-get install -y --no-install-recommends default-mysql-client=1.0.5 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update -qq \
&& apt-get install -y postgresql-contrib libpq-dev python3-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ENV PYTHONUNBUFFERED 1

Expand Down
5 changes: 2 additions & 3 deletions chart/lw-app/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ version: 0.0.1
appVersion: 0.0.1

dependencies:
- name: mariadb
chart: stable/mariadb
version: 7.5.1
- name: postgresql
version: 9.3.2
repository: "https://charts.bitnami.com/bitnami"
4 changes: 2 additions & 2 deletions chart/lw-app/templates/django-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ spec:
- name: DJANGO_SETTINGS_MODULE
value: 'lw.core.settings.production'
- name: DB_NAME
value: {{ .Values.mariadb.db.name }}
value: {{ .Release.Namespace}}-postgresql-headless
- name: DB_USER
value: {{ .Values.mariadb.db.user }}
value: {{ .Values.postgresql.postgresqlUsername }}
- name: DB_HOST
value: {{ .Release.Name }}-mariadb
- name: DB_PASSWORD
Expand Down
23 changes: 5 additions & 18 deletions chart/lw-app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,8 @@ nginx:
ingress:
enabled: false

mariadb:
master:
resources:
limits:
memory: 200Mi

replication:
enabled: false

rootUser:
forcePassword: true
password: test

db:
name: lw
user: lw
forcePassword: true
password: test
postgresql:
local: true
postgresqlPassword: qwerty
volumePermissions:
enabled: true
15 changes: 7 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ version: '3.4'

services:
db:
image: mariadb:10.3
image: postgres:13-alpine
environment:
MYSQL_DATABASE: lw
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- ./db:/var/lib/mysql
- ./mysql.conf.d:/etc/mysql/conf.d
- POSTGRES_HOST_AUTH_METHOD=trust
ports:
- 5432:5432

nginx:
build:
Expand All @@ -21,7 +19,7 @@ services:
build:
context: .
target: backend
command: bash -c "pip install -r requirements.txt && python manage.py migrate && ./manage.py runserver 0.0.0.0:8080"
command: bash -c "pip install -r requirements.txt && python manage.py migrate && python -m pdb manage.py runserver 0.0.0.0:8080"
volumes:
- .:/code
ports:
Expand All @@ -32,7 +30,8 @@ services:
DJANGO_ENV: dev
DJANGO_SETTINGS_MODULE: 'lw.core.settings.dev'
DB_NAME: 'lw'
DB_USER: 'root'
DB_USER: 'postgres'
DB_PASSWORD: ''
DB_HOST: db
DB_PORT: 5432
SECRET_KEY: secret_key
10 changes: 5 additions & 5 deletions import.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ def patched_save(self, *args, **kwargs):

home_page = HomePage.objects.live()[0]

index_page_type = ContentType.objects.get(app_label='translations', model='TranslationIndexPage')
index_page_type = ContentType.objects.get(app_label='translations', model='translationindexpage')
index_page = TranslationIndexPage(id=253, intro='', title='Переводы', slug='w', content_type=index_page_type)
home_page.add_child(instance=index_page)
index_page.save_revision().publish()

json_path = '/work/books_lw_dump.json'
json_path = 'books_lw_dump.json'
BookImporter(json_path).run()

json_path = '/work/translations_lw_dump.json'
json_path = 'translations_lw_dump.json'
TranslationPageImporter(json_path).run()

csv_path = '/work/users.csv'
UsersImporter(csv_path).run()
# csv_path = 'users.csv'
# UsersImporter(csv_path).run()
16 changes: 13 additions & 3 deletions lw/core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
INSTALLED_APPS = [
'lw.core',
'lw.home',
'lw.search',
'lw.translations',

'wagtailmedia',

'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.contrib.modeladmin',
'wagtail.contrib.postgres_search',
'wagtail.contrib.search_promotions',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
Expand All @@ -42,7 +44,6 @@
'wagtail.search',
'wagtail.admin',
'wagtail.core',
'wagtail.contrib.modeladmin',
'wagtailmenus',

'modelcluster',
Expand Down Expand Up @@ -122,11 +123,12 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('DB_NAME', 'oops'), # 'oops' is to avoid failure when we start dev_sqlite
'USER': os.environ.get('DB_USER', 'oops'),
'PASSWORD': os.environ.get('DB_PASSWORD', 'oops'),
'HOST': os.environ.get('DB_HOST', 'oops'),
'PORT': os.environ.get('DB_PORT', 'oops')
}
}

Expand Down Expand Up @@ -228,3 +230,11 @@
ACCOUNT_LOGIN_ON_PASSWORD_RESET = True
ACCOUNT_LOGOUT_REDIRECT_URL = '/'
ACCOUNT_EMAIL_VERIFICATION = None

WAGTAILSEARCH_BACKENDS = {
'default': {
'BACKEND': 'wagtail.contrib.postgres_search.backend',
'ATOMIC_REBUILD': True,
'SEARCH_CONFIG': 'russian',
},
}
12 changes: 1 addition & 11 deletions lw/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@
from wagtail.core import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls

from lw.search import views as search_views
from . import views

urlpatterns = [
path('django-admin/', admin.site.urls),

path('admin/', include(wagtailadmin_urls)),
path('documents/', include(wagtaildocs_urls)),

path('search/', search_views.search, name='search'),

# path('user/logout/', views.logout_view),

path('', include('allauth.urls')),

# For anything not caught by a more specific rule above, hand over to
# Wagtail's page serving mechanism. This should be the last pattern in
# the list:
path('', include('lw.translations.urls')),
path('', include(wagtail_urls)),
]

Expand Down
5 changes: 4 additions & 1 deletion lw/home/jinja2/home/sidebar_content.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Поиск<br>
<form action="search/node" method="GET">
<input type="search" name="query" />
<input type="submit" value="search" />
</form>
ВК-виджет<br>
Ссылки
Empty file removed lw/search/__init__.py
Empty file.
34 changes: 0 additions & 34 deletions lw/search/views.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "base.html" %}
{% load static wagtailcore_tags %}

{#% load static wagtailcore_tags %#}

{% block body_class %}template-searchresults{% endblock %}

Expand All @@ -8,7 +9,7 @@
{% block content %}
<h1>Search</h1>

<form action="{% url 'search' %}" method="get">
<form action="{{ url('search') }}" method="get">
<input type="text" name="query"{% if search_query %} value="{{ search_query }}"{% endif %}>
<input type="submit" value="Search" class="button">
</form>
Expand All @@ -17,20 +18,20 @@ <h1>Search</h1>
<ul>
{% for result in search_results %}
<li>
<h4><a href="{% pageurl result %}">{{ result }}</a></h4>
<h4><a href="{{ result.specific.url }}">{{ result }}</a></h4>
{% if result.search_description %}
{{ result.search_description }}
{% endif %}
</li>
{% endfor %}
</ul>

{% if search_results.has_previous %}
<a href="{% url 'search' %}?query={{ search_query|urlencode }}&amp;page={{ search_results.previous_page_number }}">Previous</a>
{% if search_results.has_previous() %}
<a href="{{ url('search') }}?query={{ search_query|urlencode }}&amp;page={{ search_results.previous_page_number() }}">Previous</a>
{% endif %}

{% if search_results.has_next %}
<a href="{% url 'search' %}?query={{ search_query|urlencode }}&amp;page={{ search_results.next_page_number }}">Next</a>
{% if search_results.has_next() %}
<a href="{{ url('search') }}?query={{ search_query|urlencode }}&amp;page={{ search_results.next_page_number() }}">Next</a>
{% endif %}
{% elif search_query %}
No results found
Expand Down
9 changes: 9 additions & 0 deletions lw/translations/models/book_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel

from wagtail.search import index
from django.utils import timezone

class BookPage(Page):
body = RichTextField(blank=True, null=True)

Expand Down Expand Up @@ -31,6 +34,12 @@ def children(self):
FieldPanel('readthesequences_link'),
]

search_fields = Page.search_fields + [
index.SearchField('title'),
index.SearchField('body'),
index.FilterField('date'),
]

def get_url_parts(self, *args, **kwargs):
(site_id, root_url, _) = super().get_url_parts(*args, **kwargs)
return (site_id, root_url, '/w/' + self.slug)
9 changes: 9 additions & 0 deletions lw/translations/models/translation_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

from wagtailmedia.edit_handlers import MediaChooserPanel

from wagtail.search import index
from django.utils import timezone

class TranslationPage(Page):
body = RichTextField(blank=True)
author = models.CharField(max_length=100, blank=True, null=True)
Expand Down Expand Up @@ -37,6 +40,12 @@ class TranslationPage(Page):
MediaChooserPanel('audio'),
]

search_fields = Page.search_fields + [
index.SearchField('title'),
index.SearchField('body'),
# index.FilterField('date'),
]

def get_url_parts(self, *args, **kwargs):
(site_id, root_url, _) = super().get_url_parts(*args, **kwargs)
return (site_id, root_url, '/w/' + self.slug)
6 changes: 6 additions & 0 deletions lw/translations/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from . import views

urlpatterns = [
path('search/node', views.search, name='search'),
]
34 changes: 33 additions & 1 deletion lw/translations/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from wagtail.core.models import Page
from wagtail.search.models import Query

# Create your views here.
def search(request):
search_query = request.GET.get('query', None)
page = request.GET.get('page', 1)

# Search
if search_query:
search_results = Page.objects.live().search(search_query)
query = Query.get(search_query)

# Record hit
query.add_hit()
else:
search_results = Page.objects.none()

# Pagination
paginator = Paginator(search_results, 10)
try:
search_results = paginator.page(page)
except PageNotAnInteger:
search_results = paginator.page(1)
except EmptyPage:
search_results = paginator.page(paginator.num_pages)

import pdb; pdb.set_trace()

return render(request, 'search.html', {
'search_query': search_query,
'search_results': search_results,
})
2 changes: 1 addition & 1 deletion services/data_migrations/importers/book/book_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def find_parent(self, created_books, index_page, parent_id):


def build_book(self, book_json):
bookpage_type = ContentType.objects.get(app_label='translations', model='BookPage')
bookpage_type = ContentType.objects.get(app_label='translations', model='bookpage')
slug = self.generate_slug(book_json['title'])

book = BookPage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def find_parent(self, books, created_translations, index_page, parent_id):


def build_translation(self, translation_json):
translationpage_type = ContentType.objects.get(app_label='translations', model='TranslationPage')
translationpage_type = ContentType.objects.get(app_label='translations', model='translationpage')
slug = self.generate_slug(translation_json['title'])

html_body = markdown.markdown(translation_json['body_value'], extensions=['md_in_html'])
Expand Down