Skip to content

Commit

Permalink
Merge pull request #8 from ylijokic/Sprint_2_Backend
Browse files Browse the repository at this point in the history
Add DB config file, update templates, add images to Musician
  • Loading branch information
jordan-hamilton committed May 11, 2020
2 parents 2fb5e45 + 813aa75 commit 43d6909
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 56 deletions.
1 change: 1 addition & 0 deletions one_hit_wonder/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Musician(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
location = models.ForeignKey('Location', on_delete=models.PROTECT)
instruments = models.ManyToManyField('Instrument')
image = models.ImageField(default='default.jpg', upload_to='profile_pics')

def __str__(self):
return f"{self.user.first_name} {self.user.last_name}"
Expand Down
85 changes: 44 additions & 41 deletions one_hit_wonder/account/templates/account/base.html
Original file line number Diff line number Diff line change
@@ -1,59 +1,62 @@
{% load static %}
<!--Base HTML template for all pages within One Hit Wonder Project-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'css/bootstrap.css' %}">

{% if title %}
<title>One Hit Wonder - {{ title }}</title>
{% else %}
<title>One Hit Wonder</title>
{% endif %}
{% if title %}
<title>One Hit Wonder - {{ title }}</title>
{% else %}
<title>One Hit Wonder</title>
{% endif %}
</head>
<body>
<nav class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="{% url 'account-home' %}">One Hit Wonder</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<!--Navigation bar-->
<nav class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="{% url 'account-landing' %}">One Hit Wonder</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav mr-auto">
<a class="nav-item nav-link active" href="{% url 'account-home' %}">Home<span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="{% url 'account-profile' %}">Profile</a>
<a class="nav-item nav-link" href="{% url 'account-messages' %}">Messages</a>
<a class="nav-item nav-link" href="{% url 'account-matches' %}">Matches</a>
<a class="nav-item nav-link" href="{% url 'account-create_ad' %}">Create Ad</a>
{% if user.is_authenticated %}
<a class="nav-item nav-link active" href="{% url 'account-home' %}">Home<span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="{% url 'account-profile' %}">Profile</a>
<a class="nav-item nav-link" href="{% url 'account-messages' %}">Messages</a>
<a class="nav-item nav-link" href="{% url 'account-matches' %}">Matches</a>
<a class="nav-item nav-link" href="{% url 'account-create_ad' %}">Create Ad</a>
{% endif %}
</div>
<!-- Right side of Navbar -->
<div class="navbar-nav">
<!-- Conditional block to display login/logout links in navbar -->
{% if user.is_authenticated %}
<a href="{% url 'logout' %}" class="nav-item nav-link">Logout</a>
{% else %}
<a href="{% url 'login' %}" class="nav-item nav-link">Login</a>
<a href="{% url 'register' %}" class="nav-item nav-link">Register</a>
{% endif %}
<!-- Conditional block to display login/logout links in navbar -->
{% if user.is_authenticated %}
<a href="{% url 'logout' %}" class="nav-item nav-link">Logout</a>
{% else %}
<a href="{% url 'login' %}" class="nav-item nav-link">Login</a>
<a href="{% url 'register' %}" class="nav-item nav-link">Register</a>
{% endif %}

</div>
</div>
</nav>
<div class = "container">
{% if messages %}
</div>
</nav>
<div class = "container">
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{message.tags}}">
{{ message }}
</div>
<div class="alert alert-{{message.tags}}">
{{ message }}
</div>
{% endfor %}
{% endif %}
{% block content %}{% endblock %}
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
{% endif %}
{% block content %}{% endblock %}
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion one_hit_wonder/account/templates/account/create_ad.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

{% block content %}
<h1>Create Ad</h1>
{% endblock content %}
{% endblock content %}
7 changes: 4 additions & 3 deletions one_hit_wonder/account/templates/account/home.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{% extends "account/base.html" %}

<h1>Welcome Back!</h1>

{% block content %}
<h1>Welcome Back!</h1>
{% for post in posts %}
<h1>{{ post.title }}</h1>
<h2>{{ post.title }}</h2>
<p>By {{ post.musician }} on {{ post.date_posted }}</p>
<p>{{ post.content }}</p>
{% endfor %}
{{ musician.user.username }}
{% endblock content %}

5 changes: 5 additions & 0 deletions one_hit_wonder/account/templates/account/landing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "account/base.html" %}

{% block content %}
<h1>One Hit Wonder</h1>
{% endblock content %}
2 changes: 1 addition & 1 deletion one_hit_wonder/account/templates/account/matches.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

{% block content %}
<h1>Matches</h1>
{% endblock content %}
{% endblock content %}
2 changes: 1 addition & 1 deletion one_hit_wonder/account/templates/account/messages.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

{% block content %}
<h1>Messages</h1>
{% endblock content %}
{% endblock content %}
16 changes: 11 additions & 5 deletions one_hit_wonder/account/templates/account/profile.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{% extends "account/base.html" %}

{% load crispy_forms_tags %}
{% block content %}
<h1>Profile</h1>
<h2>{{ user.username }}</h2>
<p>{{ user.first_name }}</p>
<p>{{ musician.location }}</p>
<div class="content-section">
<div class="media">
<img class="rounded-circle account-img" src="{{ user.musician.image.url }}">
<div class="media-body">
<h2 class="account-heading">{{ user.username }}</h2>
<p class="text-secondary">{{ user.email }}</p>
</div>
</div>

</div>
{% endblock content %}
8 changes: 7 additions & 1 deletion one_hit_wonder/account/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from django.urls import path
from . import views
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static
from . import views

urlpatterns = [
path('', views.home, name='account-landing'),
path('', views.home, name='account-home'),
path('profile/', views.profile, name='account-profile'),
path('messages/', views.messages, name='account-messages'),
Expand All @@ -13,3 +16,6 @@
path('logout/', auth_views.LogoutView.as_view(template_name="account/logout.html"), name="logout"),
]

# For use during debugging. Change settings for live deployment
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
10 changes: 7 additions & 3 deletions one_hit_wonder/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
]


def landing(request):
print(request)
return render(request, 'account/landing.html')


# Decorator to check if user is logged in before displaying profile
@login_required
def home(request):
context = {
'posts': posts
Expand All @@ -24,11 +31,8 @@ def home(request):
# Decorator to check if user is logged in before displaying profile
@login_required
def profile(request):
user_id = request.user.id
musician = Musician.objects.get(id=user_id)
context = {
'title': 'Profile',
'musician': musician
}
return render(request, 'account/profile.html', context)

Expand Down
7 changes: 7 additions & 0 deletions one_hit_wonder/mariadb.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[client]
host = one-hit-wonder.cqtwgm1vyu0i.us-east-1.rds.amazonaws.com
database = one_hit_wonder
user = admin
password = D0nt8reakM3!
default-character-set = utf8
init_command = SET default_storage_engine=INNODB
4 changes: 4 additions & 0 deletions one_hit_wonder/one_hit_wonder/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
# Tells crispy forms to use bootstrap 4
CRISPY_TEMPLATE_PACK = 'bootstrap4'

# Creates directories for different types of media
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

# Sets default url to account-home page after successful login
LOGIN_REDIRECT_URL = 'account-home'

Expand Down

0 comments on commit 43d6909

Please sign in to comment.