Skip to content
This repository was archived by the owner on Nov 23, 2024. It is now read-only.
Closed
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
15 changes: 14 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ $msg_up = <<MSG_UP
System Wyborczy v2

- Panel administratora:
http://localhost:8080/admin
http://localhost:8080/admin

(Default)
Login:
admin
Pass:
haker7

- Konsola maszyny wirtualnej:
$ vagrant ssh
Expand All @@ -19,6 +25,13 @@ System Wyborczy v2

Panel administratora:
http://localhost:8080/admin

(Default)
Login:
admin
Pass:
haker7


Logi:
$ sw-logs
Expand Down
36 changes: 23 additions & 13 deletions sw-admin/sw_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
login_manager = LoginManager()
login_manager.init_app(app)

#machine Timezone
machTz = datetime.datetime.now().astimezone().tzinfo

# use dicts and lists as json in postgres
import psycopg2.extras
psycopg2.extensions.register_adapter(dict, psycopg2.extras.Json)
Expand Down Expand Up @@ -233,7 +236,7 @@ def admin_copypoll():
name, options, choice_type, possible_recipients, sending_out_to, closes_on_date, mail_template, max_choices, description = row
return render_template('copypoll.html', poll_id=poll_id, name=name, options=options, choice_type=choice_type,
possible_recipients=possible_recipients, sending_out_to_amount=0,
closes_on_date=closes_on_date, mail_template=mail_template, should_disable=False,
closes_on_date=closes_on_date.strftime("%Y-%m-%d %H:%M"), mail_template=mail_template, should_disable=False,
max_choices=max_choices, description=description)

@app.route('/admin/editpoll', methods=['GET'])
Expand All @@ -249,7 +252,7 @@ def admin_editpoll():
should_disable = "disabled" if sending_out_to_amount > 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'])
Expand Down Expand Up @@ -454,21 +457,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
Expand Down
5 changes: 2 additions & 3 deletions sw-database/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -83,5 +82,5 @@ create table polls(

-- Jeżeli wartość nie jest NULL, o danej godzinie głosowanie zostanie rozpocząte
-- (między innymi ustawiając `mailing_active` na true)
planned_start_sending timestamp with time zone
planned_start_sending timestamptz not null
);