Skip to content

Commit fc79a46

Browse files
author
Michael Zhang
committed
Some more stuff
1 parent 18ccdcc commit fc79a46

16 files changed

+150
-109
lines changed

cal.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22

33
from flask import Flask
4-
from flask_oauthlib.provider import OAuth2Provider
54

65
import config
76
import views

forms.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from datetime import datetime
2-
31
from flask_wtf import Form
42
from sqlalchemy import func
53
from wtforms import ValidationError
@@ -32,8 +30,10 @@ def validate_password(self, field):
3230

3331
class RegisterForm(Form):
3432
email = StringField('Email', validators=[InputRequired()])
35-
username = StringField('Username', validators=[InputRequired(), Length(min=4, max=16, message='Username must be between 4 and 16 characters long.')])
36-
password = PasswordField('Password', validators=[InputRequired(), Length(min=8, max=56, message='Password must be between 8 and 56 characters long.')])
33+
username = StringField('Username', validators=[InputRequired(), Length(min=4, max=16,
34+
message='Username must be between 4 and 16 characters long.')])
35+
password = PasswordField('Password', validators=[InputRequired(), Length(min=8, max=56,
36+
message='Password must be between 8 and 56 characters long.')])
3737

3838
def validate_email(self, field):
3939
if not util.validate_email_format(field.data):
@@ -51,9 +51,11 @@ def validate_username(self, field):
5151
class EventForm(Form):
5252
title = StringField('Title', validators=[InputRequired(), Length(max=256)])
5353
start_time = IntegerField('Start Time',
54-
validators=[InputRequired(), NumberRange(min=0, max=2147483647, message='Start time must be between 0 and 2147483647!')])
54+
validators=[InputRequired(), NumberRange(min=0, max=2147483647,
55+
message='Start time must be between 0 and 2147483647!')])
5556
duration = FloatField('Duration (hours)',
56-
validators=[InputRequired(), NumberRange(min=0, max=2147483647, message='Duration must be between 0 and 2147483647!')])
57+
validators=[InputRequired(), NumberRange(min=0, max=2147483647,
58+
message='Duration must be between 0 and 2147483647!')])
5759
description = StringField('Description', widget=TextArea(), validators=[InputRequired(), Length(max=1024)])
5860
link = StringField('Link', validators=[InputRequired(), Length(max=256)])
5961

migrations/versions/10d5b977cbe4_.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@
1111
down_revision = '4716a9303c39'
1212

1313
from alembic import op
14-
import sqlalchemy as sa
1514

1615

1716
def upgrade():
18-
### commands auto generated by Alembic - please adjust! ###
17+
### commands auto generated by Alembic - please adjust! ###
1918
op.create_index(op.f('ix_events_start_time'), 'events', ['start_time'], unique=False)
2019
### end Alembic commands ###
2120

2221

2322
def downgrade():
24-
### commands auto generated by Alembic - please adjust! ###
23+
### commands auto generated by Alembic - please adjust! ###
2524
op.drop_index(op.f('ix_events_start_time'), table_name='events')
2625
### end Alembic commands ###

migrations/versions/4716a9303c39_.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@
1111
down_revision = '06cfdde7ecc1'
1212

1313
from alembic import op
14-
import sqlalchemy as sa
1514

1615

1716
def upgrade():
18-
### commands auto generated by Alembic - please adjust! ###
17+
### commands auto generated by Alembic - please adjust! ###
1918
op.drop_index('ix_events_start_time', table_name='events')
2019
### end Alembic commands ###
2120

2221

2322
def downgrade():
24-
### commands auto generated by Alembic - please adjust! ###
23+
### commands auto generated by Alembic - please adjust! ###
2524
op.create_index('ix_events_start_time', 'events', ['start_time'], unique=False)
2625
### end Alembic commands ###

migrations/versions/8a9998406bc7_.py

+28-28
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
revision = '8a9998406bc7'
1111
down_revision = 'daf5b5301c75'
1212

13-
from alembic import op
1413
import sqlalchemy as sa
14+
from alembic import op
1515

1616

