Skip to content

Commit 3518a7c

Browse files
committed
models
1 parent 453eed2 commit 3518a7c

File tree

6 files changed

+67
-24
lines changed

6 files changed

+67
-24
lines changed

app/urls.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,9 @@
11
from django.conf.urls import url
22
from django.contrib import admin
3-
from django.views.generic import TemplateView
43
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
54
from django.conf import settings
65
from django.conf.urls.static import static
7-
from tasks.models import Task
8-
import json
9-
10-
class TaskView(TemplateView):
11-
template_name ="index.html"
12-
def process(self, t):
13-
task = t.to_dict()
14-
for i in ('path', 'depth', 'path', 'numchild'):
15-
if i in task:
16-
del task[i]
17-
task['id'] = str(task['id'])
18-
childrens = [c.id for c in t.get_children()]
19-
task["dependencies"] = ",".join([str(i) for i in childrens])
20-
return task
21-
def get_context_data(self, **kwargs):
22-
ctx = super(TaskView, self).get_context_data(**kwargs)
23-
tasks = Task.objects.all()
24-
25-
ctx["tasks"] = json.dumps([ self.process(t) for t in tasks])
26-
return ctx
27-
6+
from tasks.views import TaskView
287

298
urlpatterns = [
309
url(r'^admin/', admin.site.urls),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 2.0.3 on 2018-03-23 01:04
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('tasks', '0002_auto_20180322_0444'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='task',
15+
name='custom_class',
16+
field=models.CharField(default='', max_length=20),
17+
preserve_default=False,
18+
),
19+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.0.3 on 2018-03-23 01:04
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('tasks', '0003_task_custom_class'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='task',
15+
name='custom_class',
16+
field=models.CharField(blank=True, max_length=20, null=True),
17+
),
18+
]

tasks/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class Task(MP_Node, ToDictMixin):
1010
start = models.DateField()
1111
end = models.DateField()
1212
progress = models.PositiveIntegerField(default=0)
13+
custom_class = models.CharField(max_length=20, null=True, blank=True)
14+
15+
def __str__(self):
16+
return self.__unicode__()
1317

1418
def __unicode__(self):
1519
return u"{}".format(self.name)

tasks/templates/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
color:white;
2020
font-size:1rem;
2121
}
22+
.gantt .red .bar-progress {
23+
fill: tomato;
24+
}
2225
</style>
2326
</head>
2427
<body>

tasks/views.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
3-
43
from django.shortcuts import render
4+
from django.views.generic import TemplateView
5+
from tasks.models import Task
6+
import json
7+
8+
class TaskView(TemplateView):
9+
template_name ="index.html"
10+
def process(self, t):
11+
task = t.to_dict()
12+
for i in ('path', 'depth', 'path', 'numchild'):
13+
if i in task:
14+
del task[i]
15+
task['id'] = str(task['id'])
16+
childrens = [c.id for c in t.get_children()]
17+
task["dependencies"] = ",".join([str(i) for i in childrens])
18+
return task
19+
20+
def get_context_data(self, **kwargs):
21+
ctx = super(TaskView, self).get_context_data(**kwargs)
22+
tasks = Task.objects.all()
23+
24+
ctx["tasks"] = json.dumps([ self.process(t) for t in tasks])
25+
return ctx
526

6-
# Create your views here.

0 commit comments

Comments
 (0)