Skip to content

Commit

Permalink
Merge pull request #206 from gcivil-nyu-org/develop
Browse files Browse the repository at this point in the history
Https, video, community
  • Loading branch information
samkitshah18 committed Apr 9, 2024
2 parents aa63be2 + 4e73aa5 commit 489f2ec
Show file tree
Hide file tree
Showing 54 changed files with 2,044 additions and 228 deletions.
13 changes: 13 additions & 0 deletions .ebextensions/django.config → .ebextensions/django.config.dev
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ option_settings:
aws:elasticbeanstalk:environment:process:websocket:
Port: '5000'
Protocol: HTTP
aws:elbv2:listener:443:
DefaultProcess: http
ListenerEnabled: 'true'
Protocol: HTTPS
SSLCertificateArns: arn:aws:acm:us-west-2:381492260474:certificate/2040d073-cbae-4329-a941-41e06674e5a2
Rules: wss
aws:elbv2:listenerrule:wss:
PathPatterns: /ws/*
Process: websocket
Priority: 2
aws:elasticbeanstalk:environment:process:https:
Port: '443'
Protocol: HTTPS

container_commands:
00_make_executable:
Expand Down
114 changes: 114 additions & 0 deletions .ebextensions/django.config.master
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
option_settings:
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "TutorNYU.settings"
PYTHONPATH: "/var/app/current:$PYTHONPATH"
DJANGO_ASGI_APPLICATION: "TutorNYU.asgi:application"
DAPHNE_PORT: "5000"
aws:elasticbeanstalk:container:python:
WSGIPath: "TutorNYU.wsgi:application"
aws:elbv2:listener:80:
DefaultProcess: http
ListenerEnabled: 'true'
Protocol: HTTP
Rules: ws
aws:elbv2:listenerrule:ws:
PathPatterns: /ws/*
Process: websocket
Priority: 1
aws:elasticbeanstalk:environment:process:http:
Port: '80'
Protocol: HTTP
aws:elasticbeanstalk:environment:process:websocket:
Port: '5000'
Protocol: HTTP
aws:elbv2:listener:443:
DefaultProcess: http
ListenerEnabled: 'true'
Protocol: HTTPS
SSLCertificateArns: arn:aws:acm:us-west-2:381492260474:certificate/65f910d1-d446-4350-a9ce-5a9a65853cd5
Rules: wss
aws:elbv2:listenerrule:wss:
PathPatterns: /ws/*
Process: websocket
Priority: 2
aws:elasticbeanstalk:environment:process:https:
Port: '443'
Protocol: HTTPS

container_commands:
00_make_executable:
command: "chmod +x /opt/elasticbeanstalk/hooks/appdeploy/pre/50start_supervisord.sh"

01_start_supervisord:
command: "/opt/elasticbeanstalk/hooks/appdeploy/pre/50start_supervisord.sh"
leader_only: true

02_start_daphne:
command: "supervisorctl -c /opt/python/etc/supervisord.conf start daphne >> /var/log/daphne_supervisor_start.log 2>&1"
leader_only: true

files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/50start_supervisord.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash

SUPERVISORD="/var/app/venv/staging-LQM1lest/bin/supervisord"
SUPERVISORCTL="/var/app/venv/staging-LQM1lest/bin/supervisorctl"

CONFIG="/opt/python/etc/supervisord.conf"

if pgrep -f $SUPERVISORD > /dev/null; then
echo "Supervisord is running, attempting to stop it."
$SUPERVISORCTL -c $CONFIG shutdown
sleep 5

if pgrep -f $SUPERVISORD > /dev/null; then
echo "Supervisord did not shut down gracefully; forcing shutdown."
pkill -f $SUPERVISORD
sleep 2
fi
fi
echo "Starting supervisord..."
$SUPERVISORD -c $CONFIG



"/opt/python/etc/supervisord.conf":
mode: "000644"
owner: root
group: root
content: |
[supervisord]
nodaemon=false

[unix_http_server]
file=/tmp/supervisor.sock

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[program:daphne]
command=/var/app/venv/staging-LQM1lest/bin/daphne -u /tmp/daphne.sock -b 0.0.0.0 -p 5000 TutorNYU.asgi:application
directory=/var/app/current
autostart=true
autorestart=true
stdout_logfile=/var/log/daphne.out.log
stderr_logfile=/var/log/daphne.err.log
environment=DJANGO_SETTINGS_MODULE="TutorNYU.settings",PYTHONPATH="/var/app/current:$PYTHONPATH"

[program:gunicorn]
command=/var/app/venv/staging-LQM1lest/bin/gunicorn TutorNYU.wsgi:application --bind 0.0.0.0:8000
directory=/var/app/current
autostart=true
autorestart=true
stdout_logfile=/var/log/gunicorn.out.log
stderr_logfile=/var/log/gunicorn.err.log
environment=DJANGO_SETTINGS_MODULE="TutorNYU.settings",PYTHONPATH="/var/app/current:$PYTHONPATH"
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ script:
- black --check .
- flake8
- coverage run manage.py test --noinput

after_script:
- coveralls


before_deploy:
- if [ "$TRAVIS_BRANCH" = "master" ]; then cp .ebextensions/django.config.master .ebextensions/django.config; fi
- if [ "$TRAVIS_BRANCH" = "develop" ]; then cp .ebextensions/django.config.dev .ebextensions/django.config; fi
- if [ "$TRAVIS_BRANCH" = "develop" ]; then cat .ebextensions/django.config; fi
- zip -r deploy_package.zip . -x "*.git*" -x "**/__pycache__/*" -x "*.pyc" -x "venv/*"

deploy:
- provider: elasticbeanstalk
access_key_id: $access_key_id
Expand All @@ -31,6 +36,8 @@ deploy:
app: "TutorNYU-dev-branch"
env: "app-env"
bucket_name: "elasticbeanstalk-us-west-2-381492260474"
zip_file: deploy_package.zip
skip_cleanup: true
on:
branch: develop

Expand All @@ -41,5 +48,6 @@ deploy:
app: "TutorNYU-production"
env: "production-env"
bucket_name: "elasticbeanstalk-us-west-2-381492260474"
skip_cleanup: true
on:
branch: master
Empty file added Community/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions Community/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions Community/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CommunityConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "Community"
42 changes: 42 additions & 0 deletions Community/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from django import forms
from TutorRegister.models import Post, Reply


class CreatePostForm(forms.ModelForm):
class Meta:
model = Post

fields = ["title", "content", "label", "attachment"]

labels = {
"title": "Title",
"content": "Content",
"label": "Label",
"attachment": "Attachment",
}

widgets = {
"title": forms.TextInput(attrs={"class": "form-control"}),
"content": forms.Textarea(attrs={"class": "form-control"}),
"label": forms.RadioSelect(attrs={"class": "form-check-input"}),
"attachment": forms.FileInput(attrs={"class": "form-control-file"}),
}

def __init__(self, *args, **kwargs):
super(CreatePostForm, self).__init__(*args, **kwargs)

self.fields["label"].choices = [
("resource", "Resource"),
("question", "Question"),
]


class CreateReplyForm(forms.ModelForm):
class Meta:
model = Reply

fields = ["content"]

labels = {"content": "Content"}

widgets = {"content": forms.Textarea(attrs={"class": "form-control"})}
Empty file.
3 changes: 3 additions & 0 deletions Community/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
122 changes: 122 additions & 0 deletions Community/templates/create_post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{% extends 'Dashboard/base_student.html' %}

{% block title %}Create New Post{% endblock %}

{% block content %}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create Post</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.btn-purple {
color: #800080;
background-color: transparent;
border-color: #800080;
}
.btn-purple.clicked {
color: #fff;
background-color: #800080;
border-color: #800080;
}
.btn-purple:hover {
color: #fff;
background-color: #800080;
border-color: #800080;
}
.card-header {
background: none; /* Remove background */
border-bottom: none; /* Remove border */
}
.btn-purple:not(.clicked):hover {
background-color: #800080;
border-color: #800080;
color: white;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="card mt-5 rounded-4 shadow">
<div class="card-header">
<h5 class="card-title" style="margin-top: 20px; margin-left: 20px;"><strong>Create a New Post</strong></h5>
</div>
<div class="card-body" style="margin-left: 20px; margin-right: 20px;">
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{% if form.errors %}
<div class="alert alert-danger" role="alert">
Please correct the errors below:
<ul>
{% for error in form.non_field_errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<div class="mb-3">
<label class="form-label">Label:</label>
<div class="btn-group" role="group" aria-label="User Type">
{% for value, label in form.label.field.choices %}
<input type="radio" class="btn-check" name="label" id="label_{{ forloop.counter }}" value="{{ value }}" autocomplete="off">
<label class="btn btn-purple" style="margin-right: 5px;" onclick="selectLabel(this)" for="label_{{ forloop.counter }}">{{ label }}</label>
{% endfor %}
</div>
</div>
<div class="mb-3">
<label for="title" class="form-label">Title</label>
{{ form.title }}
{% for error in form.title.errors %}
<div class="text-danger">{{ error }}</div>
{% endfor %}
</div>
<div class="mb-3">
<label for="content" class="form-label">Content</label>
{{ form.content }}
{% for error in form.content.errors %}
<div class="text-danger">{{ error }}</div>
{% endfor %}
</div>
<div class="mb-3">
<label for="attachment" class="form-label">Attach File (optional)</label>
<input class="form-control" type="file" id="attachment" name="attachment">
{% for error in form.attachment.errors %}
<div class="text-danger">{{ error }}</div>
{% endfor %}
</div>
<div class="d-flex justify-content-center">
<button type="submit" class="btn btn-primary btn-purple" style="background-color: #600E90; color: white; border-color: #600E90; margin-bottom: 20px; margin-left: 20px">Post</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>

<!-- Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
<script>
function selectLabel(button) {
// Remove 'clicked' class from all buttons
document.querySelectorAll('.btn-purple').forEach(btn => {
btn.classList.remove('clicked');
btn.style.backgroundColor = "white";
btn.style.color='#600E90';
});
// Add 'clicked' class to selected button
button.classList.add('clicked');
button.style.backgroundColor='#600E90';
button.style.color = 'white';
}
</script>
</body>
</html>

{% endblock %}

0 comments on commit 489f2ec

Please sign in to comment.