Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor Augusto committed Sep 20, 2022
0 parents commit 4c375dc
Show file tree
Hide file tree
Showing 71 changed files with 965 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
db.sqlite3
media/*
Empty file added apps/core/__init__.py
Empty file.
Binary file added apps/core/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added apps/core/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file added apps/core/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file added apps/core/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file added apps/core/__pycache__/views.cpython-39.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions apps/core/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 apps/core/apps.py
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.
3 changes: 3 additions & 0 deletions apps/core/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.
61 changes: 61 additions & 0 deletions apps/core/templates/core/base.html
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>
11 changes: 11 additions & 0 deletions apps/core/templates/core/frontpage.html
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 %}
17 changes: 17 additions & 0 deletions apps/core/templates/core/login.html
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 %}
19 changes: 19 additions & 0 deletions apps/core/templates/core/signup.html
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 %}
3 changes: 3 additions & 0 deletions apps/core/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
19 changes: 19 additions & 0 deletions apps/core/views.py
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 added apps/feed/__init__.py
Empty file.
Binary file added apps/feed/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added apps/feed/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file added apps/feed/__pycache__/api.cpython-39.pyc
Binary file not shown.
Binary file added apps/feed/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file added apps/feed/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file added apps/feed/__pycache__/views.cpython-39.pyc
Binary file not shown.
5 changes: 5 additions & 0 deletions apps/feed/admin.py
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)
16 changes: 16 additions & 0 deletions apps/feed/api.py
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})
6 changes: 6 additions & 0 deletions apps/feed/apps.py
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'
29 changes: 29 additions & 0 deletions apps/feed/migrations/0001_initial.py
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.
12 changes: 12 additions & 0 deletions apps/feed/models.py
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',)
108 changes: 108 additions & 0 deletions apps/feed/templates/feed.html
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 %}
40 changes: 40 additions & 0 deletions apps/feed/templates/search.html
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 %}
3 changes: 3 additions & 0 deletions apps/feed/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
Loading

0 comments on commit 4c375dc

Please sign in to comment.