Skip to content

Commit

Permalink
added black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhiren-NYU committed Oct 23, 2023
1 parent 52cc46b commit d44a344
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 108 deletions.
2 changes: 1 addition & 1 deletion CheerUp/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CheerUp.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CheerUp.settings")

application = get_asgi_application()
82 changes: 43 additions & 39 deletions CheerUp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,65 +20,69 @@
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-7a(i$_$tw(o7y2(ad4u8==68h4qln2%g&^a#6d+gz4b66j3v$#'
SECRET_KEY = "django-insecure-7a(i$_$tw(o7y2(ad4u8==68h4qln2%g&^a#6d+gz4b66j3v$#"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['seproject-cheerup-env.eba-vmpudkzi.us-west-2.elasticbeanstalk.com', 'localhost', '127.0.0.1']
ALLOWED_HOSTS = [
"seproject-cheerup-env.eba-vmpudkzi.us-west-2.elasticbeanstalk.com",
"localhost",
"127.0.0.1",
]


# Application definition

INSTALLED_APPS = [
'location.apps.LocationConfig',
'events.apps.EventsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
"location.apps.LocationConfig",
"events.apps.EventsConfig",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = 'CheerUp.urls'
ROOT_URLCONF = "CheerUp.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = 'CheerUp.wsgi.application'
WSGI_APPLICATION = "CheerUp.wsgi.application"


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}

Expand All @@ -88,26 +92,26 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'US/Pacific'
TIME_ZONE = "US/Pacific"

USE_I18N = True

Expand All @@ -117,9 +121,9 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = 'static/'
STATIC_URL = "static/"

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
6 changes: 3 additions & 3 deletions CheerUp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.urls import include, path

urlpatterns = [
path('admin/', admin.site.urls),
path('events/', include('events.urls')),
path('locations/', include('location.urls')),
path("admin/", admin.site.urls),
path("events/", include("events.urls")),
path("locations/", include("location.urls")),
]
2 changes: 1 addition & 1 deletion CheerUp/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CheerUp.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CheerUp.settings")

application = get_wsgi_application()
4 changes: 2 additions & 2 deletions events/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class EventsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'events'
default_auto_field = "django.db.models.BigAutoField"
name = "events"
2 changes: 1 addition & 1 deletion events/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

class EventsForm(forms.Form):
model = Event
fields = ['event_name', 'start_time', 'end_time', 'capacity']
fields = ["event_name", "start_time", "end_time", "capacity"]
32 changes: 23 additions & 9 deletions events/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,37 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
('location', '__first__'),
("location", "__first__"),
]

operations = [
migrations.CreateModel(
name='Event',
name="Event",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('event_name', models.CharField(max_length=200)),
('start_time', models.DateTimeField()),
('end_time', models.DateTimeField()),
('capacity', models.IntegerField()),
('event_location', models.ForeignKey(default=261, on_delete=django.db.models.deletion.CASCADE, to='location.location')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("event_name", models.CharField(max_length=200)),
("start_time", models.DateTimeField()),
("end_time", models.DateTimeField()),
("capacity", models.IntegerField()),
(
"event_location",
models.ForeignKey(
default=261,
on_delete=django.db.models.deletion.CASCADE,
to="location.location",
),
),
],
),
]
3 changes: 1 addition & 2 deletions events/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@


from django.db import models
from location.models import Location

# Create your models here.


Expand Down
11 changes: 5 additions & 6 deletions events/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

from . import views

app_name = 'events'
app_name = "events"
urlpatterns = [

path('', views.index, name='index'),
path('create-event', views.createEvent, name='create-event'),
path('save-event/', views.saveEvent, name='save-event'),
path('delete/<int:event_id>/', views.deleteEvent, name='delete-event'),
path("", views.index, name="index"),
path("create-event", views.createEvent, name="create-event"),
path("save-event/", views.saveEvent, name="save-event"),
path("delete/<int:event_id>/", views.deleteEvent, name="delete-event"),
]
31 changes: 16 additions & 15 deletions events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@

# Create your views here.


def index(request):
events = Event.objects.filter(is_active=True)
return render(request, 'events/events.html', {'events': events})
return render(request, "events/events.html", {"events": events})


def saveEvent(request):
event = Event()
try:
event_name = request.POST['event_name']
event_location_id = request.POST['event_location_id']
event_name = request.POST["event_name"]
event_location_id = request.POST["event_location_id"]
location_object = Location.objects.get(id=event_location_id)

start_time = request.POST['start_time']
end_time = request.POST['end_time']
capacity = request.POST['capacity']
start_time = request.POST["start_time"]
end_time = request.POST["end_time"]
capacity = request.POST["capacity"]
except (KeyError, Event.DoesNotExist):
# Redisplay the question voting form.
return redirect('events:index')
return redirect("events:index")
else:
event.event_name = event_name
event.event_location = location_object
Expand All @@ -35,27 +36,27 @@ def saveEvent(request):
# Always return an HttpResponseRedirect after successfully dealing
# with POST data. This prevents data from being posted twice if a
# user hits the Back button.
return HttpResponseRedirect(reverse('events:index'))
return HttpResponseRedirect(reverse("events:index"))


def createEvent(request):
if request.method == 'POST':
if request.method == "POST":
form = EventsForm(request.POST)
if form.is_valid():
return redirect('events:index')
return redirect("events:index")
else:
form = EventsForm()
return render(request, 'events/create-event.html', {'form': form})
return render(request, "events/create-event.html", {"form": form})


def deleteEvent(request, event_id):
event = get_object_or_404(Event, pk=event_id)
print(request)
print(event)
if request.method == 'POST':
if request.POST.get('action') == 'delete':
if request.method == "POST":
if request.POST.get("action") == "delete":
# Set is_active to False instead of deleting
event.is_active = False
event.save()
return redirect('events:index')
return redirect('events:index')
return redirect("events:index")
return redirect("events:index")
4 changes: 2 additions & 2 deletions location/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class LocationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'location'
default_auto_field = "django.db.models.BigAutoField"
name = "location"
10 changes: 5 additions & 5 deletions location/management/commands/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@


class Command(BaseCommand):
help = 'Load data from a CSV file into the database'
help = "Load data from a CSV file into the database"

def handle(self, *args, **options):
csv_file = r'C:\Users\dhire\OneDrive\Desktop\NYU\SE\Project\CheerUp\exported_data.csv' # Provide the path to your CSV file
csv_file = r"C:\Users\dhire\OneDrive\Desktop\NYU\SE\Project\CheerUp\exported_data.csv" # Provide the path to your CSV file

with open(csv_file, 'r', encoding='utf-8') as file:
with open(csv_file, "r", encoding="utf-8") as file:
csv_reader = csv.reader(file)
for row in csv_reader:
locat.objects.create(
Expand All @@ -21,6 +21,6 @@ def handle(self, *args, **options):
zipcode=row[7],
address=row[4],
url=row[5],
category=row[6]
category=row[6],
)
self.stdout.write(self.style.SUCCESS('Data loaded successfully'))
self.stdout.write(self.style.SUCCESS("Data loaded successfully"))
Loading

0 comments on commit d44a344

Please sign in to comment.