Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@

# Created by https://www.toptal.com/developers/gitignore/api/django
# Edit at https://www.toptal.com/developers/gitignore?templates=django

### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
media

# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
# <django-project-name>/staticfiles/

### Django.Python Stack ###
# Byte-compiled / optimized / DLL files
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo

# Django stuff:

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

Hongji0611/ministagram/.vscode/
Empty file.
7 changes: 7 additions & 0 deletions Hongji0611/ministagram/accounts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from accounts.models import FollowRelation

class FollowRelationAdmin(admin.ModelAdmin):
list_display = ('follower', )

admin.site.register(FollowRelation, FollowRelationAdmin)
5 changes: 5 additions & 0 deletions Hongji0611/ministagram/accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
name = 'accounts'
25 changes: 25 additions & 0 deletions Hongji0611/ministagram/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.0.8 on 2020-07-12 07:51

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='FollowRelation',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('followee', models.ManyToManyField(related_name='followee', to=settings.AUTH_USER_MODEL)),
('follower', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='follower', to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file.
12 changes: 12 additions & 0 deletions Hongji0611/ministagram/accounts/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

# Create your models here.


class FollowRelation(models.Model):
objects = models.Manager()
DoesNotExist = models.Manager()
follower = models.OneToOneField(
User, related_name='follower', on_delete=models.CASCADE) # 나를 팔로우 하는 사람
followee = models.ManyToManyField(User, related_name='followee') # 내가 팔로우
21 changes: 21 additions & 0 deletions Hongji0611/ministagram/accounts/templates/accounts/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'base.html' %}

{% block title %}
{% endblock %}

{% block content %}
<div class="row">
<div class="col"></div>
<div class="'col-6">
<div class="alert alert-primary" role="alert">
Please enter your login information. </div>
<form action="" method="post">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="login" class = 'btn btn-outline-primary'>
</form>
</div>
<div class="col"></div>

</div>
{% endblock %}
17 changes: 17 additions & 0 deletions Hongji0611/ministagram/accounts/templates/accounts/logout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'base.html' %}

{% block title %}
{% endblock %}

{% block content %}
<div class="row">
<div class="col"></div>
<div class="'col-6">
<div class="alert alert-primary" role="alert">
로그아웃 되었습니다. </div>
<a href="{% url 'accounts:login'%}" class="btn btn-outline-success">login 하기</a>
</div>
<div class="col"></div>

</div>
{% endblock %}
99 changes: 99 additions & 0 deletions Hongji0611/ministagram/accounts/templates/accounts/relation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{% extends 'base.html' %}

{% block title %}
{% endblock %}

{% block content %}
<div class = "all" style = "width :600px; margin:0 auto;">

<p>사용자 찾기</p>
<input type = "text" id = "searchUserName" placeholder = "Enter username..">
<button id = "search" class = "btn-outline-success">검색</button>
<p><b id = "searchResult"></b>
<span id = "searchFollow" style = "display:none;">-<button></button></span></p>
<hr><hr>

<!-- 친구 목록 -->
<h4>날 팔로우하는 사람들</h4>
{% if followers %} <!-- 객체가 존재한다면-->
<ul class = "list-group">
{% for myfollower in followers %}
<li class = "list-group-item col-md-6">
{{myfollower.follower.username}}
<!--나를 팔로우하는 사람을 내가 팔로우하지 않은 경우-->
{% if myfollower.follower.id in followees_ids %}
- <button class = "unfollow btn btn-outline-success" data-user-id = "{{myfollower.follower.id}}">언팔로우</button>

{% else %}
- <button class = "follow btn btn-outline-success" data-user-id = "{{myfollower.follower.id}}">팔로우</button>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}

<h4>내가 팔로우하는 사람들</h4>
{% if followees %}
<ul class = "list-group">
{% for user in followees %}
<li class = "list-group-item col-md-6">{{user.username}} - <button class = "unfollow btn btn-outline-success" data-user-id = "{{user.id}}">언팔로우</button></li>
{% endfor %}
</ul>
{% endif %}
</div>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>

<script>
$(document).ready(function(){
$('#search').click(function(){
var username = $('#searchUserName').val();
var followeesIds = "{{followees_ids}}";
$.get("{% url 'accounts:relationuserinfo' %}", {'username' :username}, function(obj){
$('#searchResult').html(obj.data.username);
var $searchRelationButton = $('#searchFollow button');
$searchRelationButton.data('user-id', obj.data.id);

console.log(username)
console.log(obj.data.id)
console.log(followeesIds)
console.log(followeesIds.indexOf(obj.data.id))

if (followeesIds.indexOf(obj.data.id) > -1){
$searchRelationButton.removeClass('follow');
$searchRelationButton.addClass('unfollow');
$searchRelationButton.html('언팔로우');
} else {
$searchRelationButton.removeClass('unfollow');
$searchRelationButton.addClass('follow');
$searchRelationButton.html('팔로우');
}
$('#searchFollow').show();
}).fail(function(data){
$('#searchResult').html(data.responseJSON.message);
});
});

$('body').delegate('.follow', 'click', function(e){
var userId = $(e.currentTarget).data('user-id');
$.post("{% url 'accounts:relationcreate' %}", {id :userId}, function(){
location.reload();
}).fail(function(data){
alert(data.responseJSON.message);
});
});

$('body').delegate('.unfollow', 'click', function(e){
var userId = $(e.currentTarget).data('user-id');
$.post("{% url 'accounts:relationdelete' %}", {id : userId}, function(){
location.reload();
}).fail(function(data){
alert(data.responseJSON.message);
});
});
});

</script>
{% endblock %}
22 changes: 22 additions & 0 deletions Hongji0611/ministagram/accounts/templates/accounts/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends 'base.html' %}

{% block title %}
{% endblock %}

{% block content %}
<div class="row">
<div class="col"></div>
<div class="'col-6">
<div class="alert alert-primary" role="alert">
sign up! </div>
<form action="" method="post">
{% csrf_token %}
{{ signup_form }}
<br>
<input type="submit" value="Sign up" class = 'btn btn-outline-primary'>
</form>
</div>
<div class="col"></div>

</div>
{% endblock %}
3 changes: 3 additions & 0 deletions Hongji0611/ministagram/accounts/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.
17 changes: 17 additions & 0 deletions Hongji0611/ministagram/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

from django.urls import path
from django.contrib.auth.views import LoginView, LogoutView
from .views import RelationView, RelationCreateView, RelationDeleteView, UserInfoGetView
from . import views

app_name = "accounts"

urlpatterns = [
path('relationuserinfo/', UserInfoGetView.as_view(), name='relationuserinfo'),
path('relationdelete/', RelationDeleteView.as_view(), name='relationdelete'),
path('relationcreate/', RelationCreateView.as_view(), name='relationcreate'),
path('relation/', RelationView.as_view(template_name='accounts/relation.html'), name='relation'),
path('signup/', views.signup, name='signup'),
path('login/', LoginView.as_view(template_name='accounts/login.html'), name='login'),
path('logout/', LogoutView.as_view(template_name='accounts/logout.html'), name='logout'),
]
Loading