mirror of
https://github.com/fergalmoran/dss.git
synced 2025-12-22 09:38:18 +00:00
Closes #8 ignore the above, I was talking shite.
This commit is contained in:
19
spa/api/v1/GenreResource.py
Normal file
19
spa/api/v1/GenreResource.py
Normal 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
|
||||
@@ -22,11 +22,9 @@ from spa.models.mix import Mix
|
||||
|
||||
class MixResource(BackboneCompatibleResource):
|
||||
comments = fields.ToManyField('spa.api.v1.CommentResource.CommentResource', 'comments', null=True, full=True)
|
||||
favourites = fields.ToManyField('spa.api.v1.UserResource.UserResource', 'favourites',
|
||||
related_name='favourites', full=False, null=True)
|
||||
|
||||
likes = fields.ToManyField('spa.api.v1.UserResource.UserResource', 'likes',
|
||||
related_name='likes', full=False, null=True)
|
||||
favourites = fields.ToManyField('spa.api.v1.UserResource.UserResource', 'favourites', 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)
|
||||
|
||||
class Meta:
|
||||
queryset = Mix.objects.filter(is_active=True)
|
||||
@@ -37,6 +35,7 @@ class MixResource(BackboneCompatibleResource):
|
||||
post_excludes = ['comments']
|
||||
filtering = {
|
||||
'comments': ALL_WITH_RELATIONS,
|
||||
'genres': ALL_WITH_RELATIONS,
|
||||
'favourites': ALL_WITH_RELATIONS,
|
||||
'likes': ALL_WITH_RELATIONS,
|
||||
'slug': ALL_WITH_RELATIONS,
|
||||
@@ -118,8 +117,6 @@ class MixResource(BackboneCompatibleResource):
|
||||
local_file=file_name,
|
||||
uid=uid)
|
||||
|
||||
self._unpackGenreList(ret, bundle.data['genre-list'])
|
||||
#if ret is hunky dory
|
||||
return ret
|
||||
|
||||
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_liked(bundle.request.user, bundle.data['liked'])
|
||||
|
||||
self._unpackGenreList(ret, bundle.data['genre-list'])
|
||||
return ret
|
||||
|
||||
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['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)
|
||||
|
||||
if bundle.request.user.is_authenticated():
|
||||
@@ -200,6 +196,7 @@ class MixResource(BackboneCompatibleResource):
|
||||
|
||||
return bundle
|
||||
|
||||
|
||||
def get_search(self, request, **kwargs):
|
||||
self.method_check(request, allowed=['get'])
|
||||
self.is_authenticated(request)
|
||||
|
||||
@@ -7,6 +7,6 @@ define ['app.lib/dssView', 'utils', 'text!/tpl/CommentItemView'],
|
||||
}
|
||||
|
||||
deleteComment: ->
|
||||
utils.messageBox "/dlg/DeleteMixConfirm", =>
|
||||
utils.messageBox "/dlg/DeleteCommentConfirm", =>
|
||||
@model.destroy()
|
||||
CommentItemView
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
CommentItemView.prototype.deleteComment = function() {
|
||||
var _this = this;
|
||||
return utils.messageBox("/dlg/DeleteMixConfirm", function() {
|
||||
return utils.messageBox("/dlg/DeleteCommentConfirm", function() {
|
||||
return _this.model.destroy();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -69,13 +69,12 @@ define ['app.lib/editableView', 'moment', 'utils', 'backbone.syphon', 'text!/tpl
|
||||
initSelection: (element, callback) ->
|
||||
console.log("MixEditView: genres:initSelection")
|
||||
result = []
|
||||
genres = parent.model.get("genre-list")
|
||||
genres = parent.model.get("genres")
|
||||
unless genres is `undefined`
|
||||
$.each genres, (data) ->
|
||||
result.push
|
||||
id: @id
|
||||
text: @text
|
||||
|
||||
text: @description
|
||||
|
||||
callback result
|
||||
|
||||
@@ -94,7 +93,10 @@ define ['app.lib/editableView', 'moment', 'utils', 'backbone.syphon', 'text!/tpl
|
||||
@model.set data
|
||||
@model.set "upload-hash", @guid
|
||||
@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 "comments"
|
||||
|
||||
|
||||
@@ -102,12 +102,12 @@
|
||||
var genres, result;
|
||||
console.log("MixEditView: genres:initSelection");
|
||||
result = [];
|
||||
genres = parent.model.get("genre-list");
|
||||
genres = parent.model.get("genres");
|
||||
if (genres !== undefined) {
|
||||
$.each(genres, function(data) {
|
||||
return result.push({
|
||||
id: this.id,
|
||||
text: this.text
|
||||
text: this.description
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -135,7 +135,11 @@
|
||||
this.model.set(data);
|
||||
this.model.set("upload-hash", this.guid);
|
||||
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) {
|
||||
this.model.unset("mix_image");
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ define ['moment', 'app', 'vent', 'marionette', 'utils',
|
||||
|
||||
renderGenres: =>
|
||||
el = @el
|
||||
$.each @model.get("genre-list"), (data) ->
|
||||
$("#genre-list", el).append '<a href="/mixes/' + @slug + '" class="label label-info arrowed-right arrowed-in">' + @text + '</a>'
|
||||
$.each @model.get("genres"), (data) ->
|
||||
$("#genre-list", el).append '<a href="/mixes/' + @slug + '" class="label label-info arrowed-right arrowed-in">' + @description + '</a>'
|
||||
true
|
||||
true
|
||||
|
||||
@@ -106,7 +106,8 @@ define ['moment', 'app', 'vent', 'marionette', 'utils',
|
||||
|
||||
mixDelete: ->
|
||||
console.log("MixItemView: mixDelete")
|
||||
vent.trigger("mix:delete", @model)
|
||||
utils.messageBox "/dlg/DeleteMixConfirm", =>
|
||||
@model.destroy()
|
||||
|
||||
mixLike: ->
|
||||
console.log("MixItemView: likeMix")
|
||||
|
||||
@@ -73,8 +73,8 @@
|
||||
MixItemView.prototype.renderGenres = function() {
|
||||
var el;
|
||||
el = this.el;
|
||||
$.each(this.model.get("genre-list"), function(data) {
|
||||
$("#genre-list", el).append('<a href="/mixes/' + this.slug + '" class="label label-info arrowed-right arrowed-in">' + this.text + '</a>');
|
||||
$.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.description + '</a>');
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
@@ -125,8 +125,11 @@
|
||||
};
|
||||
|
||||
MixItemView.prototype.mixDelete = function() {
|
||||
var _this = this;
|
||||
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() {
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
var socket = new io.Socket({host: 'ext-test.deepsouthsounds.com', resource: 'socket.io', port: '8000', rememberTransport: false});
|
||||
socket.connect();
|
||||
|
||||
@@ -37,4 +36,3 @@ function message (from, msg) {
|
||||
console.log(msg);
|
||||
$('#lines').append($('<p>').append($('<b>').text(from), msg));
|
||||
}
|
||||
*/
|
||||
@@ -79,14 +79,14 @@
|
||||
</div>
|
||||
{% if user.is_authenticated %}
|
||||
<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 %>">
|
||||
<i class="icon-heart"></i> Like</a>
|
||||
<i class="icon-heart"></i> Like<% if (liked) { %>d<% } %></a>
|
||||
</div>
|
||||
<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 %>"
|
||||
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>
|
||||
{% endif %}
|
||||
<div class="footer-button">
|
||||
|
||||
15
templates/views/dlg/DeleteCommentConfirm.html
Normal file
15
templates/views/dlg/DeleteCommentConfirm.html
Normal 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 %}
|
||||
@@ -7,7 +7,7 @@
|
||||
<h3>You sure about this chief??</h3>
|
||||
{% endblock %}
|
||||
{% 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.
|
||||
{% endblock %}
|
||||
{% block primarybutton %}Cancel{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user