1717
def upgrade():
18-
### commands auto generated by Alembic - please adjust! ###
18+
### commands auto generated by Alembic - please adjust! ###
1919
op.add_column(u'events', sa.Column('_default_scopes', sa.Text(), nullable=True))
2020
op.add_column(u'events', sa.Column('_redirect_uris', sa.Text(), nullable=True))
2121
op.add_column(u'events', sa.Column('client_id', sa.String(length=40), nullable=True))
@@ -24,38 +24,38 @@ def upgrade():
2424
op.create_index(op.f('ix_events_client_secret'), 'events', ['client_secret'], unique=True)
2525
op.create_unique_constraint(None, 'events', ['client_id'])
2626
op.create_table('token',
27-
sa.Column('id', sa.Integer(), nullable=False),
28-
sa.Column('client_id', sa.String(length=40), nullable=False),
29-
sa.Column('user_id', sa.Integer(), nullable=True),
30-
sa.Column('token_type', sa.String(length=40), nullable=True),
31-
sa.Column('access_token', sa.String(length=255), nullable=True),
32-
sa.Column('refresh_token', sa.String(length=255), nullable=True),
33-
sa.Column('expires', sa.DateTime(), nullable=True),
34-
sa.Column('_scopes', sa.Text(), nullable=True),
35-
sa.ForeignKeyConstraint(['client_id'], ['events.client_id'], ),
36-
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
37-
sa.PrimaryKeyConstraint('id'),
38-
sa.UniqueConstraint('access_token'),
39-
sa.UniqueConstraint('refresh_token')
40-
)
27+
sa.Column('id', sa.Integer(), nullable=False),
28+
sa.Column('client_id', sa.String(length=40), nullable=False),
29+
sa.Column('user_id', sa.Integer(), nullable=True),
30+
sa.Column('token_type', sa.String(length=40), nullable=True),
31+
sa.Column('access_token', sa.String(length=255), nullable=True),
32+
sa.Column('refresh_token', sa.String(length=255), nullable=True),
33+
sa.Column('expires', sa.DateTime(), nullable=True),
34+
sa.Column('_scopes', sa.Text(), nullable=True),
35+
sa.ForeignKeyConstraint(['client_id'], ['events.client_id'], ),
36+
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
37+
sa.PrimaryKeyConstraint('id'),
38+
sa.UniqueConstraint('access_token'),
39+
sa.UniqueConstraint('refresh_token')
40+
)
4141
op.create_table('grant',
42-
sa.Column('id', sa.Integer(), nullable=False),
43-
sa.Column('user_id', sa.Integer(), nullable=True),
44-
sa.Column('client_id', sa.String(length=40), nullable=False),
45-
sa.Column('code', sa.String(length=255), nullable=False),
46-
sa.Column('redirect_uri', sa.String(length=255), nullable=True),
47-
sa.Column('expires', sa.DateTime(), nullable=True),
48-
sa.Column('_scopes', sa.Text(), nullable=True),
49-
sa.ForeignKeyConstraint(['client_id'], ['events.client_id'], ),
50-
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
51-
sa.PrimaryKeyConstraint('id')
52-
)
42+
sa.Column('id', sa.Integer(), nullable=False),
43+
sa.Column('user_id', sa.Integer(), nullable=True),
44+
sa.Column('client_id', sa.String(length=40), nullable=False),
45+
sa.Column('code', sa.String(length=255), nullable=False),
46+
sa.Column('redirect_uri', sa.String(length=255), nullable=True),
47+
sa.Column('expires', sa.DateTime(), nullable=True),
48+
sa.Column('_scopes', sa.Text(), nullable=True),
49+
sa.ForeignKeyConstraint(['client_id'], ['events.client_id'], ),
50+
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
51+
sa.PrimaryKeyConstraint('id')
52+
)
5353
op.create_index(op.f('ix_grant_code'), 'grant', ['code'], unique=False)
5454
### end Alembic commands ###
5555

5656

5757
def downgrade():
58-
### commands auto generated by Alembic - please adjust! ###
58+
### commands auto generated by Alembic - please adjust! ###
5959
op.drop_constraint(None, 'events', type_='unique')
6060
op.drop_index(op.f('ix_events_client_secret'), table_name='events')
6161
op.drop_column(u'events', 'is_confidential')

migrations/versions/daf5b5301c75_.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
revision = 'daf5b5301c75'
1111
down_revision = 'f79ba2365689'
1212

13-
from alembic import op
1413
import sqlalchemy as sa
14+
from alembic import op
1515

1616

1717
def upgrade():
18-
### commands auto generated by Alembic - please adjust! ###
18+
### commands auto generated by Alembic - please adjust! ###
1919
op.add_column('eventvotes', sa.Column('user_id', sa.Integer(), nullable=True))
2020
op.create_unique_constraint('eventvote_user_event_uc', 'eventvotes', ['user_id', 'event_id'])
2121
op.create_foreign_key('eventvote_user_id_fk', 'eventvotes', 'users', ['user_id'], ['id'])
2222
### end Alembic commands ###
2323

