Skip to content

Commit ea7da3c

Browse files
committed
Initial Commit
0 parents  commit ea7da3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+14760
-0
lines changed

Project/__init__.py

Whitespace-only changes.

Project/actions.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import json
2+
3+
from django.views.decorators.csrf import ensure_csrf_cookie
4+
from django.http import JsonResponse
5+
6+
from .forms import MODEL_FORMS
7+
8+
9+
@ensure_csrf_cookie
10+
def create_object(request):
11+
form_data = json.loads(request.body)
12+
model_class = form_data.pop('model')
13+
model_form = MODEL_FORMS[model_class](form_data)
14+
15+
result = {'success': False}
16+
if model_form.is_valid():
17+
model_form.save()
18+
result["success"] = True
19+
else:
20+
result["errors"] = model_form.errors.as_json()
21+
22+
return JsonResponse(result)

Project/admin.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib import admin
2+
3+
from .models import Project, Resource, Article, Author
4+
5+
admin.site.register(Project)
6+
admin.site.register(Resource)

Project/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class ProjectConfig(AppConfig):
5+
name = 'Project'

Project/forms.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from django.forms import ModelForm
2+
3+
from .models import Project, Resource, Binder
4+
5+
6+
class ProjectForm(ModelForm):
7+
8+
class Meta:
9+
model = Project
10+
fields = ['name',]
11+
12+
13+
class BinderForm(ModelForm):
14+
15+
class Meta:
16+
model = Binder
17+
fields = ['name',]
18+
19+
20+
class ResourceForm(ModelForm):
21+
22+
class Meta:
23+
model = Resource
24+
fields = ['url',]
25+
26+
27+
MODEL_FORMS = {
28+
"project": ProjectForm,
29+
"binder": BinderForm,
30+
"resource": ResourceForm
31+
}

Project/migrations/0001_initial.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generated by Django 3.1.3 on 2020-11-24 01:40
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
initial = True
10+
11+
dependencies = [
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='Project',
17+
fields=[
18+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19+
('name', models.CharField(max_length=24)),
20+
],
21+
),
22+
migrations.CreateModel(
23+
name='Resource',
24+
fields=[
25+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
26+
('url', models.URLField()),
27+
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Project.project')),
28+
],
29+
),
30+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Generated by Django 3.1.3 on 2020-11-24 01:53
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('Project', '0001_initial'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Author',
16+
fields=[
17+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('name', models.CharField(max_length=64)),
19+
('slug', models.CharField(default='', max_length=64)),
20+
],
21+
),
22+
migrations.AddField(
23+
model_name='project',
24+
name='slug',
25+
field=models.SlugField(default=1),
26+
preserve_default=False,
27+
),
28+
migrations.CreateModel(
29+
name='Article',
30+
fields=[
31+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
32+
('name', models.CharField(max_length=64)),
33+
('content', models.TextField()),
34+
('slug', models.CharField(default='', max_length=64)),
35+
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Project.author')),
36+
],
37+
),
38+
]

Project/migrations/0003_binder.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 3.1.3 on 2020-11-24 19:46
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('Project', '0002_auto_20201123_1753'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Binder',
16+
fields=[
17+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('name', models.CharField(max_length=36)),
19+
('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='Project.project')),
20+
],
21+
),
22+
]

Project/migrations/__init__.py

Whitespace-only changes.

Project/models.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from django.db import models
2+
3+
4+
class Project(models.Model):
5+
name = models.CharField(max_length=24)
6+
slug = models.SlugField()
7+
8+
def __str__(self):
9+
return self.name
10+
11+
12+
class Binder(models.Model):
13+
name = models.CharField(max_length=36)
14+
project = models.ForeignKey(Project, blank=True, null=True, on_delete=models.SET_NULL)
15+
16+
17+
class Resource(models.Model):
18+
url = models.URLField()
19+
project = models.ForeignKey(Project, on_delete=models.CASCADE)
20+
21+
22+
class Article(models.Model):
23+
"""Table schema to store articles."""
24+
name = models.CharField(max_length=64)
25+
author = models.ForeignKey('Author', on_delete=models.CASCADE)
26+
content = models.TextField()
27+
slug = models.CharField(default='', max_length=64)
28+
29+
def __str__(self):
30+
return '%s' % self.name
31+
32+
33+
class Author(models.Model):
34+
"""Table schema to store auhtors."""
35+
name = models.CharField(max_length=64)
36+
slug = models.CharField(default='', max_length=64)
37+
38+
def __str__(self):
39+
return '%s' % self.name

Project/templates/__init__.py

Whitespace-only changes.

Project/templates/html/__init__.py

Whitespace-only changes.

