Skip to content

Commit

Permalink
Fixed administration bugs, reshuffling, graphing.
Browse files Browse the repository at this point in the history
Added small test for an utility function.
  • Loading branch information
TaaviE committed Jan 8, 2019
1 parent 2931543 commit 5099a50
Show file tree
Hide file tree
Showing 15 changed files with 364 additions and 267 deletions.
2 changes: 2 additions & 0 deletions background.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Background scheduling tasks, TODO: BROKEN FOR NOW
import datetime

from main import mail
from models.wishlist_model import NoteState
from utility import *
Expand Down
104 changes: 86 additions & 18 deletions init_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ create table groups
description integer
);


create table families
(
id serial not null
Expand All @@ -19,6 +20,8 @@ create table families
creation timestamp default now() not null
);



create unique index families_id_uindex
on families (id);

Expand All @@ -33,6 +36,8 @@ create table names_genitive
genitive varchar(255) not null
);

alter table names_genitive owner to jolod;

create unique index names_genitive_name_uindex
on names_genitive (name);

Expand All @@ -45,6 +50,8 @@ create table role
description varchar(255)
);



create unique index role_id_uindex
on role (id);

Expand All @@ -56,11 +63,11 @@ create table "user"
id serial not null
constraint user_id_pk
primary key,
email varchar(255),
password varchar(255),
email varchar(255) not null,
password varchar(255) not null,
confirmed_at timestamp,
active boolean,
username varchar(255),
username varchar(255) not null,
last_login_at timestamp,
current_login_at timestamp,
last_login_ip varchar(255),
Expand All @@ -69,43 +76,57 @@ create table "user"
last_activity_at timestamp,
last_activity_ip varchar(255),
language varchar(5) default 'en'::character varying not null,
first_seen timestamp default now() not null
first_seen timestamp default now() not null,
birthday timestamp
);



create table roles_users
(
id integer
id integer not null
constraint roles_users_id_fkey
references "user",
role_id integer
role_id integer not null
constraint roles_users_role_id_fkey
references role
);

alter table roles_users owner to jolod;

create table shuffles
(
giver integer not null
constraint shuffles_pkey
primary key
constraint shuffles_giver_fkey
references "user",
getter integer not null
constraint shuffles_getter_fkey
references "user",
year timestamp not null,
"group" integer not null
constraint shuffles_groups_id_fk
references groups
references groups,
year integer not null,
id serial not null
constraint shuffles_pk
primary key
);



create index shuffles_group_index
on shuffles ("group");

create index shuffles_group_giver_index
on shuffles ("group", giver);
create index shuffles_year_index
on shuffles (year);

create unique index shuffles_giver_getter_group_year_uindex
on shuffles (giver, getter, "group", year);

create unique index shuffles_id_uindex
on shuffles (id);

create unique index shuffles_giver_group_getter_year_uindex
on shuffles (giver, "group", getter, year);
create unique index shuffles_giver_year_uindex
on shuffles (giver, year);

create unique index user_email_uindex
on "user" (email);
Expand All @@ -126,11 +147,14 @@ create table users_families_admins
family_id integer not null
constraint users_families_admins_family_id_fkey
references families,
admin boolean not null
admin boolean not null,
confirmed boolean default false not null
);

comment on table users_families_admins is 'Contains all user-family relationships and if the user is the admin of that family';

alter table users_families_admins owner to jolod;

create table users_groups_admins
(
user_id integer not null
Expand All @@ -141,9 +165,12 @@ create table users_groups_admins
group_id integer not null
constraint users_groups_admins_group_id_fkey
references groups,
admin boolean not null
admin boolean not null,
confirmed boolean default false not null
);

alter table users_groups_admins owner to jolod;

create table wishlists
(
user_id integer not null
Expand All @@ -156,9 +183,12 @@ create table wishlists
references "user",
id bigserial not null
constraint wishlists_note_id_pk
primary key
primary key,
received timestamp
);



create unique index wishlists_note_id_uindex
on wishlists (id);

Expand All @@ -171,9 +201,12 @@ create table families_groups
references families,
group_id integer not null
constraint families_groups_admins_groups_id_fk
references groups
references groups,
confirmed boolean default false not null
);

alter table families_groups owner to jolod;

create index families_groups_admins_family_id_index
on families_groups (family_id);

Expand All @@ -194,6 +227,8 @@ create table user_connection
provider varchar(255)
);

alter table user_connection owner to jolod;

create unique index user_connection_id_uindex
on user_connection (id);

Expand All @@ -208,6 +243,39 @@ create table reminders
type varchar(4)
);



create index reminders_group_index
on reminders ("group");

create table subscription_types
(
id serial not null
constraint subscription_types_pk
primary key,
name varchar(255)
);

alter table subscription_types owner to jolod;

create table subscriptions
(
user_id integer not null
constraint subscriptions_pk
primary key
constraint subscriptions_user_id_fk
references "user",
type integer not null
constraint subscriptions_subscription_types_id_fk
references subscription_types,
until timestamp not null
);