2424

2525
def downgrade():
26-
### commands auto generated by Alembic - please adjust! ###
26+
### commands auto generated by Alembic - please adjust! ###
2727
op.drop_constraint('eventvote_user_id_fk', 'eventvotes', type_='foreignkey')
2828
op.drop_constraint('eventvote_user_event_uc', 'eventvotes', type_='unique')
2929
op.drop_column('eventvotes', 'user_id')

migrations/versions/f79ba2365689_.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
revision = 'f79ba2365689'
1111
down_revision = '10d5b977cbe4'
1212

13-
from alembic import op
1413
import sqlalchemy as sa
14+
from alembic import op
1515

1616

1717
def upgrade():
18-
### commands auto generated by Alembic - please adjust! ###
18+
### commands auto generated by Alembic - please adjust! ###
1919
op.add_column('events', sa.Column('removed', sa.Boolean(), nullable=True))
2020
### end Alembic commands ###
2121

2222

2323
def downgrade():
24-
### commands auto generated by Alembic - please adjust! ###
24+
### commands auto generated by Alembic - please adjust! ###
2525
op.drop_column('events', 'removed')
2626
### end Alembic commands ###

models.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
from datetime import datetime, timedelta
2+
13
from flask_login import current_user, LoginManager
24
from flask_oauthlib.provider import OAuth2Provider
35
from flask_sqlalchemy import SQLAlchemy
4-
56
from sqlalchemy import UniqueConstraint
6-
from sqlalchemy.orm import backref
77
from sqlalchemy.ext.hybrid import hybrid_property
8+
from sqlalchemy.orm import backref
89

9-
from datetime import datetime, timedelta
1010
import util
1111

1212
db = SQLAlchemy()
@@ -97,9 +97,9 @@ class Event(db.Model):
9797
removed = db.Column(db.Boolean, default=False)
9898

9999
# OAuth2 stuff
100-
client_id = db.Column(db.String(40), unique=True)
101-
client_secret = db.Column(db.String(55), unique=True, index=True, nullable=False)
102-
is_confidential = db.Column(db.Boolean)
100+
client_id = db.Column(db.String(40), unique=True, default=util.generate_string(16))
101+
client_secret = db.Column(db.String(55), unique=True, index=True, nullable=False, default=util.generate_string(32))
102+
is_confidential = db.Column(db.Boolean, default=True)
103103
_redirect_uris = db.Column(db.Text)
104104
_default_scopes = db.Column(db.Text)
105105

@@ -195,6 +195,7 @@ def scopes(self):
195195
return self._scopes.split()
196196
return []
197197

198+
198199
def get_current_user():
199200
if current_user:
200201
return current_user
@@ -210,6 +211,7 @@ def load_client(client_id):
210211
def load_grant(client_id, code):
211212
return Grant.query.filter_by(client_id=client_id, code=code).first()
212213

214+
213215
@oauth.grantsetter
214216
def save_grant(client_id, code, request, *args, **kwargs):
215217
expires = datetime.utcnow() + timedelta(seconds=100)
@@ -256,4 +258,4 @@ def save_token(token, request, *args, **kwargs):
256258
)
257259
db.session.add(tok)
258260
db.session.commit()
259-
return tok
261+
return tok

