Skip to content

Commit

Permalink
make task only item; task & wish will be related extra
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Chen committed May 25, 2017
1 parent d292d68 commit 3bd6ca7
Show file tree
Hide file tree
Showing 26 changed files with 301 additions and 1,292 deletions.
157 changes: 0 additions & 157 deletions settings/init.json
Original file line number Diff line number Diff line change
@@ -1,161 +1,4 @@
[
{
"model": "twido.todolist",
"pk": 1,
"fields": {
"profile": 2,
"timestamp": "2017-05-16T08:22:39.211Z",
"name": "__default__",
"reminder": null,
"related_users": null,
"text": "The default list. It will be created automatically."
}
},
{
"model": "twido.todolist",
"pk": 2,
"fields": {
"profile": 2,
"timestamp": "2017-05-16T08:14:16.373Z",
"name": "Daily",
"reminder": "2017-05-17T02:05:00Z",
"related_users": null,
"text": "This is a sample list with some tasks. Feel free to do something with it."
}
},
{
"model": "twido.todolist",
"pk": 3,
"fields": {
"profile": 2,
"timestamp": "2017-05-16T08:18:33.332Z",
"name": "A empty list",
"reminder": null,
"related_users": null,
"text": "There is no task in this list. Just create some as you wish to play with.\n"
}
},
{
"model": "twido.todolist",
"pk": 4,
"fields": {
"profile": 2,
"timestamp": "2017-05-16T08:19:43.194Z",
"name": "Project Mars",
"reminder": "2017-05-16T01:00:00Z",
"related_users": "Tom,Mike,Jack",
"text": "The common tasks for Project Mars"
}
},
{
"model": "twido.todo",
"pk": 1,
"fields": {
"profile": 2,
"timestamp": "2017-05-16T08:12:24.238Z",
"social_account": null,
"created_at": "2017-05-16T08:12:24.237Z",
"title": "A task in default list. (try moving it to antoher list on left)",
"text": null,
"status": 0,
"content": null,
"labels": "todo",
"raw": null,
"list": 1,
"deadline": "2017-05-16T08:30:00Z"
}
},
{
"model": "twido.todo",
"pk": 2,
"fields": {
"profile": 2,
"timestamp": "2017-05-16T08:15:07.459Z",
"social_account": null,
"created_at": "2017-05-16T08:15:07.458Z",
"title": "Buy milk",
"text": null,
"status": 9,
"content": null,
"labels": "life",
"raw": null,
"list": 2,
"deadline": "2017-05-15T23:40:00Z"
}
},
{
"model": "twido.todo",
"pk": 3,
"fields": {
"profile": 2,
"timestamp": "2017-05-16T08:16:16.519Z",
"social_account": null,
"created_at": "2017-05-16T08:16:16.519Z",
"title": "Running after dinner",
"text": null,
"status": -1,
"content": null,
"labels": "life,health",
"raw": null,
"list": 2,
"deadline": "2017-05-17T12:00:00Z"
}
},
{
"model": "twido.todo",
"pk": 4,
"fields": {
"profile": 2,
"timestamp": "2017-05-16T08:17:13.288Z",
"social_account": null,
"created_at": "2017-05-16T08:17:13.288Z",
"title": "touch my baby :)",
"text": null,
"status": 0,
"content": null,
"labels": "life,baby",
"raw": null,
"list": 2,
"deadline": "2017-05-17T03:30:00Z"
}
},
{
"model": "twido.todo",
"pk": 5,
"fields": {
"profile": 2,
"timestamp": "2017-05-16T08:20:56.830Z",
"social_account": null,
"created_at": "2017-05-16T08:20:56.830Z",
"title": "Daily standup meeting",
"text": null,
"status": 10,
"content": null,
"labels": "team",
"raw": null,
"list": 4,
"deadline": "2017-05-09T16:00:00Z"
}
},
{
"model": "twido.todo",
"pk": 6,
"fields": {
"profile": 2,
"timestamp": "2017-05-16T08:21:29.119Z",
"social_account": null,
"created_at": "2017-05-16T08:21:29.119Z",
"title": "Critical issue discussion",
"text": null,
"status": 1,
"content": null,
"labels": "project",
"raw": null,
"list": 4,
"deadline": "2017-05-16T08:00:00Z"
}
},

{
"model": "auth.user",
"pk": 1,
Expand Down
2 changes: 1 addition & 1 deletion twido/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.forms import ModelForm
from django import forms
from .models import TodoList, Todo, UserProfile
from .models import Task, UserProfile
from django.contrib.auth.forms import UserCreationForm
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import get_user_model
Expand Down
99 changes: 32 additions & 67 deletions twido/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ class TaskStatus(object):
EXPIRED: _('Expired'),
}
_glyphicons = {
NEW: 'glyphicon glyphicon-file text-muted ',
NEW: 'glyphicon glyphicon-record text-primary ',
STARTED: 'glyphicon glyphicon-play text-info',
PAUSED: 'glyphicon glyphicon-pause text-info',
PAUSED: 'glyphicon glyphicon-pause text-default',
DONE: 'glyphicon glyphicon-ok text-success',
CANCEL: 'glyphicon glyphicon-remove text-muted',
EXPIRED: 'glyphicon glyphicon-exclamation-sign text-danger',
Expand Down Expand Up @@ -391,7 +391,7 @@ def get_img_url(self):

class List(ProfileBasedModel):
"""
A list contains one or more things you want. (todolist, wishlist, ...)
A list contains one or more things you want or want to do. (todolist, wishlist, ...)
"""
name = models.CharField(max_length=100)
reminder = models.DateTimeField(null=True, blank=True)
Expand All @@ -401,7 +401,6 @@ class List(ProfileBasedModel):

class Meta:
unique_together = ('profile', 'name')
abstract = True

__default_name = '__default__'

Expand Down Expand Up @@ -432,7 +431,7 @@ def is_default(self):
return self.name == self.__default_name

def __str__(self):
return "%d:%s" % (self.id, self.name)
return "%s (id=%d)" % (self.name, self.id)

def save(self, force_insert=False, force_update=False, using=None,
update_fields=None, is_default=False):
Expand All @@ -441,25 +440,13 @@ def save(self, force_insert=False, force_update=False, using=None,
return super(List, self).save(force_insert=force_insert, force_update=force_update,
using=using, update_fields=update_fields)


class WishList(List):
"""
A wish list contains one or more things you want.
"""
pass


class TodoList(List):
"""
A Todo list contains one or more things you want to do or buy.
"""
def delete(self, using=None, keep_parents=False):
s = str(self)
log.debug('deleting todo list %s' % s)
log.debug('deleting list %s' % s)
with transaction.atomic():
Todo.objects.filter(list=self, profile=self.profile).update(list=self.get_default(self.profile))
Task.objects.filter(list=self, profile=self.profile).update(list=self.get_default(self.profile))
log.debug('all tasks in todo list %s are moved to default list.' % s)
super(TodoList, self).delete(using=using, keep_parents=keep_parents)
super(List, self).delete(using=using, keep_parents=keep_parents)
log.info('todo list %s is deleted.' % s)


Expand All @@ -472,14 +459,13 @@ class Task(ProfileBasedModel):
status = models.SmallIntegerField(choices=TaskStatus.Choices, default=TaskStatus.NEW, db_index=True)
text = models.TextField(null=True, blank=True)
labels = models.TextField(null=True, blank=True)
reminder = models.DateTimeField(null=True, blank=True)
list = models.ForeignKey(to=List)

content = models.TextField(null=True, blank=True)
social_account = models.ForeignKey(to=SocialAccount, db_index=True, null=True, blank=True)
raw = models.OneToOneField(to=RawStatus, null=True, blank=True)

class Meta:
abstract = True

def save(self, *args, **kwargs):
if not self.created_at:
self.created_at = timezone.now()
Expand All @@ -498,61 +484,40 @@ def get_status_glyphicon(self):
return TaskStatus.get_glyphicon(self.status)

def get_view_path(self):
raise NotImplementedError
return reverse('task', args=(self.id, ))

def __str__(self):
return '%s (id=%d)' % (self.title, self.id)


class Todo(Task):
"""
Todo entity
"""
list = models.ForeignKey(to=TodoList)
deadline = models.DateTimeField(null=True, blank=True)

def get_view_path(self):
return reverse('todo', args=(self.id,))


class Appointment(Task):
"""
Schedule appointment
"""
start_at = models.DateTimeField()
end_at = models.DateTimeField()
location = models.TextField()


class Wish(Task):
"""
A wish means a thing you want (maybe a travel, a bag or even a lover.)
"""
list = models.ForeignKey(to=WishList)
img = models.BinaryField()



# class WishListRel(models.Model):
# class Todo(Task):
# """
# Wish-list and wish relationship. Wishes on a wish-list of a user.
# Todo entity
# """
# list = models.ForeignKey(to=WishList)
# task = models.ForeignKey(to=Wish)
# # list = models.ForeignKey(to=TodoList)
# deadline = models.DateTimeField(null=True, blank=True)
#
# class Meta:
# unique_together = ('list', 'task')


# class TodoListRel(models.Model):
# def get_view_path(self):
# return reverse('todo', args=(self.id,))
#
#
# class Appointment(Task):
# """
# Wish-list and wish relationship. Wishes on a wish-list of a user.
# Schedule appointment
# """
# list = models.ForeignKey(to=TodoList)
# task = models.ForeignKey(to=Wish)
# start_at = models.DateTimeField()
# end_at = models.DateTimeField()
# location = models.TextField()
#
#
# class Meta:
# unique_together = ('list', 'task')
# class Wish(Task):
# """
# A wish means a thing you want (maybe a travel, a bag or even a lover.)
# """
# # list = models.ForeignKey(to=WishList)
# img = models.BinaryField()




# ========== Admin Pages ==========
Expand Down
4 changes: 2 additions & 2 deletions twido/templates/includes/paginatition.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

<!-- fast backward -->
<li>
<a href="?p={% if page.number|add:"10" > page.paginator.num_pages %}{{ page.painator.num_pages }}{% else %}{{ page.number|add:'10' }}{% endif %}" aria-label="Prev">
<a href="?p={% if page.number|add:"10" > page.paginator.num_pages %}{{ page.paginator.num_pages }}{% else %}{{ page.number|add:'10' }}{% endif %}" aria-label="Prev">
<span aria-hidden="true"><i class="glyphicon glyphicon-fast-forward"></i></span>
</a></li>

Expand All @@ -56,4 +56,4 @@
{# {% endif %}#}
</ul>
<!-- END pagination -->
{% endif %}
{% endif %}
3 changes: 2 additions & 1 deletion twido/templates/includes/topnavbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
<ul class="nav navbar-nav">
{% if request.user.is_authenticated %}
<li class="{% if request.path == '/home/' %}active{% endif %}"><a href="{% url 'home' %}">{% trans 'Home' %}{% if request.path == '/home/' %}<span class="sr-only">(current)</span>{% endif %}</a></li>
<li class="{% if request.path == '/todolist/' %}active{% endif %}"><a href="{% url 'todolist' %}">{% trans 'Todos' %}{% if request.path == '/todolist/' %}<span class="sr-only">(current)</span>{% endif %}</a></li>
{# <li class="{% if request.path == '/todolist/' %}active{% endif %}"><a href="{% url 'todolist' %}">{% trans 'Todos' %}{% if request.path == '/todolist/' %}<span class="sr-only">(current)</span>{% endif %}</a></li>#}
<li class="{% if request.path == '/list/' %}active{% endif %}"><a href="{% url 'list' %}">{% trans 'Lists' %}{% if request.path == '/list/' %}<span class="sr-only">(current)</span>{% endif %}</a></li>
{# <li><a href="{% url 'wishlist' %}">Wishes</a></li>#}
{# <li class="dropdown">#}
{# <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"#}
Expand Down
2 changes: 1 addition & 1 deletion twido/templates/twido/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<!-- left col -->
<div class="col-lg-3 col-md-3">
<div class="bs-component">
{% include 'twido/includes-list/todolists-menu.html' %}
{% include 'twido/includes-list/lists-menu.html' %}
{# {% include 'twido/includes-list/wishlists-menu.html' %}#}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<H3>{% trans 'Default List' %}</H3> <span>{% trans '(unlisted tasks)' %}</span>
</div>
{% else %}
<form class="form-horizontal" method="post" action="{% url 'todolist' thelist.id %}">
<form class="form-horizontal" method="post" action="{% url 'list' thelist.id %}">
{% csrf_token %}
<fieldset>
{# <legend class="edit">{{ thelist.name }}</legend>#}
Expand Down
Loading

0 comments on commit 3bd6ca7

Please sign in to comment.