Project/templates/html/template.html

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<!-- Required meta tags -->
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7+
8+
<!-- Bootstrap CSS -->
9+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
10+
11+
<title>Django and Vue.js</title>
12+
<style>
13+
.router-link-active {
14+
color: black;
15+
text-decoration: none;
16+
}
17+
</style>
18+
</head>
19+
<body class="bg-light">
20+
<div class="bg-white container">
21+
22+
<div class="jumbotron">
23+
<h1 class="display-4">Django and Vue.js</h1>
24+
<p class="lead">
25+
Wouldn’t it be cool if you could prototype a custom web application that’s responsive (mobile ready), reactive (light-speed fast), with a full–featured back office site to manage the content; all of that in no time? Actually, with a mashup between Django’s and Vue.js, you can! 😁
26+
</p>
27+
</div>
28+
29+
<!-- Content -->
30+
<div id="myapp">
31+
<nav class="navbar navbar-expand-lg navbar-light bg-light">
32+
<ul class="navbar-nav mr-auto">
33+
<li class="nav-item">
34+
<router-link
35+
class="nav-link text-primary"
36+
to="/author/"
37+
>
38+
Go to Authors
39+
</router-link>
40+
</li>
41+
<li class="nav-item">
42+
<router-link
43+
class="nav-link text-primary"
44+
to="/article/"
45+
>
46+
Go to Articles
47+
</router-link>
48+
</li>
49+
</ul>
50+
</nav>
51+
<br />
52+
<router-view></router-view>
53+
</div>
54+
</div>
55+
56+
<!-- Vue.js -->
57+
<script src="https://unpkg.com/vue"></script>
58+
<script src="https://unpkg.com/vue-router"></script>
59+
<script src="https://unpkg.com/vuex"></script>
60+
61+
{% include 'vue/template.vue' %}
62+
63+
<!-- Vue app -->
64+
65+
66+
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
67+
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
68+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
69+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
70+
</body>
71+
</html>

Project/templates/html/triage.html

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{% load static %}
2+
3+
<!doctype html>
4+
<html lang="en">
5+
<head>
6+
<!-- Required meta tags -->
7+
<meta charset="utf-8">
8+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
9+
</head>
10+
11+
<body>
12+
13+
<div id="projects">
14+
<h1>Triage</h1>
15+
16+
<div id="triageApp">
17+
<project-list></project-list>
18+
</div>
19+
</div>
20+
<!-- Vue.js -->
21+
<script src="https://unpkg.com/vue@next"></script>
22+
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
23+
<script>
24+
axios.defaults.xsrfCookieName = 'csrftoken'
25+
axios.defaults.xsrfHeaderName = "X-CSRFTOKEN"
26+
</script>
27+
28+
{% include 'vue/triage.vue' %}
29+
{% include 'scripts/triage.html' %}
30+
31+
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
32+
</body>
33+
34+
</html>

Project/templates/scripts/__init__.py

Whitespace-only changes.
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<script>
2+
3+
// store
4+
const store = new Vuex.Store({
5+
state: {
6+
authors: [
7+
{% for author in authors %}
8+
{
9+
name: '{{ author.name }}',
10+
slug: '{{ author.slug }}',
11+
bio: 'Generic Bio'
12+
},
13+
{% endfor %}
14+
],
15+
articles: [
16+
{% for article in articles %}
17+
{
18+
content: '{{ article.content | linebreaksbr }}',
19+
name: '{{ article.name }}',
20+
slug: '{{ article.slug }}',
21+
},
22+
{% endfor %}
23+
],
24+
},
25+
getters: {
26+
getArticleBySlug: (state) => (slug) => {
27+
return state.articles.find(articles => articles.slug === slug)
28+
},
29+
getAuthorBySlug: (state) => (slug) => {
30+
return state.authors.find(authors => authors.slug === slug)
31+
},
32+
}
33+
});
34+
35+
// components
36+
ArticleList = Vue.component('article-list', {
37+
data: function () { return { articles: store.state.articles } },
38+
template: '#article-list-template',
39+
});
40+
41+
AuthorList = Vue.component('author-list', {
42+
data: function () { return { authors: store.state.authors } },
43+
template: '#author-list-template',
44+
});
45+
46+
ArticleItem = Vue.component('article-item', {
47+
delimiters: ['[[', ']]'],
48+
props: ['name', 'slug', 'content'],
49+
template: '#article-item-template',
50+
});
51+
52+
AuthorItem = Vue.component('author-item', {
53+
delimiters: ['[[', ']]'],
54+
props: ['name', 'slug', 'bio'],
55+
template: '#author-item-template',
56+
methods: {
57+
reverseName: function() {
58+
this.name = this.name.split('').reverse().join('')
59+
}
60+
}
61+
});
62+
63+
// router
64+
const routes = [
65+
{ component: ArticleList, path: '/article/', },
66+
{ component: AuthorList, path: '/author/', },
67+
{ component: ArticleItem, path: '/article/:slug/', },
68+
{ component: AuthorItem, path: '/author/:slug/', },
69+
]
70+
71+
const router = new VueRouter({
72+
mode: 'history',
73+
routes: routes,
74+
})
75+
76+
// app
77+
const vm = new Vue({
78+
router,
79+
store,
80+
}).$mount('#myapp');
81+
82+
</script>

0 commit comments

Comments
 (0)