mirror of https://gitlab.crans.org/bde/nk20
Compare commits
No commits in common. "2c7995a79e9ed5faea4628bd7fb9d139e517f4f2" and "518de596bb0999f1cac7c2c748ae5ae9a12e2d5c" have entirely different histories.
2c7995a79e
...
518de596bb
|
@ -1,3 +0,0 @@
|
|||
__pycache__
|
||||
media
|
||||
db.sqlite3
|
32
Dockerfile
32
Dockerfile
|
@ -1,27 +1,25 @@
|
|||
FROM python:3-alpine
|
||||
FROM python:3-buster
|
||||
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
# Install LaTeX requirements
|
||||
RUN apk add --no-cache gettext texlive texmf-dist-latexextra texmf-dist-fontsextra nginx gcc libc-dev libffi-dev postgresql-dev libxml2-dev libxslt-dev jpeg-dev
|
||||
|
||||
RUN apk add --no-cache bash
|
||||
|
||||
RUN mkdir /code
|
||||
WORKDIR /code
|
||||
COPY requirements /code/requirements
|
||||
RUN pip install gunicorn ptpython --no-cache-dir
|
||||
RUN pip install -r requirements/base.txt -r requirements/cas.txt -r requirements/production.txt --no-cache-dir
|
||||
|
||||
RUN apt update && \
|
||||
apt install -y gettext nginx uwsgi uwsgi-plugin-python3 && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install LaTeX requirements
|
||||
RUN apt update && \
|
||||
apt install -y texlive-latex-extra texlive-fonts-extra texlive-lang-french && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY . /code/
|
||||
|
||||
# Configure nginx
|
||||
RUN mkdir /run/nginx
|
||||
RUN ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log
|
||||
RUN ln -sf /code/nginx_note.conf_docker /etc/nginx/conf.d/nginx_note.conf
|
||||
RUN rm /etc/nginx/conf.d/default.conf
|
||||
# Comment what is not needed
|
||||
RUN pip install -r requirements/base.txt
|
||||
RUN pip install -r requirements/cas.txt
|
||||
RUN pip install -r requirements/production.txt
|
||||
|
||||
ENTRYPOINT ["/code/entrypoint.sh"]
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["./manage.py", "shell_plus", "--ptpython"]
|
||||
EXPOSE 8000
|
||||
|
|
|
@ -24,8 +24,7 @@ class ClubTable(tables.Table):
|
|||
}
|
||||
model = Club
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
fields = ('name', 'email',)
|
||||
order_by = ('name',)
|
||||
fields = ('id', 'name', 'email')
|
||||
row_attrs = {
|
||||
'class': 'table-row',
|
||||
'id': lambda record: "row-" + str(record.pk),
|
||||
|
|
|
@ -299,22 +299,6 @@ class ClubListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
|||
model = Club
|
||||
table_class = ClubTable
|
||||
|
||||
def get_queryset(self, **kwargs):
|
||||
"""
|
||||
Filter the user list with the given pattern.
|
||||
"""
|
||||
qs = super().get_queryset().filter()
|
||||
if "search" in self.request.GET:
|
||||
pattern = self.request.GET["search"]
|
||||
|
||||
qs = qs.filter(
|
||||
Q(name__iregex=pattern)
|
||||
| Q(note__alias__name__iregex="^" + pattern)
|
||||
| Q(note__alias__normalized_name__iregex=Alias.normalize("^" + pattern))
|
||||
)
|
||||
|
||||
return qs
|
||||
|
||||
|
||||
class ClubDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
||||
"""
|
||||
|
|
|
@ -163,12 +163,6 @@ class Transaction(PolymorphicModel):
|
|||
When saving, also transfer money between two notes
|
||||
"""
|
||||
|
||||
if not self.source.is_active or not self.destination.is_active:
|
||||
if 'force_insert' not in kwargs or not kwargs['force_insert']:
|
||||
if 'force_update' not in kwargs or not kwargs['force_update']:
|
||||
raise ValidationError(_("The transaction can't be saved since the source note "
|
||||
"or the destination note is not active."))
|
||||
|
||||
# If the aliases are not entered, we assume that the used alias is the name of the note
|
||||
if not self.source_alias:
|
||||
self.source_alias = str(self.source)
|
||||
|
@ -177,7 +171,7 @@ class Transaction(PolymorphicModel):
|
|||
self.destination_alias = str(self.destination)
|
||||
|
||||
if self.source.pk == self.destination.pk:
|
||||
# When source == destination, no money is transferred
|
||||
# When source == destination, no money is transfered
|
||||
super().save(*args, **kwargs)
|
||||
return
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ class ConsoView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
|||
table_class = HistoryTable
|
||||
|
||||
def get_queryset(self, **kwargs):
|
||||
return super().get_queryset(**kwargs).order_by("-created_at", "-id")[:20]
|
||||
return super().get_queryset(**kwargs).order_by("-created_at", "-id").all()[:20]
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""
|
||||
|
|
|
@ -272,7 +272,7 @@
|
|||
"note",
|
||||
"alias"
|
||||
],
|
||||
"query": "[\"AND\", [\"OR\", {\"note__in\": [\"NoteUser\", \"objects\", [\"filter\", {\"user__memberships__club__name\": \"Kfet\"}], [\"all\"]]}, {\"note__in\": [\"NoteClub\", \"objects\", [\"all\"]]}], {\"note__is_active\": true}]",
|
||||
"query": "[\"OR\", {\"note__in\": [\"NoteUser\", \"objects\", [\"filter\", {\"user__memberships__club__name\": \"Kfet\"}], [\"all\"]]}, {\"note__in\": [\"NoteClub\", \"objects\", [\"all\"]]}]",
|
||||
"type": "view",
|
||||
"mask": 1,
|
||||
"field": "",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
|
@ -15,10 +15,4 @@ python manage.py compilemessages
|
|||
python manage.py makemigrations
|
||||
python manage.py migrate
|
||||
|
||||
nginx
|
||||
|
||||
if [ "$DJANGO_APP_STAGE" = "prod" ]; then
|
||||
gunicorn -b 0.0.0.0:8000 --workers=2 --threads=4 --worker-class=gthread note_kfet.wsgi --access-logfile '-' --error-logfile '-';
|
||||
else
|
||||
python manage.py runserver 0.0.0.0:8000;
|
||||
fi
|
||||
python manage.py runserver 0.0.0.0:8000
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
upstream note {
|
||||
server 127.0.0.1:8000;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name note;
|
||||
|
||||
location / {
|
||||
proxy_pass http://note;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $host;
|
||||
proxy_redirect off;
|
||||
}
|
||||
|
||||
location /static {
|
||||
alias /code/static/;
|
||||
}
|
||||
|
||||
location /media {
|
||||
alias /code/media/;
|
||||
}
|
||||
}
|
|
@ -50,10 +50,8 @@ class SessionMiddleware(object):
|
|||
|
||||
def __call__(self, request):
|
||||
user = request.user
|
||||
if 'HTTP_X_REAL_IP' in request.META:
|
||||
ip = request.META.get('HTTP_X_REAL_IP')
|
||||
elif 'HTTP_X_FORWARDED_FOR' in request.META:
|
||||
ip = request.META.get('HTTP_X_FORWARDED_FOR').split(', ')[0]
|
||||
if 'HTTP_X_FORWARDED_FOR' in request.META:
|
||||
ip = request.META.get('HTTP_X_FORWARDED_FOR')
|
||||
else:
|
||||
ip = request.META.get('REMOTE_ADDR')
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<h4>
|
||||
{% trans "search clubs" %}
|
||||
</h4>
|
||||
<input class="form-control mx-auto w-25" type="text" id="search_field"/>
|
||||
<input class="form-control mx-auto w-25" type="text" onkeyup="search_field_moved();return(false);" id="search_field"/>
|
||||
<hr>
|
||||
<a class="btn btn-primary text-center my-4" href="{% url 'member:club_create' %}">{% trans "Create club" %}</a>
|
||||
</div>
|
||||
|
@ -28,32 +28,43 @@
|
|||
{% endblock %}
|
||||
{% block extrajavascript %}
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
let old_pattern = null;
|
||||
let searchbar_obj = $("#search_field");
|
||||
var timer_on = false;
|
||||
var timer;
|
||||
|
||||
function reloadTable() {
|
||||
let pattern = searchbar_obj.val();
|
||||
$("#club_table").load(location.href + "?search=" + pattern.replace(" ", "%20") + " #club_table", init);
|
||||
}
|
||||
function getInfo() {
|
||||
var asked = $("#search_field").val();
|
||||
/* on ne fait la requête que si on a au moins un caractère pour chercher */
|
||||
var sel = $(".table-row");
|
||||
if (asked.length >= 1) {
|
||||
$.getJSON("/api/members/club/?format=json&search="+asked, function(buttons){
|
||||
let selected_id = buttons.results.map((a => "#row-"+a.id));
|
||||
$(".table-row,"+selected_id.join()).show();
|
||||
$(".table-row").not(selected_id.join()).hide();
|
||||
|
||||
searchbar_obj.keyup(function() {
|
||||
if (timer_on)
|
||||
clearTimeout(timer);
|
||||
timer_on = true;
|
||||
setTimeout(reloadTable, 0);
|
||||
});
|
||||
}else{
|
||||
// show everything
|
||||
$('table tr').show();
|
||||
}
|
||||
}
|
||||
var timer;
|
||||
var timer_on;
|
||||
/* Fontion appelée quand le texte change (délenche le timer) */
|
||||
function search_field_moved(secondfield) {
|
||||
if (timer_on) { // Si le timer a déjà été lancé, on réinitialise le compteur.
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout("getInfo(" + secondfield + ")", 300);
|
||||
}
|
||||
else { // Sinon, on le lance et on enregistre le fait qu'il tourne.
|
||||
timer = setTimeout("getInfo(" + secondfield + ")", 300);
|
||||
timer_on = true;
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
// clickable row
|
||||
$(document).ready(function($) {
|
||||
$(".table-row").click(function() {
|
||||
window.document.location = $(this).data("href");
|
||||
timer_on = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
init();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
$(document).ready(function() {
|
||||
let old_pattern = null;
|
||||
let searchbar_obj = $("#searchbar");
|
||||
var timer_on = false;
|
||||
var timer;
|
||||
|
||||
function reloadTable() {
|
||||
let pattern = searchbar_obj.val();
|
||||
|
@ -35,19 +33,17 @@
|
|||
return;
|
||||
|
||||
$("#user_table").load(location.href + "?search=" + pattern.replace(" ", "%20") + " #user_table", init);
|
||||
|
||||
$(".table-row").click(function() {
|
||||
window.document.location = $(this).data("href");
|
||||
});
|
||||
}
|
||||
|
||||
searchbar_obj.keyup(function() {
|
||||
if (timer_on)
|
||||
clearTimeout(timer);
|
||||
timer_on = true;
|
||||
setTimeout(reloadTable, 0);
|
||||
});
|
||||
searchbar_obj.keyup(reloadTable);
|
||||
|
||||
function init() {
|
||||
$(".table-row").click(function() {
|
||||
window.document.location = $(this).data("href");
|
||||
timer_on = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue