Skip to content

Commit d5f968b

Browse files
committed
S3 support added
1 parent 1aefd4c commit d5f968b

File tree

6 files changed

+62
-15
lines changed

6 files changed

+62
-15
lines changed

conditional/blueprints/major_project_submission.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import json
2+
import os
3+
24
import requests
5+
import boto3
6+
from botocore.exceptions import ClientError
37

48
from flask import Blueprint
59
from flask import request
@@ -9,6 +13,7 @@
913
from sqlalchemy import desc
1014

1115
import structlog
16+
from werkzeug.utils import secure_filename
1217

1318
from conditional.util.context_processors import get_member_name
1419

@@ -53,6 +58,25 @@ def display_major_project(user_dict=None):
5358
major_projects_len=major_projects_len,
5459
username=user_dict['username'])
5560

61+
@major_project_bp.route('/major_project/upload', methods=['POST'])
62+
@auth.oidc_auth
63+
@get_user
64+
def upload_major_project_files(user_dict=None):
65+
log = logger.new(request=request, auth_dict=user_dict)
66+
log.info('Uploading Major Project File(s)')
67+
68+
file = request.files['file']
69+
if not file:
70+
return "No file", 400
71+
72+
# Temporarily save files to a place, to be uploaded on submit
73+
74+
safe_name = secure_filename(file.filename)
75+
filename = f"/tmp/{user_dict['username']}/{safe_name}"
76+
77+
os.makedirs(os.path.dirname(filename), exist_ok=True)
78+
file.save(filename)
79+
5680

5781
@major_project_bp.route('/major_project/submit', methods=['POST'])
5882
@auth.oidc_auth
@@ -65,10 +89,19 @@ def submit_major_project(user_dict=None):
6589
name = post_data['projectName']
6690
description = post_data['projectDescription']
6791

68-
if name == "" or description == "":
92+
if name == "" or len(description.strip().split()) < 50:
6993
return jsonify({"success": False}), 400
7094
project = MajorProject(user_dict['username'], name, description)
7195

96+
# Acquire S3 Bucket instance
97+
s3 = boto3.resource("s3")
98+
bucket = s3.create_bucket(Bucket="major-project-media")
99+
# Collect all the locally cached files and put them in the bucket
100+
for file in os.listdir(f"/tmp/{user_dict['username']}"):
101+
bucket.upload_file(file, file.split("/")[-1])
102+
os.remove(file)
103+
os.rmdir(f"/tmp/{user_dict['username']}")
104+
72105
username = user_dict['username']
73106
send_slack_ping({"text":f"<!subteam^S5XENJJAH> *{get_member_name(username)}* ({username})"
74107
f" submitted their major project, *{name}*!"})

conditional/templates/major_project_submission.html

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% extends "nav.html" %}
22
{% block extraHeader %}
3-
<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>
3+
<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>
44
{% endblock %}
55
{% block title %}
66
Major Project Form
@@ -12,13 +12,13 @@ <h3 class="page-title">Major Project Form</h3>
1212
<!--TODO: put a box explaining major project -->
1313
<div class="panel panel-default">
1414
<div class="panel-body">
15-
<p class="lead">This talks about major project submission guidelines. Rubber cheese chalk and cheese
16-
pepper jack. Lancashire monterey jack say cheese roquefort stinking bishop danish fontina manchego
17-
cheese and wine. Cheeseburger cow dolcelatte feta fondue pecorino roquefort cauliflower cheese. St.
18-
agur blue cheese danish fontina emmental stilton smelly cheese bavarian bergkase fromage cheesy
19-
feet. Paneer stilton halloumi ricotta macaroni cheese stinking bishop cottage cheese camembert de
20-
normandie. Danish fontina cheese triangles squirty cheese cheese on toast camembert de
21-
normandie.</p>
15+
<p class="lead">Hi! Welcome to the Major Project submission form. We're excited to read about your major
16+
project. For us(E-Board) to best evaluate your project, please give us as much detail as possible.
17+
Don't feel pressured to write full paragraphs though, good bullet points are plenty!<br>Generally,
18+
major projects are most likely to pass when they meet three of the 4 Major Project Pillars -
19+
spending considerable time on your project, benefiting House, learning new things, and applying hard
20+
skills. And of course, after you submit, please try to talk to E-Board members (in-person or over
21+
Slack) so we are familiar with your project and can ask you questions!</p>
2222
</div>
2323
</div>
2424
<form data-module="majorProjectForm">
@@ -33,23 +33,25 @@ <h3 class="page-title">Major Project Form</h3>
3333
<div class="row">
3434
<div class="col-lg-6">
3535
<label class="form-label" for="skills-applied">Skills Applied</label>
36-
<textarea id="skills-applied" name="skills-applied" class="form-control" rows="5"
37-
placeholder="A comma-separated list of skills, similar to what you'd put on a resume."></textarea>
36+
<textarea id="skills-applied" name="skills-applied" class="form-control form-textarea"
37+
rows="5"
38+
placeholder="List what skills you used for this project (at least 2!), similar to what you'd put on a resume."></textarea>
3839
</div>
3940
<div class="col-lg-6">
4041
<label class="form-label" for="time-commitment">Time Commitment</label>
41-
<textarea id="time-commitment" name="time-commitment" class="form-control" rows="5"
42+
<textarea id="time-commitment" name="time-commitment" class="form-control form-textarea"
43+
rows="5"
4244
wrap="hard"
43-
placeholder="Tell us about how much time you spent on the project."></textarea>
45+
placeholder="We're looking for a considerable amount of time spent on your major project, we suggest ~5 hours minimum."></textarea>
4446
</div>
4547
</div>
4648
<label class="form-label" for="description">Detailed Description</label>
47-
<textarea id="description" name="description" class="form-control" rows="10"
49+
<textarea id="description" name="description" class="form-control form-textarea" rows="10"
4850
placeholder="Tell us everything! More information is better than less."></textarea>
4951
<div class="row">
5052
<div class="col-lg-5">
5153
<label class="form-label" for="links">Project Links</label>
52-
<textarea id="links" name="links" class="form-control" rows="2"
54+
<textarea id="links" name="links" class="form-control form-textarea" rows="2"
5355
placeholder="If you have links (GitHub, YouTube, etc.), put them here!"></textarea>
5456
</div>
5557
<div class="col-lg-4">

config.env.py

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
LDAP_BIND_DN = env.get("CONDITIONAL_LDAP_BIND_DN", "cn=conditional,ou=Apps,dc=csh,dc=rit,dc=edu")
2626
LDAP_BIND_PW = env.get("CONDITIONAL_LDAP_BIND_PW", "")
2727

28+
# S3 information
29+
AWS_ACCESS_KEY_ID = env.get("AWS_ACCESS_KEY_ID", "")
30+
AWS_SECRET_ACCESS_KEY = env.get("AWS_SECRET_ACCESS_KEY", "")
31+
2832
# Sentry config
2933
# Not required for local development, but if you set it, make sure the
3034
# SENTRY_ENV is 'local-development'

frontend/stylesheets/pages/_major-project.scss

+4
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
margin-bottom: 0;
77
margin-top: 1.25rem;
88
font-size: 2rem;
9+
}
10+
11+
.form-textarea {
12+
resize: vertical;
913
}

requirements.in

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
alembic~=0.9.8
22
astroid~=2.4.0
33
blinker~=1.4
4+
boto3==1.35.13
5+
botocore==1.35.13
46
click~=7.1
57
csh_ldap>=2.3.1
68
ddtrace~=1.1.4

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ blinker==1.4
2222
# via
2323
# -r requirements.in
2424
# sentry-sdk
25+
boto3==1.35.13
26+
botocore==1.35.13
2527
certifi==2022.5.18.1
2628
# via
2729
# requests

0 commit comments

Comments
 (0)