Closes #8 ignore the above, I was talking shite.

This commit is contained in:
Fergal Moran
2013-12-20 19:36:51 +00:00
parent b7b02ace5f
commit f44d8359e1
12 changed files with 227 additions and 188 deletions

View File

@@ -0,0 +1,19 @@
from tastypie import fields
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization
from tastypie.exceptions import ImmediateHttpResponse
from tastypie.http import HttpBadRequest, HttpMethodNotAllowed, HttpUnauthorized, HttpApplicationError, HttpNotImplemented
from spa.api.v1.BackboneCompatibleResource import BackboneCompatibleResource
from spa.models import Mix, UserProfile, Genre
from spa.models.comment import Comment
class GenreResource(BackboneCompatibleResource):
class Meta:
queryset = Genre.objects.all().order_by('text')
resource_name = 'genres'
excludes = ['id', 'resource_uri']
authorization = Authorization()
authentication = Authentication()
always_return_data = True

View File

@@ -22,11 +22,9 @@ from spa.models.mix import Mix
class MixResource(BackboneCompatibleResource): class MixResource(BackboneCompatibleResource):
comments = fields.ToManyField('spa.api.v1.CommentResource.CommentResource', 'comments', null=True, full=True) comments = fields.ToManyField('spa.api.v1.CommentResource.CommentResource', 'comments', null=True, full=True)
favourites = fields.ToManyField('spa.api.v1.UserResource.UserResource', 'favourites', favourites = fields.ToManyField('spa.api.v1.UserResource.UserResource', 'favourites', related_name='favourites', full=False, null=True)
related_name='favourites', full=False, null=True) likes = fields.ToManyField('spa.api.v1.UserResource.UserResource', 'likes', related_name='likes', full=False, null=True)
genres = fields.ToManyField('spa.api.v1.GenreResource.GenreResource', 'genres', related_name='genres', full=True, null=True)
likes = fields.ToManyField('spa.api.v1.UserResource.UserResource', 'likes',
related_name='likes', full=False, null=True)
class Meta: class Meta:
queryset = Mix.objects.filter(is_active=True) queryset = Mix.objects.filter(is_active=True)
@@ -37,6 +35,7 @@ class MixResource(BackboneCompatibleResource):
post_excludes = ['comments'] post_excludes = ['comments']
filtering = { filtering = {
'comments': ALL_WITH_RELATIONS, 'comments': ALL_WITH_RELATIONS,
'genres': ALL_WITH_RELATIONS,
'favourites': ALL_WITH_RELATIONS, 'favourites': ALL_WITH_RELATIONS,
'likes': ALL_WITH_RELATIONS, 'likes': ALL_WITH_RELATIONS,
'slug': ALL_WITH_RELATIONS, 'slug': ALL_WITH_RELATIONS,
@@ -118,8 +117,6 @@ class MixResource(BackboneCompatibleResource):
local_file=file_name, local_file=file_name,
uid=uid) uid=uid)
self._unpackGenreList(ret, bundle.data['genre-list'])
#if ret is hunky dory
return ret return ret
def obj_update(self, bundle, **kwargs): def obj_update(self, bundle, **kwargs):
@@ -130,7 +127,6 @@ class MixResource(BackboneCompatibleResource):
bundle.obj.update_favourite(bundle.request.user, bundle.data['favourited']) bundle.obj.update_favourite(bundle.request.user, bundle.data['favourited'])
bundle.obj.update_liked(bundle.request.user, bundle.data['liked']) bundle.obj.update_liked(bundle.request.user, bundle.data['liked'])
self._unpackGenreList(ret, bundle.data['genre-list'])
return ret return ret
def apply_sorting(self, obj_list, options=None): def apply_sorting(self, obj_list, options=None):
@@ -185,7 +181,7 @@ class MixResource(BackboneCompatibleResource):
bundle.data['tooltip'] = render_to_string('inc/player_tooltip.html', {'item': bundle.obj}) bundle.data['tooltip'] = render_to_string('inc/player_tooltip.html', {'item': bundle.obj})
bundle.data['comment_count'] = bundle.obj.comments.count() bundle.data['comment_count'] = bundle.obj.comments.count()
bundle.data['genre-list'] = json.to_ajax(bundle.obj.genres.all(), 'description', 'slug') #bundle.data['genre-list'] = json.to_ajax(bundle.obj.genres.all(), 'description', 'slug')
bundle.data['liked'] = bundle.obj.is_liked(bundle.request.user) bundle.data['liked'] = bundle.obj.is_liked(bundle.request.user)
if bundle.request.user.is_authenticated(): if bundle.request.user.is_authenticated():
@@ -200,6 +196,7 @@ class MixResource(BackboneCompatibleResource):
return bundle return bundle
def get_search(self, request, **kwargs): def get_search(self, request, **kwargs):
self.method_check(request, allowed=['get']) self.method_check(request, allowed=['get'])
self.is_authenticated(request) self.is_authenticated(request)