create unique index subscriptions_user_id_type_uindex
on subscriptions (user_id, type);

create unique index subscription_types_id_uindex
on subscription_types (id);

4 changes: 2 additions & 2 deletions models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
Contains all the models used in SecretSantaGraph
"""
import models.familiy_user_admin_model
import models.family_model
import models.groups_model
import models.shuffles_model
import models.user_group_admin_model
import models.users_families_admins
import models.users_groups_admins_model
import models.users_model
import models.wishlist_model
6 changes: 4 additions & 2 deletions models/shuffles_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

class Shuffle(db.Model):
__tablename__ = "shuffles"
giver = db.Column(db.Integer(), db.ForeignKey(User.id), primary_key=True, nullable=False)

id = db.Column(db.BigInteger, primary_key=True, nullable=False, autoincrement=True)
giver = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=False)
getter = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=False)
year = db.Column(db.DateTime(), nullable=False, default=datetime.now())
year = db.Column(db.Integer(), default=datetime.now().year, nullable=False)
group = db.Column(db.Integer(), db.ForeignKey(Group.id))

def __str__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class UserFamilyAdmin(db.Model):
user_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True, unique=True, nullable=False)
family_id = db.Column(db.Integer, db.ForeignKey("families.id"), nullable=False)
admin = db.Column(db.Boolean, nullable=False)
confirmed = db.Column(db.Boolean, nullable=False, default=False)

def __init__(self, user_id, family_id, admin):
self.user_id = user_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class UserGroupAdmin(db.Model):
user_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True, unique=True, nullable=False)
group_id = db.Column(db.Integer, db.ForeignKey("groups.id"), nullable=False)
admin = db.Column(db.Boolean, nullable=False)
confirmed = db.Column(db.Boolean, nullable=False, default=False)

def __init__(self, user_id, group_id, admin):
self.user_id = user_id
Expand Down
4 changes: 2 additions & 2 deletions secretsanta/connectiongraph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import secretsanta.connection as SantaConnection
import secretsanta.connection as santaconnection


class ConnectionGraph:
Expand Down Expand Up @@ -56,4 +56,4 @@ def make_weighted_conn(self, source, target, year):
if vertice in self.members_to_families and source_family == self.members_to_families[vertice]:
weight += len(self.vertices[target])

return SantaConnection.Connection(source, target, year, weight)
return santaconnection.Connection(source, target, year, weight)
23 changes: 11 additions & 12 deletions secretsanta/secretsantagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def random_connection(self,
target_queue,
year):

source = len(source_queue) - 1
destination = len(target_queue) - 1
source_index = len(source_queue) - 1
target_index = len(target_queue) - 1

change_sources = True

while source >= 0 and destination >= 0:
source = source_queue[source]
target = target_queue[destination]
while source_index >= 0 and target_index >= 0:
source = source_queue[source_index]
target = target_queue[target_index]

conn = self.old_connections.make_weighted_conn(
source,
Expand All @@ -43,23 +43,22 @@ def random_connection(self,
)

if self.connection_is_valid(conn, connections):

if source < len(source_queue) - 1:
source_queue[source] = source_queue.pop()
if source_index < len(source_queue) - 1:
source_queue[source_index] = source_queue.pop()
else:
source_queue.pop()

if destination < len(target_queue) - 1:
target_queue[destination] = target_queue.pop()
if target_index < len(target_queue) - 1:
target_queue[target_index] = target_queue.pop()
else:
target_queue.pop()

return conn

if change_sources:
source -= 1
source_index -= 1
else:
destination -= 1
target_index -= 1

change_sources = not change_sources

Expand Down
11 changes: 7 additions & 4 deletions templates/editfam.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

{% block content %}
<noscript>{{ _("Your browser does not support JavaScript, certain functionality might be limited") }}</noscript>
<table class="mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--2dp mdl-shadow--2dp mdl-color--white mdl-cell mdl-cell--6-col-tablet mdl-cell--8-col-desktop mdl-cell--4-col-phone mdl-cell--6-col">
<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp mdl-shadow--2dp mdl-color--white mdl-cell mdl-cell--6-col-tablet mdl-cell--8-col-desktop mdl-cell--4-col-phone mdl-cell--6-col">
<tbody>
<tr>
<th>{{ _("Member") }}</th>
Expand Down Expand Up @@ -44,10 +44,13 @@
</td>
{% endif %}

{% if member[2] %}
{% if admin %}
<td>
<a class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent"
href="./removefromfam?id={{ member[1] }}">{{ _("Remove") }}</a>
<form method="post" action="./editfam">
<input id="action" name="next" type="hidden" value="DELETE">
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect"
name="id" type="submit" value="{{ member[1] }}">{{ _("Remove") }}</button>
</form>
</td>
{% endif %}
</tr>
Expand Down
Loading

0 comments on commit 5099a50

Please sign in to comment.