Commit 57b935ed authored by gijs's avatar gijs

Merge branch 'master' of gitlab.constantvzw.org:osp/work.w

parents b8ddfedb 2b2d3696
......@@ -29,8 +29,7 @@ class Score(models.Model):
stage_set = models.TextField(blank=True)
duration = models.TextField(blank=True)
genre = models.TextField(blank=True)
tags = models.TextField(blank=True)
tags = TaggableManager()
tags = TaggableManager(blank=True)
mainline = JSONField(blank=True)
language = models.TextField(blank=True)
......
......@@ -52,11 +52,11 @@ class PermissionSerializer(serializers.Serializer):
list_serializer_class = PermissionListSerializer
class ScoreSerializer(TaggitSerializer, serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField()
tags = TagListSerializerField()
tags = TagListSerializerField(required=False)
permissions = PermissionSerializer(source="*", many=True)
is_editable = serializers.SerializerMethodField()
class Meta:
model = Score
......@@ -68,6 +68,9 @@ class ScoreSerializer(TaggitSerializer, serializers.HyperlinkedModelSerializer):
assign_perm("view_score", self.context['request'].user, instance)
return instance
def get_is_editable(self, obj):
return self.context['request'].user.has_perm('change_score', obj)
def update(self, instance, validated_data):
instance = super(ScoreSerializer, self).update(instance, validated_data)
......
This diff is collapsed.
......@@ -6,23 +6,33 @@ window.W = window.W || {};
(function(undefined) {
'use strict';
function is_external_link(el) {
return ('external' in el.dataset);
}
W.ScoreApp = new Marionette.Application({
W.ScoreApp = Marionette.Application.extend({
region: 'body',
triggers: {
keydown: 'keydown'
},
channelName:'user',
onStart: function(options) {
var userAuthModel = new W.UserAuthModel();
var baseView = new W.BaseView({model: userAuthModel});
var channel = this.getChannel();
var radio = this.getChannel();
this.model = new W.UserAuthModel();
// this.listenTo(this.model, 'change', function() { radio.trigger('change', this.model); });
// this.listenTo(this.model, 'change', function() {
// var view = this.getView();
// // console.log(view);
// // view.destroy();
// // var baseView = new W.BaseView({model: this.model});
// // this.showView(baseView);
// });
var baseView = new W.BaseView({model: this.model});
this.showView(baseView);
userAuthModel.fetch();
baseView.model.fetch();
// hide modals when typing escape
$(document).on("keydown", function(event) {
if (event.keyCode == 27) {
......@@ -34,7 +44,7 @@ window.W = window.W || {};
$(document).on("click", "a", function(e) {
// Do not interfere with Backbone Paginator.
if (! e.isDefaultPrevented() && !is_external_link(e.target)) {
if (! e.isDefaultPrevented() && ! W.utils.is_external_link(e.target)) {
e.preventDefault(); // This is important
var href = $(e.currentTarget).attr('href');
......
;
window.W = window.W || {};
(function (undefined) {
'use strict';
W.ToggableBehavior = Marionette.Behavior.extend({
ui: {
'toggle': '.panel__toggle',
},
triggers: {
'click @ui.toggle': 'toggle',
},
onShow: function () {
this.$el.removeClass('is-collapsed');
},
onHide: function () {
// console.log("hiding");
this.$el.addClass('is-collapsed');
},
onToggle: function () {
this.$el.toggleClass('is-collapsed');
},
});
W.ModalBehavior = Marionette.Behavior.extend({
ui: {
'close': '.btn-close',
'submit': '.btn-submit',
'register': '.js-register',
},
triggers: {
'click @ui.close': 'hide:modal',
'click @ui.submit': 'submit',
'click @ui.register': 'show:register',
},
});
})();
......@@ -8,6 +8,8 @@ window.W = window.W || {};
W.ScoreController = Marionette.MnObject.extend({
home: function () {
document.title = 'Organon';
var baseView = this.getOption('application').getView();
var view = new W.HomeView();
baseView.showChildView('main', view);
......@@ -17,6 +19,8 @@ window.W = window.W || {};
about: function () {
document.title = 'Organon: La notation W';
var baseView = this.getOption('application').getView();
var view = new W.AboutView();
baseView.showChildView('main', view);
......@@ -25,6 +29,8 @@ window.W = window.W || {};
userList: function () {
document.title = 'Organon: liste des utilisateurs';
var baseView = this.getOption('application').getView();
var view = new W.UserListView();
baseView.showChildView('main', view);
......@@ -34,6 +40,8 @@ window.W = window.W || {};
userDetail: function () {
document.title = 'Organon: liste des partitions de l\'utilisateur';
var baseView = this.getOption('application').getView();
var view = new W.UserDetailView();
baseView.showChildView('main', view);
......@@ -43,16 +51,20 @@ window.W = window.W || {};
scoreList: function () {
document.title = 'Organon: liste des partitions';
var baseView = this.getOption('application').getView();
var view = new W.ScoreListView();
baseView.showChildView('main', view);
baseView.getChildView('help').triggerMethod("hide");
baseView.getChildView('header').triggerMethod("hide");
// baseView.getChildView('header').triggerMethod("show");
},
scoreDetail: function (id) {
document.title = 'Organon: partition';
var baseView = this.getOption('application').getView();
// Backbone relational refuse to instantiate more than one model
......
......@@ -32,5 +32,6 @@ window.W = window.W || {};
W.config.lang = W.utils.getUserLanguage();
var scoreApp = W.ScoreApp.start();
var scoreApp = new W.ScoreApp();
scoreApp.start();
})();
......@@ -205,7 +205,6 @@ window.W = window.W || {};
// console.log(data);
return data;
},
});
......@@ -279,6 +278,16 @@ window.W = window.W || {};
return 1;
},
getEditable: function () {
var parent = this.get('parent');
if (parent && parent.getEditable) {
return parent.getEditable();
}
return this.get("score").get("is_editable");
},
getDepth: function () {
return _.reduce(this.get('sublines').models, function (depth, line) { return Math.max(line.getDepth(), depth); }, 0) + 1;
},
......
......@@ -6,6 +6,11 @@ window.W.utils = window.W.utils || {};
(function (undefined) {
'use strict';
W.utils.is_external_link = function (el) {
// data-external is used for attachments
return (el.host !== window.location.host) || ('external' in el.dataset);
};
W.utils.animatedScroll = function (el, distance, duration) {
var start = Date.now(),
......@@ -40,7 +45,7 @@ window.W.utils = window.W.utils || {};
W.utils.translate = window.t = function (string) {
if (!(W.config.lang in W.lang)) {
console.log(W.config.lang + " n'est pas une langue defini. On passe au français");
// console.log(W.config.lang + " n'est pas une langue defini. On passe au français");
W.config.lang = "fr"
};
......@@ -49,7 +54,7 @@ window.W.utils = window.W.utils || {};
if (string in entries) {
return entries[string];
} else {
console.log(string + " n'est pas traduit");
// console.log(string + " n'est pas traduit");
return string;
}
}
......
This diff is collapsed.
......@@ -185,6 +185,7 @@
<script src="{% static 'playground/js/extendedTemplate.js' %}"></script>
<script src="{% static 'playground/js/models.js' %}"></script>
<script src="{% static 'playground/js/collections.js' %}"></script>
<script src="{% static 'playground/js/behaviors.js' %}"></script>
<script src="{% static 'playground/js/views.js' %}"></script>
<script src="{% static 'playground/js/controllers.js' %}"></script>
<script src="{% static 'playground/js/routers.js' %}"></script>
......
<% if (search) { %>
Résultats pour: <%- search %>
Résultats pour: <span class="btn-filter" data-filter="search" data-value="<% search %>"><span class="btn-filter__label"><%- ('terme') %></span>:<%- search %> [x]</span>
<% } %>
<% if (language) { %>
<span class="btn-filter" data-filter="language" data-value="<%- language %>"><span class="btn-filter__label"><%- ('Langue') %></span>:<%- language %> [x]</span>
<span class="btn-filter" data-filter="language" data-value="<%- language %>"><span class="btn-filter__label"><%- ('langue') %></span>:<%- language %> [x]</span>
<% } if (score_type) { %>
<span class="btn-filter" data-filter="score_type" data-value="<%- score_type %>"><span class="btn-filter__label"><%- ('Type de partition') %></span>:
<span class="btn-filter" data-filter="score_type" data-value="<%- score_type %>"><span class="btn-filter__label"><%- ('type') %></span>:
<% if (score_type === 1) { %>
<%- t('Transcription') %>
<%- t('transcription') %>
<% } else if (score_type === 2) { %>
<%- t('Prescription') %>
<%- t('prescription') %>
<% } else if (score_type === 3) { %>
<%- t('Traduction') %>
<%- t('traduction') %>
<% } %>
[x]
</span>
<% } if (tags) { %>
<span class="btn-filter" data-filter="tags" data-value="<%- tags %>"><span class="btn-filter__label"><%- ('Tags') %></span>:<%- tags %> [x]</span>
<span class="btn-filter" data-filter="tags" data-value="<%- tags %>"><span class="btn-filter__label"><%- ('tags') %></span>:<%- tags %> [x]</span>
<% } %>
<a href="#"><%- t('Créer une nouvelle partition') %></a>
<h1 class="create__heading"><a href="#"><%- t('Créer une partition') %></a></h1>
<form class="create-form" action="" method="post">
<input type="text" name="title" placeholder="<%- t('Titre') %>" required>
<input type="submit" name="submit" value="<%- t('Créer') %>">
<form class="create__form create__form--inactive panel-form" action="" method="post">
<input class="create__textfield panel-form__textfield" type="text" name="title" placeholder="<%- t('Titre') %>" required>
<input class="create__submit panel-form__submit" type="submit" name="submit" value="<%- t('Créer') %>">
</form>
<label><span class="label-text"><%- t('Titre') %></span><input type="text" name="title" ></label>
<label><span class="label-text"><%- t('Fiche') %></span><input type="file" name="file" ></label>
\ No newline at end of file
<label><span class="label-text"><%- t('Pièce-jointe') %></span><input type="file" name="file" ></label>
......@@ -2,5 +2,5 @@
<label><span class="label-text"><%- t('Titre') %></span><input type="text" name="title" value="<%- title %>" /></label><a href="<%- attachment %>">Link</a><button>supprimer</delete>
<% } else { %>
<label><span class="label-text"><%- t('Titre') %></span><input type="text" name="title" ></label>
<label><span class="label-text"><%- t('Fiche') %></span><input type="file" name="file" ></label>
<% } %>
\ No newline at end of file
<label><span class="label-text"><%- t('Pièce-jointe') %></span><input type="file" name="file" ></label>
<% } %>
<div class="panel__toggle js-toggle">menu</div>
<div class="content">
<div class="main-header__content content">
<div class="main-header__logo logo">
<h1 class="logo__name"><a href="/" class="logo_link">Organon</a></h1>
<p class="logo__tagline"><%- t('Un logiciel pour noter l’action performée') %></p>
</div>
<nav class="main-header__menu main-header__menu--primary">
<ul>
<li><a href="/la-notation-w/"><%- t('La notation W') %></a></li>
<li><a href="/partitions/"><%- t('Répertoire de partitions') %></a></li>
</ul>
</nav>
<div id="create"></div>
<nav class="main-header__user">
<% if (username) { %>
<%- t('Bienvenue') %> <a href="/compte"><%- username %></a>
<%- t('Bienvenue') %> <a href="/compte"><%- username %></a> <a href="#" class="js-logout">(←)</a>
<% } %>
<ul>
<% if (username) { %>
<li><a href="#" class="js-logout"><%- t('Se déconnecter') %></a></li>
<!-- <li><a href="#" class="js-logout"><%- t('Se déconnecter') %></a></li> -->
<% } else { %>
<li><a href="#" class="js-login"><%- t('Se connecter') %></a> <a href="#" class="js-register"><%- t('S’inscrire') %></a></li>
<li><a href="#" class="js-login"><%- t('Se connecter') %></a> <!--<a href="#" class="js-register"><%- t('S’inscrire') %></a>--></li>
<% } %>
</ul>
</nav>
<div class="main-header__logo logo">
<h1 class="logo__name"><a href="/" class="logo_link">Organon</a></h1>
<p class="logo__tagline"><%- t('Un logiciel pour noter l’action performée.') %></p>
</div>
<nav class="main-header__menu">
<ul>
<li><a href="/la-notation-w/"><%- t('La notation W') %></a></li>
<li><a href="/partitions/"><%- t('Repertoire de partitions') %></a></li>
<li id="create"></li>
<li><a href="#" class="js-lang" data-lang="en">en</a> <a href="#" class="js-lang" data-lang="fr">fr</a></li>
<li><a href="#"><%- t('Crédits') %></a></li>
<li><a href="#"><%- t('Site W') %></a></li>
<nav class="main-header__menu main-header__menu--secondary menu menu--inline">
<ul class="menu__list">
<% if (W.config.lang === "fr") { %>
<li class="menu__item"><a href="#" class="js-lang" data-lang="en">English</a></li>
<% } else { %>
<li class="menu__item"><a href="#" class="js-lang" data-lang="fr">Français</a></li>
<% } %>
<li class="menu__item"><a href="#"><%- t('Crédits') %></a></li>
<li class="menu__item"><a href="http://1110111.org"><%- t('Site W') %></a></li>
</ul>
</nav>
</div>
......@@ -11,14 +11,9 @@
<br>
<section>
<h1><%- t('Le choix de W') %></h1>
<br>
<div id="latest_updated"></div>
<br>
<br>
<h1><%- t('Mes partitions') %></h1>
<br>
<div id="user_scores"></div>
</section>
......@@ -17,6 +17,7 @@
</p>
<p style="text-align: right; margin-top: 1em">
<a href="#" class="js-register" style="float: left;"><%- t('S’inscrire') %></a>
<input type="submit" class="btn-submit" value="<%- t('se connecter') %>" />
</p>
</form>
......
<fieldset>
<% if (parent) { %>
<label>
<span class="label-text">Tag</span>
<span class="label-text"><%- t('Opérateur') %></span>
<select name="tag">
<% _.each(tagChoices, function(t) {%>
<option value="<%= t %>" <% if (tag===t) { %>selected<% } %>><%= t %></option>
......@@ -59,6 +59,9 @@
<%- t('axe modulé') %>
</label>
<!-- attachments -->
<section data-name="attachment"></section>
<!-- actant -->
<label><span class="label-text"><%- t('Actant') %></span>
<input type="text" name="actant" value="<%- actant %>">
......@@ -68,9 +71,6 @@
<label><span class="label-text"><%- t('Adresse') %></span>
<input type="text" name="adresse" value="<%- adresse %>">
</label>
<!-- attachments -->
<section data-name="attachment"></section>
</fieldset>
<fieldset name="extra-fields">
......
<!-- Title -->
<label>
<span class="label-text"><%- t('Titre') %>:</span>
<input type="text" name="title" value="<%- title %>">
<input type="text" name="title" value="<%- title %>" required>
</label>
<!-- description -->
......
<a href="/partitions/<%- id %>"><%- title %></a> &mdash;
<span class="score-list-foo__meta">
<a class="item__title" href="/partitions/<%- id %>"><%- title %></a> &mdash;
<span class="item__meta">
<% if (score_author) { %> par <%- score_author %>, <% } %>
le <%- humanDate %>
<% if (tags.length) { %> <br> <% } %>
<% for (var i = 0; i < tags.length; i++) { %>
#<%- tags[i] %>
<% } %>
......
<div class="scores content">
<h1><%- t('Partitions existantes') %></h1>
<br>
<div class="scores__content content">
<h1 class="scores__heading"><%- t("Partitions existantes") %></h1>
<div id="foo"></div>
<div id="list"></div>
</div>
<div id="search-panel" class="score-filters panel panel--right"></div>
<div id="search-panel"></div>
<article>
<article class="<% if (!is_editable) { %>read-only<% } %>">
<header id="sidebar">
<h1 id="title"><%- title %></h1>
<div class="score-actions">
<button class="save" data-label-progress="<%- t('Enregistrer…') %>" data-label="<%- t('Enregistrer') %>" <% if (!hasChanges) { %>disabled<% } %>><%- t('Enregistrer') %></button>
......@@ -8,8 +9,6 @@
<!--<button data-name="export"><%- t('Export') %></button>-->
</div>
<h1 id="title"><%- title %></h1>
</header>
<div id="main-area">
......@@ -21,31 +20,36 @@
</article>
<aside class="panel__alt panel--score-meta <% if (!metaExpanded) { %>is-collapsed<% } %>">
<span class="panel__toggle__alt js-toggle"><%- t('Infos') %></span>
<span class="panel__toggle__alt js-toggle"><%- t('infos') %></span>
<section class="content">
<button class="edit score-edit"><%- t('Éditer') %></button>
<dl class="score-meta">
<% if (presentation) { %>
<dt><%- t('Présentation') %></dt>
<dt class="score-meta__term"><%- t('Présentation') %></dt>
<dd><%- presentation %></dd>
<% } %>
<% if (stage_set) { %>
<dt><%- t('Mise') %></dt>
<dt class="score-meta__term"><%- t('Mise') %></dt>
<dd><%= stage_set.replace(/\n/g, "<br />") %></dd>
<% } %>
</dl>
<dl class="score-meta">
<!-- Extended fields -->
<% if (performance_author && (score_type === 1 || score_type === 3)) { %>
<dt class="extended"><%- t('Auteur de la performance') %></dt>
<dd class="extended"><%- performance_author %></dd>
<dt class="score-meta__term"><%- t('Auteur de la performance') %></dt>
<dd><%- performance_author %></dd>
<% } %>
<% if (score_author) { %>
<dt class="extended"><%- t('Auteur de la partition') %></dt>
<dd class="extended"><%- score_author %></dd>
<dt class="score-meta__term"><%- t('Auteur de la partition') %></dt>
<dd><%- score_author %></dd>
<% } %>
<% if (score_type) { %>
<dt class="extended"><%- t('Type de partition') %></dt>
<dd class="extended">
<dt class="score-meta__term"><%- t('Type de partition') %></dt>
<dd>
<% switch (score_type) {
case 1:
%>
......@@ -65,48 +69,48 @@
} %>
</dd>
<% } %>
<dt class="extended"><%- t('Effectif') %></dt>
<dd class="extended">
<% if (effectif && effectif !== "") { %>
<dt class="score-meta__term"><%- t('Effectif') %></dt>
<dd>
<% if (effectif && effectif.type === rangeType.exact) { %>
<%- effectif.value %> <%- (effectif.value > 1) ? t('performeurs') : t('performeur') %>
<% } else if (effectif && effectif.type === rangeType.minimal) { %>
<%- t('au moins') %> <%- effectif.value %> <%- t('performeurs') %>
<% } else if (effectif && effectif.type === rangeType.range) { %>
<%- t('entre') %> <%- effectif.value[0] %> ét <%- effectif.value[1] %> <%- t('performeurs') %>
<%- t('entre') %> <%- effectif.value[0] %> et <%- effectif.value[1] %> <%- t('performeurs') %>
<% } else { %>
<%- t('indéterminé') %>
<% } %>
</dd>
<% } %>
<% if (duration) { %>
<dt class="extended"><%- t('Durée') %></dt>
<dd class="extended"><%- duration %></dd>
<dt class="score-meta__term"><%- t('Durée') %></dt>
<dd><%- duration %></dd>
<% } %>
<% if (tags) { %>
<dt class="extended"><%- t('Tags') %></dt>
<dd class="extended">
<ul>
<%
tag_list = tags;
for (var i=0; i < tag_list.length; i++) { %>
<li><%- tag_list[i] %></li>
<% if (tags && tags.length) { %>
<dt class="score-meta__term score-meta__term--hidden"><%- t('Tags') %></dt>
<dd>
<ul>
<% for (var i=0; i < tags.length; i++) { %>
<li class="score-meta__tag-item">#<%- tags[i] %></li>
<% } %>
</ul>
</dd>
<% } %>
<!--
<% if (genre) { %>
<dt class="extended"><%- t('Genre') %></dt>
<dd class="extended"><%- genre %></dd>
<dt><%- t('Genre') %></dt>
<dd><%- genre %></dd>
<% } %> -->
<% if (language) { %>
<dt class="extended"><%- t('Langue') %></dt>
<dd class="extended"><%- language %></dd>
<% } %>
<dt class="extended"><%- t('Publié le') %></dt>
<dd class="extended"><%- formatTimestamp(created_at) %></dd>
<dt class="extended"><%- t('Modifié le') %></dt>
<dd class="extended"><%- formatTimestamp(updated_at) %></dd>
<dt class="score-meta__term score-meta__term--inline"><%- t('Publié le') %></dt>
<dd><%- formatTimestamp(created_at) %></dd>
<dt class="score-meta__term score-meta__term--inline"><%- t('Modifié le') %></dt>
<dd><%- formatTimestamp(updated_at) %></dd>
<!-- <dt class="score-meta-expand-toggle"></dt> -->
</dl>
......@@ -115,4 +119,4 @@
<form></form>
</section>
</aside>
\ No newline at end of file
</aside>
<div class="panel__toggle js-collapse">filtres</div>
<div class="content">
<div id="search"></div>
<div id="applied-filters"></div>
<div class="filters">
<div class="filters__filter">
<p><%- t('type de partition') %></p>
<div id="score-type-filter"></div>
</div>
<div id="score-type-filter"></div>
<div class="filters__filter">
<p><%- t('tags') %></p>
<div id="tag-filter"></div>
</div>
<div id="tag-filter"></div>
<div class="filters__filter">
<p><%- t('langue') %></p>
<div id="language-filter"></div>
</div>
</div>
<div id="language-filter"></div>
</div>
<form class="search__form" action="search_submit" method="get" accept-charset="utf-8">
<input class="search__textfield search-input" type="text" placeholder="<%- t('Titre ou auteur') %>">
<button class="search"><%- t('rechercher') %></button>
<h1 class="search__heading">Recherche</h1>
<form class="search__form panel-form" action="search_submit" method="get" accept-charset="utf-8">
<input class="search__textfield search-input panel-form__textfield" type="text" placeholder="<%- t('Titre ou auteur') %>">
<button class="search__submit panel-form__submit"><%- t('Ok') %></button>
</form>
......@@ -150,12 +150,15 @@ class ScoreViewSet(viewsets.ModelViewSet):
shared_with = self.request.query_params.get('shared_with', None)
if shared_with is not None:
queryset = get_objects_for_user(self.request.user, 'playground.view_score')
# Do not return scores for AnonymousUser
if (self.request.user.is_anonymous()):
return queryset.none()
return get_objects_for_user(self.request.user, 'playground.view_score')
is_featured = self.request.query_params.get('is_featured', None)
is_featured= self.request.query_params.get('is_featured', None)
if is_featured is not None:
ids = FeaturedScore.objects.all().order_by('-order').values_list("score__id", flat=True)
queryset = queryset.filter(id__in=ids)
return queryset.filter(id__in=ids)
return queryset
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment