Permalink
Browse files

Deleted all the tags part

- ManyToMany relationships need some hacking right now in ember-data. So I won't include them to keep the example as simple as possible
  • Loading branch information...
escalant3 committed Nov 10, 2012
1 parent 9bf83fa commit 0bbc97373cd32afc98b98e0da69ee2124819360e
View
@@ -1,7 +1,6 @@
from django.contrib import admin
from tasks.models import Person, Task, Tag
from tasks.models import Person, Task
admin.site.register(Person)
admin.site.register(Task)
admin.site.register(Tag)
View
@@ -2,7 +2,7 @@
from tastypie.authorization import Authorization
from tastypie.resources import ModelResource
from tasks.models import Person, Task, Tag
from tasks.models import Person, Task
class PersonResource(ModelResource):
@@ -29,7 +29,6 @@ class Meta:
class TaskResource(ModelResource):
person_id = fields.ToOneField(PersonResource, 'person', null=True)
tags = fields.ToManyField('tasks.api.TagResource', 'tags')
class Meta:
queryset = Task.objects.all()
@@ -43,20 +42,3 @@ class Meta:
# This option is necessary cause ember-data expects
# return data after a POST or PUT
always_return_data = True
class TagResource(ModelResource):
class Meta:
queryset = Tag.objects.all()
resource_name = 'tag'
# Authorization is needed for write methods
authorization = Authorization()
list_allowed_methods = ['get', 'post', 'put']
detail_allowed_methods = ['get', 'post', 'put', 'delete']
# This option is necessary cause ember-data expects
# return data after a POST or PUT
always_return_data = True
@@ -8,17 +8,9 @@ def __unicode__(self):
return self.name
class Tag(models.Model):
name = models.CharField(max_length=30)
def __unicode__(self):
return self.name
class Task(models.Model):
name = models.CharField(max_length=30)
person = models.ForeignKey(Person, null=True)
tags = models.ManyToManyField(Tag)
def __unicode__(self):
return self.name
@@ -21,13 +21,7 @@ App.Person = DS.Model.extend({
App.Task = DS.Model.extend({
name: DS.attr('string'),
person: DS.belongsTo('App.Person'),
tags: DS.hasMany('App.Tags')
});
App.Tag = DS.Model.extend({
name: DS.attr('string'),
task: DS.belongsTo('App.Task')
person: DS.belongsTo('App.Person')
});
// Application root view
@@ -93,33 +87,6 @@ App.CreateTaskView = Em.TextField.extend({
}
});
App.ToggleTagView = Em.View.extend({
tagName: "span",
classNames: ["label", "label-info"],
click: function(a, b, c) {
var tag,
task;
tag = this.get('content');
task = this.get('task');
Em.get(task, 'tags').pushObject(tag);
App.store.commit();
}
});
App.CreateTagView = Em.TextField.extend({
placeholder: "Add a new tag",
insertNewline: function() {
value = this.get('value');
if (!!value) {
App.Tag.createRecord({name: value});
App.store.commit();
this.set('value', '');
}
}
});
// The router is the main component of the application
App.Router = Ember.Router.extend({
@@ -223,7 +190,9 @@ App.Router = Ember.Router.extend({
// Ember-data store using the Django Tastypie adapter
App.store = DS.Store.create({
revision: 7,
adapter: DS.DjangoTastypieAdapter.create()
adapter: DS.DjangoTastypieAdapter.create({
serverDomain: "http://localhost:8000"
})
});
// Start!
@@ -173,12 +173,20 @@ DS.DjangoTastypieAdapter = DS.RESTAdapter.extend({
// Add the server domain if any
if (!!this.serverDomain) {
url = this.serverDomain + url;
url = this.removeTrailingSlash(this.serverDomain) + url;
}
return url;
},
removeTrailingSlash: function(url) {
if (url.charAt(url.length -1) === '/') {
console.log("REMOVE");
return url.slice(0, -1);
}
return url;
},
/**
django-tastypie does not pluralize names for lists
*/
@@ -95,19 +95,6 @@ <h5>Tags Assigned</h5>
{{/each}}
</ul>
<h5>Tags Available</h5>
{{view App.CreateTagView }}
<ul class="unstyled">
{{#each tag in availableTags}}
<li>
{{#view App.ToggleTagView contentBinding="tag" taskBinding="this"}}
{{ tag.name }}
{{/view}}
</li>
{{/each}}
</li>
</script>
<script src="static/tasks/js/app.js"></script>
View
@@ -1,7 +1,7 @@
from django.conf.urls.defaults import patterns, include, url
from tastypie.api import Api
from tasks.api import PersonResource, TaskResource, TagResource
from tasks.api import PersonResource, TaskResource
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
@@ -13,7 +13,6 @@
v1_api = Api(api_name='v1')
v1_api.register(PersonResource())
v1_api.register(TaskResource())
v1_api.register(TagResource())
urlpatterns = patterns('',
# Examples:

0 comments on commit 0bbc973

Please sign in to comment.