Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement see potential match and request or decline, plus reformatting #14

Merged
merged 11 commits into from
Aug 17, 2023
Merged
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.env
settings.py
__pycache__/
db.sqlite3
db.sqlite3
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
#- repo: https://github.com/thibaudcolas/curlylint
# rev: v0.13.1
# hooks:
# - id: curlylint
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.2
hooks:
- id: prettier
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# code-spark

Code Spark: A dating-style app for programmers to find project partners. And love?
12 changes: 12 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Todo

- [x] login feature
- [x] see another profile, selected randomly
- [x] design necessary data
- [x] mvp of seeing another user from the database
- [x] randomize it
- [ ] Let a user to request a match or decline
- [x] Send a form response to /match
- [x] Receive the form and create a MatchRequest object
- [x] Handle the case on the home page when there are no matches available
- [ ] Handle the case when user requests a match and a match reqeust object exists with current user as the target
4 changes: 2 additions & 2 deletions code_spark/app/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class AppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'app'
default_auto_field = "django.db.models.BigAutoField"
name = "app"
53 changes: 41 additions & 12 deletions code_spark/app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,55 @@ class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='UserAccount',
name="UserAccount",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('github_profile_name', models.CharField(max_length=255, unique=True)),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("github_profile_name", models.CharField(max_length=255, unique=True)),
],
),
migrations.CreateModel(
name='MatchRequest',
name="MatchRequest",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('match_request_status', models.IntegerField()),
('created_date', models.DateTimeField(auto_now_add=True)),
('accepted_date', models.DateTimeField(blank=True, null=True)),
('match_request_receiver', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='received_requests', to='app.useraccount')),
('match_request_sender', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sent_requests', to='app.useraccount')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("match_request_status", models.IntegerField()),
("created_date", models.DateTimeField(auto_now_add=True)),
("accepted_date", models.DateTimeField(blank=True, null=True)),
(
"match_request_receiver",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="received_requests",
to="app.useraccount",
),
),
(
"match_request_sender",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="sent_requests",
to="app.useraccount",
),
),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.2.4 on 2023-08-17 15:45

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("app", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="matchrequest",
name="match_request_receiver",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="received_requests",
to=settings.AUTH_USER_MODEL,
),
),
migrations.AlterField(
model_name="matchrequest",
name="match_request_sender",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="sent_requests",
to=settings.AUTH_USER_MODEL,
),
),
migrations.DeleteModel(
name="UserAccount",
),
]
12 changes: 9 additions & 3 deletions code_spark/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@


class MatchRequest(models.Model):
match_request_sender = models.ForeignKey(User, related_name='sent_requests', on_delete=models.CASCADE)
match_request_receiver = models.ForeignKey(User, related_name='received_requests', on_delete=models.CASCADE)
match_request_status = models.IntegerField()
match_request_sender = models.ForeignKey(
User, related_name="sent_requests", on_delete=models.CASCADE
)
match_request_receiver = models.ForeignKey(
User, related_name="received_requests", on_delete=models.CASCADE
)
match_request_status = (
models.IntegerField()
) # 1 is request_match sent, -1 is sender declined, 2 is receiver accepted, -2 is receiver declined.
created_date = models.DateTimeField(auto_now_add=True)
accepted_date = models.DateTimeField(null=True, blank=True)

Expand Down
47 changes: 23 additions & 24 deletions code_spark/app/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
{% load static %}
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="{% static 'index.css' %}" />
<title>DJANGO SOCIAL AUTH</title>
</head>
<body>
<div class="container-fluid">
<div>
<h1 class="text-white text-center">
{% block title %}
{% endblock %}
</h1>
<div class="card p-5">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</body>
</html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="{% static 'index.css' %}" />
<title>DJANGO SOCIAL AUTH</title>
</head>
<body>
<div class="container-fluid">
<div>
<h1 class="text-white text-center">{% block title %} {% endblock %}</h1>
<div class="card p-5">{% block content %} {% endblock %}</div>
</div>
</div>
</body>
</html>
37 changes: 29 additions & 8 deletions code_spark/app/templates/home.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
{% extends 'base.html' %}
{% block title %}HOME{% endblock %}
{% block content %}
<div class="row">
<div class="col-sm-12 mb-3">
<h4 class="text-center">Welcome {{ user.username }}</h4>
</div>
{% extends 'base.html' %} {% block title %}HOME{% endblock %} {% block content%}
<div class="row">
<div class="col-sm-12 mb-3">
<h4 class="text-center">Welcome {{ user.username }}</h4>
<h4 class="text-center">{{ potential_match_message }}</h4>
{% if potential_match %}
<h4 class="text-center">Would you like to request a match?</h4>
<div class="text-center">
<form action="decline" method="GET">
<button type="submit" id="noButton">No</button>
<input
type="hidden"
name="target-user"
value="{{ potential_match.username }}"
/>
</form>

