diff --git a/Vagrantfile b/Vagrantfile index af9ad85..10e9410 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -4,7 +4,13 @@ $msg_up = < 0 else "" return render_template('editpoll.html', poll_id=poll_id, name=name, options=options, choice_type=choice_type, possible_recipients=possible_recipients, sending_out_to_amount=sending_out_to_amount, - closes_on_date=closes_on_date, mail_template=mail_template, should_disable=should_disable, + closes_on_date=closes_on_date.strftime("%Y-%m-%d %H:%M"), mail_template=mail_template, should_disable=should_disable, max_choices=max_choices, description=description) @app.route('/admin/editpoll', methods=['POST']) @@ -353,10 +356,28 @@ def admin_sendout_plan_post(): if not row: return "Głosowanie nie istnieje", 400 + closeOnDate = query_db_one('select closes_on_date from polls where id=%s and owner_user=%s', [poll_id, int(current_user.get_id())]) + + timestamp = f'{request.form["planSendoutDate"]} {request.form["planSendoutTime"]}' - db_execute('set time zone \'Europe/Warsaw\'; update polls set planned_start_sending=%s::timestamptz where id=%s and owner_user=%s', - [timestamp, poll_id, int(current_user.get_id())]) - get_db().commit() + + #todo: improve name. Tired lol + beforeCloseMins = 5 + + + t1=datetime.strptime(timestamp,"%Y-%m-%d %H:%M") + t2=datetime.now() + tClose = closeOnDate[0].replace(tzinfo=None) #ByPassTMP + difCl = tClose - t1 + + if t1 <= t2: + flash("Data wysyłki jest z przeszłości") + elif difCl.total_seconds() / 60 < beforeCloseMins: + flash("Wysłanie maili musi nastapić " + str(beforeCloseMins) + " min najpóźniej przed końcem wyborów") + else: + db_execute('set time zone \'Europe/Warsaw\'; update polls set planned_start_sending=%s::timestamptz where id=%s and owner_user=%s', + [timestamp, poll_id, int(current_user.get_id())]) + get_db().commit() return redirect(f'/admin/sendout?id={poll_id}', code=303) @@ -454,21 +475,28 @@ def admin_results(): return "Głosowanie nie istnieje", 400 name, options, max_choices, possible_recipients_len, sending_out_to_len, sent_to_len = row print(f"ilosc opcji :{ max_choices}") - vote_results = result_getter(poll_id, max_choices) - - voted_len = int(subprocess.Popen(['du', '--inodes', '-sS', f"/opt/sw/poll/{poll_id}/results/"], stdout=subprocess.PIPE).stdout.read().decode('utf8').split('\t')[0]) - 1 results = [] - for i, option in enumerate(options): - results.append({ 'score': vote_results.get(f"option_{i}", 0), 'name': option['name'], 'description': option['description'] }) + + try: + vote_results = result_getter(poll_id, max_choices) + + voted_len = int(subprocess.Popen(['du', '--inodes', '-sS', f"/opt/sw/poll/{poll_id}/results/"], stdout=subprocess.PIPE).stdout.read().decode('utf8').split('\t')[0]) - 1 + + + for i, option in enumerate(options): + results.append({ 'score': vote_results.get(f"option_{i}", 0), 'name': option['name'], 'description': option['description'] }) + except: + return "Nikt nie zagłosował v Brak plików", 400 + return render_template('results.html', - name=name, - possible_recipients_len=possible_recipients_len, - sending_out_to_len=sending_out_to_len, - sent_to_len=sent_to_len, - voted_len=voted_len, - results=results) + name=name, + possible_recipients_len=possible_recipients_len, + sending_out_to_len=sending_out_to_len, + sent_to_len=sent_to_len, + voted_len=voted_len, + results=results) @app.route('/admin/peek', methods=['GET']) @login_required diff --git a/sw-admin/templates/sendout.html b/sw-admin/templates/sendout.html index 05c6d65..e4b54dd 100644 --- a/sw-admin/templates/sendout.html +++ b/sw-admin/templates/sendout.html @@ -1,6 +1,18 @@ {% extends "baseloggedin.html" %} {% block title %}Rozsyłka maili dla głosowania "{{name}}"{% endblock %} {% block content %} + + +{% with messages = get_flashed_messages() %} + {% if messages %} +
+ {% for message in messages %} + + {% endfor %} +
+ {% endif %} +{% endwith %} +

Rozsyłka maili dla głosowania "{{name}}"

diff --git a/sw-database/schema.sql b/sw-database/schema.sql index 70d164f..391ca04 100644 --- a/sw-database/schema.sql +++ b/sw-database/schema.sql @@ -57,8 +57,7 @@ create table polls( -- Czas kiedy głosowanie się kończy -- Format: "YYYY-MM-DD hh:mm" -- Na przykład: "2022-01-01 13:30" - -- Issue na zmianę typu na `timestamp with time zone`: https://github.com/informatyzacja-sspwr-projekty/SWv2/issues/10 - closes_on_date text not null, + closes_on_date timestamptz not null, -- Czy sw-mailsender wysyła maile z `sending_out_to`? mailing_active boolean default false not null, @@ -82,6 +81,7 @@ create table polls( closed boolean default false not null, -- Jeżeli wartość nie jest NULL, o danej godzinie głosowanie zostanie rozpocząte + -- Przy Tworzeniu wyborów domyślnie jest NULL -- (między innymi ustawiając `mailing_active` na true) - planned_start_sending timestamp with time zone + planned_start_sending timestamptz );