static/js/timeline.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ $(document).ready(function () {
8585
stopTime = startTime + 30 * 24 * 60 * 60 * 1000;
8686

8787
$.get("/events/list/json", function (data) {
88-
data = JSON.parse(data).filter(function(item) { return item.approved == true && item.endTime > now; });
88+
data = JSON.parse(data).filter(function (item) {
89+
return item.approved == true && item.endTime > now;
90+
});
8991

9092
var daysBetween = 1;
9193
var time = new Date(startTime);

templates/base/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ <h4 class="panel-title">Upcoming Events
2525
</div>
2626
<table class="table table-hover table-striped">
2727
<thead>
28-
<th>Name</th>
29-
<th>Date</th>
28+
<th>Name</th>
29+
<th>Date</th>
3030
</head>
3131
<tbody id="upcoming_ctfs"></tbody>
3232
</table>

templates/events/list.html

+47-43
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
</li>
1313
{% if current_user.admin %}
1414
<li role="presentation"{% if tab == "unapproved" %} class="active"{% endif %}>
15-
<a href="{{ url_for('events.events_unapproved') }}" aria-controls="settings" role="tab">Unapproved</a>
15+
<a href="{{ url_for('events.events_unapproved') }}" aria-controls="settings"
16+
role="tab">Unapproved</a>
1617
</li>
1718
{% endif %}
1819
<li role="presentation"{% if tab == "upcoming" %} class="active"{% endif %}>
@@ -29,55 +30,58 @@
2930
</ul>
3031
<table class="table table-hover table-striped">
3132
<thead>
32-
<th>Name</th>
33-
<th>Description</th>
34-
<th>Date</th>
35-
<th>Duration</th>
36-
<th>Website</th>
37-
{% if enabled_actions %}
38-
<th>Actions</th>
39-
{% endif %}
33+
<th>Name</th>
34+
<th>Description</th>
35+
<th>Date</th>
36+
<th>Duration</th>
37+
<th>Website</th>
38+
{% if enabled_actions %}
39+
<th>Actions</th>
40+
{% endif %}
4041
</thead>
4142
<tbody>
42-
{% for event in events %}
43-
<tr id="event_{{ event.id }}">
44-
<td><a href="{{ url_for('events.events_detail', event_id=event.id) }}">{{ event.title }}</a></td>
45-
<td>{{ event.description }}</td>
46-
<td><time class="timeago" datetime="{{ event.start_time_format }}">{{ event.start_time_format }}</time></td>
47-
<td>{{ event.duration|duration('hour') }}</td>
48-
<td><a href="{{ event.link }}" target="_blank">Website</a></td>
49-
{% if enabled_actions %}
50-
<td>
51-
<form>
52-
{% if 'approve' in enabled_actions %}
53-
<button id="approve_{{ event.id }}" class="btn btn-xs btn-success" type="submit"
54-
formaction="{{ url_for('events.events_approve', event_id=event.id) }}"
55-
formmethod="post">Approve
56-
</button>
57-
{% endif %}
58-
{% if 'manage' in enabled_actions %}
59-
<button id="approve_{{ event.id }}" class="btn btn-xs btn-primary" type="submit"
60-
formaction="{{ url_for('events.events_manage', event_id=event.id) }}"
61-
formmethod="get">Manage
62-
</button>
63-
{% endif %}
64-
{% if 'remove' in enabled_actions %}
65-
<button id="remove_{{ event.id }}" class="btn btn-xs btn-danger" type="submit"
66-
formaction="{{ url_for('events.events_remove', event_id=event.id) }}"
67-
formmethod="post">Delete
68-
</button>
69-
{% endif %}
70-
</form>
71-
</td>
72-
{% endif %}
73-
</tr>
74-
{% endfor %}
43+
{% for event in events %}
44+
<tr id="event_{{ event.id }}">
45+
<td><a href="{{ url_for('events.events_detail', event_id=event.id) }}">{{ event.title }}</a></td>
46+
<td>{{ event.description }}</td>
47+
<td>
48+
<time class="timeago"
49+
datetime="{{ event.start_time_format }}">{{ event.start_time_format }}</time>
50+
</td>
51+
<td>{{ event.duration|duration('hour') }}</td>
52+
<td><a href="{{ event.link }}" target="_blank">Website</a></td>
53+
{% if enabled_actions %}
54+
<td>
55+
<form>
56+
{% if 'approve' in enabled_actions %}
57+
<button id="approve_{{ event.id }}" class="btn btn-xs btn-success" type="submit"
58+
formaction="{{ url_for('events.events_approve', event_id=event.id) }}"
59+
formmethod="post">Approve
60+
</button>
61+
{% endif %}
62+
{% if 'manage' in enabled_actions %}
63+
<button id="approve_{{ event.id }}" class="btn btn-xs btn-primary" type="submit"
64+
formaction="{{ url_for('events.events_manage', event_id=event.id) }}"
65+
formmethod="get">Manage
66+
</button>
67+
{% endif %}
68+
{% if 'remove' in enabled_actions %}
69+
<button id="remove_{{ event.id }}" class="btn btn-xs btn-danger" type="submit"
70+
formaction="{{ url_for('events.events_remove', event_id=event.id) }}"
71+
formmethod="post">Delete
72+
</button>
73+
{% endif %}
74+
</form>
75+
</td>
76+
{% endif %}
77+
</tr>
78+
{% endfor %}
7579
</tbody>
7680
</table>
7781
</div>
7882

7983
<script type="text/javascript">
80-
$(document).ready(function() {
84+
$(document).ready(function () {
8185
$.timeago.settings.allowFuture = true;
8286
$('.timeago').timeago();
8387
});

0 commit comments

Comments
 (0)