-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vitor Augusto
committed
Sep 20, 2022
0 parents
commit 4c375dc
Showing
71 changed files
with
965 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea/ | ||
db.sqlite3 | ||
media/* |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CoreConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'apps.core' |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!DOCTYPE html> | ||
|
||
{% load static %} | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Twikker</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css"> | ||
<link rel="stylesheet" href="{% static 'css/main.css' %}"> | ||
</head> | ||
<body> | ||
<!-- navbar --> | ||
<nav class="navbar is-info" role="navigation"> | ||
<div class="navbar-brand"> | ||
<a href="/" class="navbar-item">Twikker</a> | ||
<a href="/" class="navbar-burger"> | ||
<span aria-hidden="true"></span> | ||
<span aria-hidden="true"></span> | ||
<span aria-hidden="true"></span> | ||
</a> | ||
</div> | ||
|
||
<div class="navbar-menu"> | ||
<div class="navbar-end"> | ||
{% if request.user.is_authenticated %} | ||
<a href="{% url 'search' %}" class="navbar-item">Search</a> | ||
<a href="{% url 'feed' %}" class="navbar-item">Feed</a> | ||
<a href="{% url 'twikkerprofile' request.user.username %}" class="navbar-item">Profile</a> | ||
<a href="{% url 'edit_profile' %}" class="navbar-item">Edit profile</a> | ||
{% endif %} | ||
<div class="navbar-item"> | ||
<div class="buttons"> | ||
{% if request.user.is_authenticated %} | ||
<a href="{% url 'logout' %}" class="button is-danger">Log out</a> | ||
{% else %} | ||
<a href="{% url 'signup' %}" class="button is-success">Sign Up</a> | ||
<a href="{% url 'login' %}" class="button is-light">Log in</a> | ||
{% endif %} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</nav> | ||
<!-- end navbar --> | ||
|
||
<!-- main content --> | ||
<section class="section"> | ||
{% block content %} | ||
{% endblock %} | ||
</section> | ||
<!-- end main content --> | ||
|
||
<!-- Scripts --> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script> | ||
{% block script %} | ||
{% endblock %} | ||
<!-- End Scripts --> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends 'core/base.html' %} | ||
|
||
{% block content %} | ||
<div class=""container> | ||
<div class="columns"> | ||
<div class="column is-12"> | ||
<h1 class="title">Welcome to Twikker</h1> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends 'core/base.html' %} | ||
|
||
{% block content %} | ||
<div class="container"> | ||
<div class="columns"> | ||
<div class="column is-12"> | ||
<h1 class="title">Log In</h1> | ||
|
||
<form method="post" action="."> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<button class="button is-success" type="submit">Log In</button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% extends 'core/base.html' %} | ||
|
||
{% block content %} | ||
<div class="container"> | ||
<div class="columns"> | ||
<div class="column is-12"> | ||
<h1 class="title">Sign Up</h1> | ||
|
||
<form method="post" action="."> | ||
{% csrf_token %} | ||
|
||
{{ form.as_p }} | ||
|
||
<button class="button is-success" type="submit">Sign Up</button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.contrib.auth import login | ||
from django.contrib.auth.forms import UserCreationForm | ||
from django.shortcuts import render, redirect | ||
|
||
|
||
def frontpage(request): | ||
return render(request, 'core/frontpage.html') | ||
|
||
|
||
def signup(request): | ||
if request.method == 'POST': | ||
form = UserCreationForm(request.POST) | ||
if form.is_valid(): | ||
user = form.save() | ||
login(request, user) | ||
return redirect('frontpage') | ||
else: | ||
form = UserCreationForm() | ||
return render(request, 'core/signup.html', {'form': form}) |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Tweek | ||
|
||
admin.site.register(Tweek) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import json | ||
|
||
from django.http import JsonResponse | ||
from django.contrib.auth.decorators import login_required | ||
|
||
from apps.feed.models import Tweek | ||
|
||
|
||
@login_required | ||
def api_add_tweek(request): | ||
data = json.loads(request.body) | ||
body = data['body'] | ||
|
||
tweek = Tweek.objects.create(body=body, created_by=request.user) | ||
|
||
return JsonResponse({'success': True}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class FeedConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'apps.feed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 4.1.1 on 2022-09-20 02:40 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Tweek', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('body', models.CharField(max_length=255)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tweeks', to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'ordering': ('-created_at',), | ||
}, | ||
), | ||
] |
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.db import models | ||
|
||
from django.contrib.auth.models import User | ||
|
||
|
||
class Tweek(models.Model): | ||
body = models.CharField(max_length=255) | ||
created_by = models.ForeignKey(User, related_name='tweeks', on_delete=models.CASCADE) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
|
||
class Meta: | ||
ordering = ('-created_at',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{% extends 'core/base.html' %} | ||
|
||
{% load humanize %} | ||
|
||
{% block content %} | ||
<div class="container" id="feedapp"> | ||
<div class="columns"> | ||
<div class="column is-12"> | ||
<div class="wrapper-form"> | ||
<form v-on:submit.prevent="submitTweek()"> | ||
<div class="field"> | ||
<div class="control"> | ||
<textarea class="textarea" v-model="body" placeholder="What are you tweeking?"></textarea> | ||
</div> | ||
</div> | ||
<div class="field"> | ||
<div class="control"> | ||
<button class="button is-success" type="submit">Submit</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
<div class="wrapper-tweeks"> | ||
{% for tweek in tweeks %} | ||
<div class="tweek"> | ||
<article class="media"> | ||
<figure class="media-left"> | ||
<p class="image is-64x64"> | ||
{% if tweek.created_by.twikkerprofile.avatar %} | ||
<img src="{{ tweek.created_by.twikkerprofile.avatar.url}}"> | ||
{% endif %} | ||
</p> | ||
</figure> | ||
|
||
<div class="media-content"> | ||
<div class="content"> | ||
<p> | ||
<strong>{{ tweek.created_ny.username }}</strong> | ||
<small>{{ tweek.created_at|naturaltime }}</small> | ||
<br> | ||
{{ tweek.body }} | ||
</p> | ||
</div> | ||
</div> | ||
</article> | ||
</div> | ||
{% endfor %} | ||
<div class="tweek" v-for="tweek in tweeks"> | ||
<p class="name">[[ tweek.tweeker ]]</p> | ||
<p>[[ tweek.body ]]</p> | ||
<p class="info">[[ tweek.created_at ]]</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block script %} | ||
<script> | ||
new Vue({ | ||
el: '#feedapp', | ||
delimiters: ['[[', ']]'], | ||
data(){ | ||
return{ | ||
tweeks: [], | ||
body: '', | ||
tweeker: '{{ request.user.username }}', | ||
created_at: 'Now', | ||
} | ||
}, | ||
methods: { | ||
submitTweek(){ | ||
console.log('submitting tweek') | ||
|
||
if (this.body.length > 0){ | ||
let tweek = { | ||
'body': this.body, | ||
'tweeker': this.tweeker, | ||
'created_at': this.created_at, | ||
}; | ||
|
||
this.tweeks.unshift(tweek); | ||
|
||
// Send to backend | ||
|
||
fetch('/api/add_tweek/',{ | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-CSRFToken': '{{ csrf_token }}', | ||
}, | ||
credentials: 'same-origin', | ||
body: JSON.stringify(tweek) | ||
}) | ||
.then((response) => { | ||
console.log(response) | ||
}) | ||
.catch((error) => { | ||
console.log(error) | ||
}) | ||
} | ||
this.body = ''; | ||
} | ||
} | ||
}) | ||
</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{% extends 'core/base.html' %} | ||
|
||
{% load humanize %} | ||
|
||
{% block content %} | ||
<div class="container"> | ||
<div class="columns"> | ||
<div class="column is-12"> | ||
<h1 class="title">Search</h1> | ||
|
||
<p>Search term: "{{ query }}"</p> | ||
|
||
<hr> | ||
|
||
<form method="get" action="{% url 'search' %}"> | ||
<div class="field"> | ||
<div class="control"> | ||
<input class="input" type="text" name="query" placeholder="Search..." value="{{ query }}"> | ||
</div> | ||
</div> | ||
|
||
<div class="field"> | ||
<div class="control"> | ||
<button class="button is-success" type="submit">Search</button> | ||
</div> | ||
</div> | ||
</form> | ||
|
||
<hr> | ||
|
||
<div class="search-results"> | ||
{% for tweeker in tweekers %} | ||
<p><a href="{% url 'twikkerprofile' tweeker.username %}">{{ tweeker.username }}</a></p> | ||
{% endfor %} | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
Oops, something went wrong.