View File

@@ -7,6 +7,6 @@ define ['app.lib/dssView', 'utils', 'text!/tpl/CommentItemView'],
} }
deleteComment: -> deleteComment: ->
utils.messageBox "/dlg/DeleteMixConfirm", => utils.messageBox "/dlg/DeleteCommentConfirm", =>
@model.destroy() @model.destroy()
CommentItemView CommentItemView

View File

@@ -21,7 +21,7 @@
CommentItemView.prototype.deleteComment = function() { CommentItemView.prototype.deleteComment = function() {
var _this = this; var _this = this;
return utils.messageBox("/dlg/DeleteMixConfirm", function() { return utils.messageBox("/dlg/DeleteCommentConfirm", function() {
return _this.model.destroy(); return _this.model.destroy();
}); });
}; };

View File

@@ -69,13 +69,12 @@ define ['app.lib/editableView', 'moment', 'utils', 'backbone.syphon', 'text!/tpl
initSelection: (element, callback) -> initSelection: (element, callback) ->
console.log("MixEditView: genres:initSelection") console.log("MixEditView: genres:initSelection")
result = [] result = []
genres = parent.model.get("genre-list") genres = parent.model.get("genres")
unless genres is `undefined` unless genres is `undefined`
$.each genres, (data) -> $.each genres, (data) ->
result.push result.push
id: @id id: @id
text: @text text: @description
callback result callback result
@@ -94,7 +93,10 @@ define ['app.lib/editableView', 'moment', 'utils', 'backbone.syphon', 'text!/tpl
@model.set data @model.set data
@model.set "upload-hash", @guid @model.set "upload-hash", @guid
@model.set "upload-extension", $("#upload-extension", @el).val() @model.set "upload-extension", $("#upload-extension", @el).val()
@model.set "genre-list", $("#genres", @el).select2("data")
$.each $("#genres", @el).select2("data"), (i, item) =>
@model.get("genres").add({description: item.text});
@model.unset "mix_image" unless @sendImage @model.unset "mix_image" unless @sendImage
@model.unset "comments" @model.unset "comments"

View File

@@ -102,12 +102,12 @@
var genres, result; var genres, result;
console.log("MixEditView: genres:initSelection"); console.log("MixEditView: genres:initSelection");
result = []; result = [];
genres = parent.model.get("genre-list"); genres = parent.model.get("genres");
if (genres !== undefined) { if (genres !== undefined) {
$.each(genres, function(data) { $.each(genres, function(data) {
return result.push({ return result.push({
id: this.id, id: this.id,
text: this.text text: this.description
}); });
}); });
} }
@@ -135,7 +135,11 @@
this.model.set(data); this.model.set(data);
this.model.set("upload-hash", this.guid); this.model.set("upload-hash", this.guid);
this.model.set("upload-extension", $("#upload-extension", this.el).val()); this.model.set("upload-extension", $("#upload-extension", this.el).val());
this.model.set("genre-list", $("#genres", this.el).select2("data")); $.each($("#genres", this.el).select2("data"), function(i, item) {
return _this.model.get("genres").add({
description: item.text
});
});
if (!this.sendImage) { if (!this.sendImage) {
this.model.unset("mix_image"); this.model.unset("mix_image");
} }

View File

@@ -49,8 +49,8 @@ define ['moment', 'app', 'vent', 'marionette', 'utils',
renderGenres: => renderGenres: =>
el = @el el = @el
$.each @model.get("genre-list"), (data) -> $.each @model.get("genres"), (data) ->
$("#genre-list", el).append '<a href="/mixes/' + @slug + '" class="label label-info arrowed-right arrowed-in">' + @text + '</a>' $("#genre-list", el).append '<a href="/mixes/' + @slug + '" class="label label-info arrowed-right arrowed-in">' + @description + '</a>'
true true
true true
@@ -106,7 +106,8 @@ define ['moment', 'app', 'vent', 'marionette', 'utils',
mixDelete: -> mixDelete: ->
console.log("MixItemView: mixDelete") console.log("MixItemView: mixDelete")
vent.trigger("mix:delete", @model) utils.messageBox "/dlg/DeleteMixConfirm", =>
@model.destroy()
mixLike: -> mixLike: ->
console.log("MixItemView: likeMix") console.log("MixItemView: likeMix")

View File

@@ -73,8 +73,8 @@
MixItemView.prototype.renderGenres = function() { MixItemView.prototype.renderGenres = function() {
var el; var el;
el = this.el; el = this.el;
$.each(this.model.get("genre-list"), function(data) { $.each(this.model.get("genres"), function(data) {
$("#genre-list", el).append('<a href="/mixes/' + this.slug + '" class="label label-info arrowed-right arrowed-in">' + this.text + '</a>'); $("#genre-list", el).append('<a href="/mixes/' + this.slug + '" class="label label-info arrowed-right arrowed-in">' + this.description + '</a>');
return true; return true;
}); });
return true; return true;
@@ -125,8 +125,11 @@
}; };
MixItemView.prototype.mixDelete = function() { MixItemView.prototype.mixDelete = function() {
var _this = this;
console.log("MixItemView: mixDelete"); console.log("MixItemView: mixDelete");
return vent.trigger("mix:delete", this.model); return utils.messageBox("/dlg/DeleteMixConfirm", function() {
return _this.model.destroy();
});
}; };
MixItemView.prototype.mixLike = function() { MixItemView.prototype.mixLike = function() {

View File

@@ -7,7 +7,6 @@
*/ */
/*
var socket = new io.Socket({host: 'ext-test.deepsouthsounds.com', resource: 'socket.io', port: '8000', rememberTransport: false}); var socket = new io.Socket({host: 'ext-test.deepsouthsounds.com', resource: 'socket.io', port: '8000', rememberTransport: false});
socket.connect(); socket.connect();
@@ -37,4 +36,3 @@ function message (from, msg) {
console.log(msg); console.log(msg);
$('#lines').append($('<p>').append($('<b>').text(from), msg)); $('#lines').append($('<p>').append($('<b>').text(from), msg));
} }
*/

View File

@@ -79,14 +79,14 @@
</div> </div>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<div class="like-button footer-button"> <div class="like-button footer-button">
<a class="btn btn-pink btn-xs <% if (liked) { %> disabled <% } %>" id="like-<%= id %>" <a class="btn <% if (liked) { %>btn-light<% } else { %>btn-pink<% } %> btn-xs" id="like-<%= id %>"
data-id="<%= id %>"> data-id="<%= id %>">
<i class="icon-heart"></i> Like</a> <i class="icon-heart"></i> Like<% if (liked) { %>d<% } %></a>
</div> </div>
<div class="favourite-button footer-button"> <div class="favourite-button footer-button">
<a class="btn btn-pink btn-xs <% if (favourited) { %> disabled <% } %> " <a class="btn <% if (favourited) { %>btn-light<% } else { %>btn-pink<% } %> btn-xs"
id="favourite-<%= id %>" id="favourite-<%= id %>"
data-id="<%= id %>"><i class="icon-star-empty"></i> Favourite</a> data-id="<%= id %>"><i class="icon-star-empty"></i> Favourite<% if (favourited) { %>d<% } %></a>
</div> </div>
{% endif %} {% endif %}
<div class="footer-button"> <div class="footer-button">

View File

@@ -0,0 +1,15 @@
{% extends 'views/dlg/_DialogBase.html' %}
{% load account %}
{% load static %}
{% load socialaccount %}
{% block header %}
<h3>You sure about this chief??</h3>
{% endblock %}
{% block content %}
Delete this comment?
{% endblock %}
{% block primarybutton %}Cancel{% endblock %}
{% block extrabuttons %}
<button type="button" class="btn btn-success" data-dismiss="modal" id="yes-no-positive">Proceed</button>
{% endblock %}

View File

@@ -7,7 +7,7 @@
<h3>You sure about this chief??</h3> <h3>You sure about this chief??</h3>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
Hit Proceed here and your mix is gone.<br/> Hit Proceed here and your mix is gone forever, no amount of complaining or bitching will bring it back.<br/>
Comments, likes, favourites, all gone, never to return. Comments, likes, favourites, all gone, never to return.
{% endblock %} {% endblock %}
{% block primarybutton %}Cancel{% endblock %} {% block primarybutton %}Cancel{% endblock %}