<form action="request" method="GET">
<button type="submit" id="yesButton">Yes</button>
<input
type="hidden"
name="target-user"
value="{{ potential_match.username }}"
/>
</form>
</div>
{% endblock %}
{% endif %}
</div>
</div>
{% endblock %}
23 changes: 10 additions & 13 deletions code_spark/app/templates/login.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{% extends 'base.html' %}
{% block title %}Sign in{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-8 mx-auto social-container my-2 order-md-1">
<button class="btn btn-primary mb-2">
<a href="{% url 'social:begin' 'github' %}">
LOGIN WITH GITHUB
</a>
</button>
</div>
</div>
{% endblock %}
{% extends 'base.html' %} {% block title %}Sign in{% endblock %} {% block
content %}
<div class="row">
<div class="col-md-8 mx-auto social-container my-2 order-md-1">
<button class="btn btn-primary mb-2">
<a href="{% url 'social:begin' 'github' %}"> LOGIN WITH GITHUB </a>
</button>
</div>
</div>
{% endblock %}
89 changes: 87 additions & 2 deletions code_spark/app/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,97 @@
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from .models import MatchRequest
from django.http import HttpResponse
from django.contrib.auth.models import User
from django.template import loader
from django.shortcuts import redirect

# Create your views here.


def login(request):
return render(request, 'login.html')
return render(request, "login.html")


@login_required
def home(request):
return render(request, 'home.html')
potential_match = get_potential_match(request.user)
if potential_match:
potential_match_message = "Your potential match is " + potential_match.username
else:
potential_match_message = (
"No potential matches available. Please check back later"
)
context = {
"potential_match_message": potential_match_message,
"potential_match": potential_match,
}
template = loader.get_template("home.html")
return HttpResponse(template.render(context, request))


# @login_required
# def match(request, other_requesting_user=None):
# if other_requesting_user:
# match_request = MatchRequest(match_request_sender)


@login_required
def request(request):
user = request.user
if MatchRequest.objects.filter(match_request_receiver=user).count() == 1:
pass
# TODO: redirect to match
match_request = MatchRequest(
match_request_sender=user,
match_request_receiver=User.objects.get(username=request.GET["target-user"]),
match_request_status=1,
# do not set created_date or accepted date
)
match_request.save()
# TODO: check for an existing matching match request_match. If found, will go to match, else go home
return redirect("home")


@login_required
def decline(request):
user = request.user
# other_requesting_user = MatchRequest.objects.get(match_request_receiver=user)
# matching_match_request = MatchRequest.objects.get(match_request_receiver=user)
# matching_match_request.
match_request = MatchRequest(
match_request_sender=user,
match_request_receiver=User.objects.get(username=request.GET["target-user"]),
match_request_status=-1,
# do not set created_date or accepted date
)
match_request.save()
# TODO: check for an existing matching match request_match. If found, will go to match, else go home
return redirect("home")


def get_potential_match(user):
"""
Returns a user that the current user has not been seen by and
has not seen.
:param user:
:return:
"""

from random import choice

pks = (
User.objects.exclude(
received_requests__match_request_sender__username=user.username
)
# .exclude( # TODO: is this needed?
# sent_requests__match_request_receiver__username=user.username
# )
.exclude(username=user.username).values_list("pk", flat=True)
)
if len(pks) == 0:
return None
random_pk = choice(pks)
potential_match = User.objects.get(pk=random_pk)

return potential_match
Loading