From 42256c71e16eef1bb9613e34bd0b2ed94d5a2a21 Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Fri, 17 Mar 2017 16:59:18 +0100 Subject: [PATCH] Delete Bibtool-draft codebase Deleted all bibtool-draft codebase, including templates, models, views, routes, etc. Migration is included to update the database --- scipost/admin.py | 63 +---- scipost/forms.py | 84 +----- scipost/migrations/0040_auto_20170317_1659.py | 106 +++++++ scipost/models.py | 227 --------------- .../templates/scipost/add_team_member.html | 40 --- scipost/templates/scipost/create_graph.html | 22 -- scipost/templates/scipost/create_list.html | 22 -- scipost/templates/scipost/create_team.html | 30 -- .../templates/scipost/edit_graph_node.html | 27 -- scipost/templates/scipost/graph.html | 263 ----------------- scipost/templates/scipost/list.html | 103 ------- scipost/urls.py | 27 -- scipost/views.py | 264 ------------------ 13 files changed, 113 insertions(+), 1165 deletions(-) create mode 100644 scipost/migrations/0040_auto_20170317_1659.py delete mode 100644 scipost/templates/scipost/add_team_member.html delete mode 100644 scipost/templates/scipost/create_graph.html delete mode 100644 scipost/templates/scipost/create_list.html delete mode 100644 scipost/templates/scipost/create_team.html delete mode 100644 scipost/templates/scipost/edit_graph_node.html delete mode 100644 scipost/templates/scipost/graph.html delete mode 100644 scipost/templates/scipost/list.html diff --git a/scipost/admin.py b/scipost/admin.py index ccb5be7f2..7151b023f 100644 --- a/scipost/admin.py +++ b/scipost/admin.py @@ -3,13 +3,11 @@ from django.contrib import admin from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User, Permission -from guardian.admin import GuardedModelAdmin - -from scipost.models import Contributor, Remark, List,\ - DraftInvitation, Node, Arc, Graph, Team, AffiliationObject,\ +from scipost.models import Contributor, Remark,\ + DraftInvitation,\ + AffiliationObject,\ SupportingPartner, SPBMembershipAgreement, RegistrationInvitation,\ AuthorshipClaim, PrecookedEmail -from virtualmeetings.models import VGM, Feedback, Nomination, Motion class ContributorInline(admin.StackedInline): @@ -27,34 +25,6 @@ admin.site.unregister(User) admin.site.register(User, UserAdmin) -# class VGMAdmin(admin.ModelAdmin): -# search_fields = ['start_date'] -# -# -# admin.site.register(VGM, VGMAdmin) -# -# -# class FeedbackAdmin(admin.ModelAdmin): -# search_fields = ['feedback', 'by'] -# -# -# admin.site.register(Feedback, FeedbackAdmin) -# -# -# class NominationAdmin(admin.ModelAdmin): -# search_fields = ['last_name', 'first_name', 'by'] -# -# -# admin.site.register(Nomination, NominationAdmin) -# -# -# class MotionAdmin(admin.ModelAdmin): -# search_fields = ['background', 'motion', 'put_forward_by'] -# -# -# admin.site.register(Motion, MotionAdmin) - - class RemarkAdmin(admin.ModelAdmin): search_fields = ['contributor', 'remark'] @@ -87,33 +57,6 @@ class PrecookedEmailAdmin(admin.ModelAdmin): admin.site.register(PrecookedEmail, PrecookedEmailAdmin) -class ListAdmin(GuardedModelAdmin): - search_fields = ['owner', 'title'] - - -admin.site.register(List, ListAdmin) -admin.site.register(Team) - - -class NodeInline(admin.StackedInline): - model = Node - - -class ArcInline(admin.StackedInline): - model = Arc - - -class GraphAdmin(GuardedModelAdmin): - inlines = [ - NodeInline, - ArcInline, - ] - search_fields = ['owner___user__last_name', 'title'] - - -admin.site.register(Graph, GraphAdmin) - - class AffiliationObjectAdmin(admin.ModelAdmin): search_fields = ['country', 'institution', 'subunit'] diff --git a/scipost/forms.py b/scipost/forms.py index b1fb349c3..221291d04 100644 --- a/scipost/forms.py +++ b/scipost/forms.py @@ -1,7 +1,6 @@ from django import forms from django.contrib.auth.models import User, Group -from django.db.models import Q from django_countries import countries from django_countries.widgets import CountrySelectWidget @@ -12,11 +11,10 @@ from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout, Div, Field, HTML, Submit from .constants import SCIPOST_DISCIPLINES, SCIPOST_SUBJECT_AREAS -from .models import TITLE_CHOICES, SCIPOST_FROM_ADDRESSES, ARC_LENGTHS,\ - Contributor, DraftInvitation, RegistrationInvitation,\ - SupportingPartner, SPBMembershipAgreement,\ - UnavailabilityPeriod, PrecookedEmail,\ - List, Team, Graph, Node +from .models import TITLE_CHOICES, SCIPOST_FROM_ADDRESSES,\ + Contributor, DraftInvitation, RegistrationInvitation,\ + SupportingPartner, SPBMembershipAgreement,\ + UnavailabilityPeriod, PrecookedEmail from virtualmeetings.models import Feedback, Nomination, Motion from journals.models import Publication @@ -260,80 +258,6 @@ class SendPrecookedEmailForm(forms.Form): from_address = forms.ChoiceField(choices=SCIPOST_FROM_ADDRESSES) -class CreateListForm(forms.ModelForm): - class Meta: - model = List - fields = ['title', 'description', 'private'] - - def __init__(self, *args, **kwargs): - super(CreateListForm, self).__init__(*args, **kwargs) - self.fields['title'].widget.attrs.update( - {'size': 30, 'placeholder': 'Descriptive title for the new List'}) - self.fields['private'].widget.attrs.update({'placeholder': 'Private?'}) - - -class CreateTeamForm(forms.ModelForm): - class Meta: - model = Team - fields = ['name'] - - def __init__(self, *args, **kwargs): - super(CreateTeamForm, self).__init__(*args, **kwargs) - self.fields['name'].widget.attrs.update( - {'size': 30, 'placeholder': 'Descriptive name for the new Team'}) - - -class AddTeamMemberForm(forms.Form): - def __init__(self, *args, **kwargs): - super(AddTeamMemberForm, self).__init__(*args, **kwargs) - self.fields['last_name'].widget.attrs.update( - {'size': 20, 'placeholder': 'Search in contributors database'}) - - last_name = forms.CharField() - - -class CreateGraphForm(forms.ModelForm): - class Meta: - model = Graph - fields = ['title', 'description', 'private'] - - def __init__(self, *args, **kwargs): - super(CreateGraphForm, self).__init__(*args, **kwargs) - self.fields['title'].widget.attrs.update( - {'size': 30, 'placeholder': 'Descriptive title for the new Graph'}) - self.fields['description'].widget.attrs.update({'placeholder': 'Detailed description'}) - - -class ManageTeamsForm(forms.Form): - teams_with_access = forms.ModelMultipleChoiceField(queryset=None) - - def __init__(self, *args, **kwargs): - contributor = kwargs.pop('contributor') - super(ManageTeamsForm, self).__init__(*args, **kwargs) - self.fields['teams_with_access'].queryset = Team.objects.filter( - Q(leader=contributor) | Q(members__in=[contributor])) - self.fields['teams_with_access'].widget.attrs.update( - {'placeholder': 'Team(s) to be given access rights:'}) - - -class CreateNodeForm(forms.ModelForm): - class Meta: - model = Node - fields = ['name', 'description'] - - -class CreateArcForm(forms.Form): - source = forms.ModelChoiceField(queryset=None) - target = forms.ModelChoiceField(queryset=None) - length = forms.ChoiceField(choices=ARC_LENGTHS) - - def __init__(self, *args, **kwargs): - graph = kwargs.pop('graph') - super(CreateArcForm, self).__init__(*args, **kwargs) - self.fields['source'].queryset = Node.objects.filter(graph=graph) - self.fields['target'].queryset = Node.objects.filter(graph=graph) - - ############################# # Supporting Partners Board # ############################# diff --git a/scipost/migrations/0040_auto_20170317_1659.py b/scipost/migrations/0040_auto_20170317_1659.py new file mode 100644 index 000000000..69ce2c10f --- /dev/null +++ b/scipost/migrations/0040_auto_20170317_1659.py @@ -0,0 +1,106 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-03-17 15:59 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('scipost', '0039_auto_20170306_0804'), + ] + + operations = [ + migrations.RemoveField( + model_name='arc', + name='added_by', + ), + migrations.RemoveField( + model_name='arc', + name='graph', + ), + migrations.RemoveField( + model_name='arc', + name='source', + ), + migrations.RemoveField( + model_name='arc', + name='target', + ), + migrations.RemoveField( + model_name='graph', + name='owner', + ), + migrations.RemoveField( + model_name='graph', + name='teams_with_access', + ), + migrations.RemoveField( + model_name='list', + name='commentaries', + ), + migrations.RemoveField( + model_name='list', + name='comments', + ), + migrations.RemoveField( + model_name='list', + name='owner', + ), + migrations.RemoveField( + model_name='list', + name='submissions', + ), + migrations.RemoveField( + model_name='list', + name='teams_with_access', + ), + migrations.RemoveField( + model_name='list', + name='thesislinks', + ), + migrations.RemoveField( + model_name='node', + name='added_by', + ), + migrations.RemoveField( + model_name='node', + name='commentaries', + ), + migrations.RemoveField( + model_name='node', + name='graph', + ), + migrations.RemoveField( + model_name='node', + name='submissions', + ), + migrations.RemoveField( + model_name='node', + name='thesislinks', + ), + migrations.RemoveField( + model_name='team', + name='leader', + ), + migrations.RemoveField( + model_name='team', + name='members', + ), + migrations.DeleteModel( + name='Arc', + ), + migrations.DeleteModel( + name='Graph', + ), + migrations.DeleteModel( + name='List', + ), + migrations.DeleteModel( + name='Node', + ), + migrations.DeleteModel( + name='Team', + ), + ] diff --git a/scipost/models.py b/scipost/models.py index 119cd4ca9..80d0640e6 100644 --- a/scipost/models.py +++ b/scipost/models.py @@ -428,233 +428,6 @@ class PrecookedEmail(models.Model): return self.email_subject -######### -# Lists # -######### - -class List(models.Model): - """ - A collection of commentaries, submissions, thesislinks, comments, etc - defined by a Contributor, for use in Graphs, etc - """ - owner = models.ForeignKey(Contributor, on_delete=models.CASCADE) - private = models.BooleanField(default=True) - teams_with_access = models.ManyToManyField('scipost.Team', blank=True) - title = models.CharField(max_length=100) - description = models.TextField(blank=True, null=True) - created = models.DateTimeField(default=timezone.now) - submissions = models.ManyToManyField('submissions.Submission', blank=True, - related_name='list_submissions') - commentaries = models.ManyToManyField('commentaries.Commentary', blank=True, - related_name='list_commentaries') - thesislinks = models.ManyToManyField('theses.ThesisLink', blank=True, - related_name='list_thesislinks') - comments = models.ManyToManyField('comments.Comment', blank=True, - related_name='list_comments') - - class Meta: - default_permissions = ['add', 'view', 'change', 'delete'] - - def __str__(self): - return '%s (owner: %s %s)' % (self.title[:30], - self.owner.user.first_name, self.owner.user.last_name) - - def header(self): - context = Context({'id': self.id, 'title': self.title, - 'first_name': self.owner.user.first_name, - 'last_name': self.owner.user.last_name}) - template = Template(''' - <p>List <a href="{% url 'scipost:list' list_id=id %}">{{ title }} - </a> (owner: {{ first_name }} {{ last_name }})</p> - ''') - return template.render(context) - - def header_as_li(self): - context = Context({'id': self.id, 'title': self.title, - 'first_name': self.owner.user.first_name, - 'last_name': self.owner.user.last_name}) - template = Template(''' - <li><p>List <a href="{% url 'scipost:list' list_id=id %}"> - {{ title }}</a> (owner: {{ first_name }} {{ last_name }})</p></li> - ''') - return template.render(context) - - def contents(self): - context = Context({}) - output = '<p>' + self.description + '</p>' - output += '<hr class="hr6"/>' - emptylist = True - if self.submissions.exists(): - emptylist = False - output += '<p>Submissions:<ul>' - for submission in self.submissions.all(): - output += submission.simple_header_as_li() - output += '</ul></p>' - if self.commentaries.exists(): - emptylist = False - output += '<p>Commentaries:<ul>' - for commentary in self.commentaries.all(): - output += commentary.simple_header_as_li() - output += '</ul></p>' - if self.thesislinks.exists(): - emptylist = False - output += '<p>Thesislinks:<ul>' - for thesislink in self.thesislinks.all(): - output += thesislink.simple_header_as_li() - output += '</ul></p>' - if self.comments.exists(): - emptylist = False - output += '<p>Comments:<ul>' - for comment in self.comments.all(): - output += comment.simple_header_as_li() - output += '</ul></p>' - if emptylist: - output += '<br/><h3>This List is empty.</h3>' - template = Template(output) - return template.render(context) - - -######### -# Teams # -######### - -class Team(models.Model): - """ - Team of Contributors, to enable private collaborations. - """ - leader = models.ForeignKey(Contributor, on_delete=models.CASCADE) - members = models.ManyToManyField(Contributor, blank=True, related_name='team_members') - name = models.CharField(max_length=100) - established = models.DateField(default=timezone.now) - - class Meta: - default_permissions = ['add', 'view', 'change', 'delete'] - - def __str__(self): - return (self.name + ' (led by ' + self.leader.user.first_name + ' ' - + self.leader.user.last_name + ')') - - def header_as_li(self): - context = Context({'name': self.name, }) - output = ('<li><p>Team {{ name }}, led by ' + self.leader.user.first_name + ' ' - + self.leader.user.last_name + '</p>') - output += '<p>Members: ' - if not self.members.all(): - output += '(none yet, except for the leader)' - else: - for member in self.members.all(): - output += member.user.first_name + ' ' + member.user.last_name + ', ' - output += '</p></li>' - template = Template(output) - return template.render(context) - - -########## -# Graphs # -########## - -class Graph(models.Model): - """ - A Graph is a collection of Nodes with directed arrows, - representing e.g. a reading list, exploration path, etc. - If private, only the teams in teams_with_access can see/edit it. - """ - owner = models.ForeignKey(Contributor, on_delete=models.CASCADE) - private = models.BooleanField(default=True) - teams_with_access = models.ManyToManyField(Team, blank=True) - title = models.CharField(max_length=100) - description = models.TextField(blank=True, null=True) - created = models.DateTimeField(default=timezone.now) - - class Meta: - default_permissions = ['add', 'view', 'change', 'delete'] - - def __str__(self): - return '%s (owner: %s %s)' % (self.title[:30], - self.owner.user.first_name, self.owner.user.last_name) - - def header_as_li(self): - context = Context({'id': self.id, 'title': self.title, - 'first_name': self.owner.user.first_name, - 'last_name': self.owner.user.last_name}) - template = Template(''' - <li><p>Graph <a href="{% url 'scipost:graph' graph_id=id %}"> - {{ title }}</a> (owner: {{ first_name }} {{ last_name }})</li> - ''') - return template.render(context) - - def contents(self): - context = Context({}) - output = self.description - template = Template(output) - return template.render(context) - - -class Node(models.Model): - """ - Node of a graph (directed). - Each node is composed of a set of submissions, commentaries, thesislinks. - Accessibility rights are set in the Graph ForeignKey. - """ - graph = models.ForeignKey(Graph, on_delete=models.CASCADE, default=None) - added_by = models.ForeignKey(Contributor, on_delete=models.CASCADE, default=None) - created = models.DateTimeField(default=timezone.now) - name = models.CharField(max_length=100) - description = models.TextField(blank=True, null=True) - submissions = models.ManyToManyField('submissions.Submission', blank=True, - related_name='node_submissions') - commentaries = models.ManyToManyField('commentaries.Commentary', blank=True, - related_name='node_commentaries') - thesislinks = models.ManyToManyField('theses.ThesisLink', blank=True, - related_name='node_thesislinks') - - class Meta: - default_permissions = ['add', 'view', 'change', 'delete'] - - def __str__(self): - return self.graph.title[:20] + ': ' + self.name[:20] - - def header_as_p(self): - context = Context({'graph_id': self.graph.id, 'id': self.id, 'name': self.name}) - output = ('<p class="node_p" id="node_id{{ id }}">' - '<a href="{% url \'scipost:graph\' graph_id=graph_id %}">{{ name }}</a></p>') - template = Template(output) - return template.render(context) - - def contents(self): - context = Context({'graph_id': self.graph.id, - 'id': self.id, 'name': self.name, - 'description': self.description}) - output = ('<div class="node_contents node_id{{ id }}">' - + '<h3>{{ name }}</h3><p>{{ description }}</p></div>') - template = Template(output) - return template.render(context) - - def contents_small(self): - output = '<div style="font-size: 60%">' + self.contents + '</div>' - template = Template(output) - return template.render() - - -ARC_LENGTHS = [ - # (4, '4'), (8, '8'), (16, '16'), (32, '32'), (64, '64'), (128, '128') - (1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8'), - ] - - -class Arc(models.Model): - """ - Arc of a graph, linking two nodes. - The length is user-adjustable. - """ - graph = models.ForeignKey(Graph, on_delete=models.CASCADE, default=None) - added_by = models.ForeignKey(Contributor, on_delete=models.CASCADE, default=None) - created = models.DateTimeField(default=timezone.now) - source = models.ForeignKey(Node, on_delete=models.CASCADE, related_name='source') - target = models.ForeignKey(Node, on_delete=models.CASCADE, related_name='target') - length = models.PositiveSmallIntegerField(choices=ARC_LENGTHS, default=32) - - ####################### # Affiliation Objects # ####################### diff --git a/scipost/templates/scipost/add_team_member.html b/scipost/templates/scipost/add_team_member.html deleted file mode 100644 index a8a592cc7..000000000 --- a/scipost/templates/scipost/add_team_member.html +++ /dev/null @@ -1,40 +0,0 @@ -{% extends 'scipost/base.html' %} - -{% block pagetitle %}: add team member{% endblock pagetitle %} - -{% block bodysup %} - -<section> - <h1>Add Members to Team</h1> - <ul> - {{ team.header_as_li }} - </ul> - - {% if contributors_found %} - <h3>Identified as contributor:</h3> - <table> - {% for contributor in contributors_found %} - <tr> - <td>{{ contributor.user.first_name }} {{ contributor.user.last_name }}</td> - <td> </td> - <td><a href="{% url 'scipost:add_team_member' team_id=team.id contributor_id=contributor.id %}">Add to the Team</a></td> - </tr> - {% endfor %} - </table> - {% elif add_team_member_form.has_changed %} - <p>No Contributor with this last name could be identified.</p> - {% else %} - <p>Add a member to the Team:</p> - <form action="{% url 'scipost:add_team_member' team_id=team.id %}" method="post"> - {% csrf_token %} - <table> - {{ add_team_member_form.as_table }} - </table> - <input type="submit" value="Search" /> - </form> - {% endif %} - - -</section> - -{% endblock bodysup %} diff --git a/scipost/templates/scipost/create_graph.html b/scipost/templates/scipost/create_graph.html deleted file mode 100644 index e3c4bc54d..000000000 --- a/scipost/templates/scipost/create_graph.html +++ /dev/null @@ -1,22 +0,0 @@ -{% extends 'scipost/base.html' %} - -{% block pagetitle %}: create graph{% endblock pagetitle %} - -{% block bodysup %} - -<section> - {% if graphcreated %} - <p>{{ message }}</p> - {% else %} - <h1>Create a new Graph</h1> - <form action="{% url 'scipost:create_graph' %}" method="post"> - {% csrf_token %} - <table> - {{ create_graph_form.as_table }} - </table> - <input type="submit" value="Create Graph" /> - </form> - {% endif %} -</section> - -{% endblock bodysup %} diff --git a/scipost/templates/scipost/create_list.html b/scipost/templates/scipost/create_list.html deleted file mode 100644 index 68a59e631..000000000 --- a/scipost/templates/scipost/create_list.html +++ /dev/null @@ -1,22 +0,0 @@ -{% extends 'scipost/base.html' %} - -{% block pagetitle %}: create list{% endblock pagetitle %} - -{% block bodysup %} - -<section> - {% if listcreated %} - <p>{{ message }}</p> - {% else %} - <h1>Create a new List</h1> - <form action="{% url 'scipost:create_list' %}" method="post"> - {% csrf_token %} - <table> - {{ create_list_form.as_table }} - </table> - <input type="submit" value="Create List" /> - </form> - {% endif %} -</section> - -{% endblock bodysup %} diff --git a/scipost/templates/scipost/create_team.html b/scipost/templates/scipost/create_team.html deleted file mode 100644 index 97559b005..000000000 --- a/scipost/templates/scipost/create_team.html +++ /dev/null @@ -1,30 +0,0 @@ -{% extends 'scipost/base.html' %} - -{% block pagetitle %}: create team{% endblock pagetitle %} - -{% block bodysup %} - -<section> - {% if teamcreated %} - <p>{{ message }}</p> - - <form action="{% url 'scipost:add_team_member' team_id=team.id %}" method="post"> - {% csrf_token %} - <table> - {{ add_team_member_form.as_table }} - </table> - <input type="submit" value="Search" /> - </form> - {% else %} - <h1>Create a new collaborative Team</h1> - <form action="{% url 'scipost:create_team' %}" method="post"> - {% csrf_token %} - <table> - {{ create_team_form.as_table }} - </table> - <input type="submit" value="Create Team" /> - </form> - {% endif %} -</section> - -{% endblock bodysup %} diff --git a/scipost/templates/scipost/edit_graph_node.html b/scipost/templates/scipost/edit_graph_node.html deleted file mode 100644 index 09e9db071..000000000 --- a/scipost/templates/scipost/edit_graph_node.html +++ /dev/null @@ -1,27 +0,0 @@ -{% extends 'scipost/base.html' %} - -{% block pagetitle %}: edit graph node{% endblock pagetitle %} - -{% block bodysup %} - -<section> - <h1>Edit Graph Node</h1> - - {% if errormessage %} - <p>{{ errormessage }}</p> - - {% else %} - - <form action="{% url 'scipost:edit_graph_node' node_id=node.id %}" method="post"> - {% csrf_token %} - <table> - {{ edit_node_form.as_table }} - </table> - <input type="submit" value="Submit" /> - </form> - - {% endif %} - -</section> - -{% endblock bodysup %} diff --git a/scipost/templates/scipost/graph.html b/scipost/templates/scipost/graph.html deleted file mode 100644 index 19679c37d..000000000 --- a/scipost/templates/scipost/graph.html +++ /dev/null @@ -1,263 +0,0 @@ -{% extends 'scipost/base.html' %} - -{% block pagetitle %}: graph{% endblock pagetitle %} - -{% block headsup %} - -<style> - - .overlay { - fill: none; - pointer-events: all; - } - -.arc { - fill: none; - stroke: #666; - stroke-width: 1.5px; -} - -circle { - fill: #ccc; - stroke: #333; - stroke-width: 1.5px; -} - -text { - font: 12px sans-serif; - pointer-events: none; - text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, 0 -1px 0 #fff, -1px 0 0 #fff; -} -</style> - -{% endblock headsup %} - -{% block bodysup %} - - -<script src="//d3js.org/d3.v3.min.js"></script> -<script> - -$(document).ready(function(){ - -$(".node_contents").hide(); -$(".delete_node").hide(); - -$("#NodeForm").hide(); -$("#ArcForm").hide(); -$("#ManageTeamsForm").hide(); - -$("#ManageTeamsFormButton").click(function(){ -$("#ManageTeamsForm").toggle(); -$("#NodeForm").hide(); -$("#ArcForm").hide(); -}); - -$("#NodeFormButton").click(function(){ -$("#ManageTeamsForm").hide(); -$("#NodeForm").toggle(); -$("#ArcForm").hide(); -}); - -$("#ArcFormButton").click(function(){ -$("#ManageTeamsForm").hide(); -$("#NodeForm").hide(); -$("#ArcForm").toggle(); -}); -}); - - -d3.json("{% url 'scipost:api_graph' graph_id=graph.id %}", function(error, json) { - if (error) return console.warn(error); - -var nodesjson = json['nodes']; -var nodes = []; -nodesjson.forEach(function(node) { - nodes[node.name] = node; - nodes[node.name].x = 300 + 100 * Math.random(); - nodes[node.name].y = 150 + 100 * Math.random(); -}); - -var arcsjson = json['arcs']; -var arcs = []; -arcsjson.forEach(function(arc) { - arcs[arc.id] = arc; - arcs[arc.id].source = nodes[arc.source]; - arcs[arc.id].target = nodes[arc.target]; - arcs[arc.id].length = arc.length; -}); - -function arclength(arc) { - return arc.length * 50; -} - -var width = 600; -var height = 300; - -var force = d3.layout.force() - .nodes(d3.values(nodes)) -// .links(arcs) - .links(d3.values(arcs)) - .size([width, height]) - .friction(0.9) - .linkStrength(1) -// .linkDistance(80) - .linkDistance(arclength) - .charge(-40) - .gravity(0.1) - .theta(0.8) - .alpha(0.1) - .on("tick", tick) - .start(); - - -var svg = d3.select("#graphic").append("svg") - .attr("width", width) -.attr("height", height) -.append("g") -.call(d3.behavior.zoom().on("zoom", zoom)) -.on("dblclick.zoom", null) -//.on("mousedown.zoom", null) -.append("g"); - -svg.append("rect") -.attr("class", "overlay") -.attr("width", width) -.attr("height", height); - -function zoom() { -svg.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")"); -} - -svg.append("defs").append("marker") - .attr("id", "arrowhead") - .attr("viewBox", "0 -5 10 10") - .attr("refX", 15) - .attr("refY", -1.5) - .attr("markerWidth", 6) - .attr("markerHeight", 6) - .attr("orient", "auto") - .append("path") - .attr("d", "M0,-5L10,0L0,5"); - -var path = svg.append("g").selectAll("path") - .data(force.links()) - .enter().append("path") - .attr("class", "arc") - .attr("marker-end", "url(#arrowhead)"); - -var circle = svg.append("g").selectAll("circle") - .data(force.nodes()) - .enter().append("circle") - .attr("r", 6) - .attr("id", function(d) { return d.id; }) -.call(force.drag); - - -circle.on("click", function(){ - d3.selectAll("circle").style("fill", "#ccc"); - d3.select(this).style("fill", "blue"); - $(".node_contents").hide(); - $(".delete_node").hide(); - $(".node_id" + $(this).attr("id")).show(); -}); - -var text = svg.append("g").selectAll("text") - .data(force.nodes()) - .enter().append("text") - .attr("x", 8) - .attr("y", ".31em") - .text(function(d) { return d.name; }); - -// Use elliptical arc path segments to doubly-encode directionality. -function tick() { - path.attr("d", linkArc); - circle.attr("transform", transform); - text.attr("transform", transform); -} - -function linkArc(d) { - var dx = d.target.x - d.source.x, - dy = d.target.y - d.source.y, - dr = Math.sqrt(dx * dx + dy * dy); - return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y; -} - -function transform(d) { - return "translate(" + d.x + "," + d.y + ")"; -} - - -}); - - -</script> - - - -<section> - <h1>Graph</h1> - {{ graph }} - {% if graph.private %} - <h3>Teams with access:</h3> - <ul> - {% for team in graph.teams_with_access.all %} - {{ team.header_as_li }} - {% endfor %} - </ul> - {% endif %} - - - {% load guardian_tags %} - {% get_obj_perms request.user for graph as "graph_perms" %} - {% if "change_graph" in graph_perms %} - - <div class="row"> - <div class="col-2"> - {% if graph.private %} - <button class="GraphButton" id="ManageTeamsFormButton"><h1>Manage Team(s)</h1></button> - <form action="{% url 'scipost:graph' graph_id=graph.id %}" method="post" id="ManageTeamsForm"> - {% csrf_token %} - {{ attach_teams_form }} - <input type="submit" value="Submit" /> - </form> - {% endif %} - <button class="GraphButton" id="NodeFormButton"><h1>Add a Node</h1></button> - <form action="{% url 'scipost:graph' graph_id=graph.id %}" method="post" id="NodeForm"> - {% csrf_token %} - <table> - {{ create_node_form.as_table }} - </table> - <input type="submit" value="Create Node" /> - </form> - <button class="GraphButton" id="ArcFormButton"><h1>Add an Arc</h1></button> - <form action="{% url 'scipost:graph' graph_id=graph.id %}" method="post" id="ArcForm"> - {% csrf_token %} - <table> - {{ create_arc_form.as_table }} - </table> - <input type="submit" value="Create Arc" /> - </form> - </div> - <div class="col-10"> - <div id="graphic"></div> - </div> - </div> - <hr class="hr6"/> - <br/> - - {% endif %} - - {{ graph.contents }} - - - {% for node in nodes %} - {{ node.contents }} - <a href="{% url 'scipost:edit_graph_node' node_id=node.id %}" class="node_contents node_id{{ node.id }}" style="margin: 10px;">Edit this Node's contents</a> - <a href="{% url 'scipost:delete_graph_node' node_id=node.id %}" class="delete_node node_id{{ node.id }}" style="color: red; margin: 10px;">Delete this Node</a> - {% endfor %} - - -</section> - -{% endblock bodysup %} diff --git a/scipost/templates/scipost/list.html b/scipost/templates/scipost/list.html deleted file mode 100644 index 2ef95a3dd..000000000 --- a/scipost/templates/scipost/list.html +++ /dev/null @@ -1,103 +0,0 @@ -{% extends 'scipost/base.html' %} - -{% block pagetitle %}: list{% endblock pagetitle %} - -{% block headsup %} - -{% endblock headsup %} - -{% block bodysup %} - - -<section> - <h1>List detail</h1> - - {{ list.header }} - <br/> - - {% load guardian_tags %} - {% get_obj_perms request.user for list as "list_perms" %} - - {% include 'scipost/list_contents.html' %} - - {% if "change_list" in list_perms %} - - <hr class="hr6"/> - <h3>Add elements to this List</h3> - <form action="{% url 'scipost:list' list_id=list.id %}" method="post"> - {% csrf_token %} - <table> - {{ search_for_list_form.as_table }} - </table> - <input type="submit" name="Submit"> - </form> - - {% if search_for_list_form.has_changed %} - <h1>Search results</h1> - {% endif %} - - {% if commentary_search_list %} - <br /> - <hr class="hr12"> - <h3>Commentaries:</h3> - <ul> - {% for commentary in commentary_search_list %} - {{ commentary.header_as_li }} - <form action="{% url 'scipost:list_add_element' list_id=list.id type='C' element_id=commentary.id %}" method="post"> - {% csrf_token %} - <input class="AddItemToList" type="submit" value="Add"/> - </form> - {% endfor %} - </ul> - {% endif %} - - {% if submission_search_list %} - <br /> - <hr class="hr12"> - <h3>Submissions:</h3> - <ul> - {% for submission in submission_search_list %} - {{ submission.header_as_li }} - <form action="{% url 'scipost:list_add_element' list_id=list.id type='S' element_id=submission.id %}" method="post"> - {% csrf_token %} - <input class="AddItemToList" type="submit" value="Add"/> - </form> - {% endfor %} - </ul> - {% endif %} - - {% if thesislink_search_list %} - <br /> - <hr class="hr12"> - <h3>Theses:</h3> - <ul> - {% for thesislink in thesislink_search_list %} - - {% include 'theses/_thesislink_header_as_li.html' with thesislink=thesislink %} - <form action="{% url 'scipost:list_add_element' list_id=list.id type='T' element_id=thesislink.id %}" method="post"> - {% csrf_token %} - <input class="AddItemToList" type="submit" value="Add"/> - </form> - {% endfor %} - </ul> - {% endif %} - - {% if comment_search_list %} - <br /> - <hr class="hr12"> - <h3>Comments:</h3> - <ul> - {% for comment in comment_search_list %} - {{ comment.header_as_li }} - <form action="{% url 'scipost:list_add_element' list_id=list.id type='c' element_id=comment.id %}" method="post"> - {% csrf_token %} - <input class="AddItemToList" type="submit" value="Add"/> - </form> - {% endfor %} - </ul> - {% endif %} - - {% endif %} -</section> - -{% endblock bodysup %} diff --git a/scipost/urls.py b/scipost/urls.py index 1ed0f1b6a..7cafa126b 100644 --- a/scipost/urls.py +++ b/scipost/urls.py @@ -236,33 +236,6 @@ urlpatterns = [ name='howto_production'), - ######### - # Lists # - ######### - - url(r'^create_list$', views.create_list, name='create_list'), - url(r'^list/(?P<list_id>[0-9]+)$', views.list, name='list'), - url(r'^list_add_element/(?P<list_id>[0-9]+)/(?P<type>[SCTc])/(?P<element_id>[0-9]+)$', - views.list_add_element, name='list_add_element'), - url(r'^list_remove_element/(?P<list_id>[0-9]+)/(?P<type>[SCTc])/(?P<element_id>[0-9]+)$', - views.list_remove_element, name='list_remove_element'), - - # Teams - url(r'^create_team$', views.create_team, name='create_team'), - url(r'^add_team_member/(?P<team_id>[0-9]+)$', views.add_team_member, name='add_team_member'), - url(r'^add_team_member/(?P<team_id>[0-9]+)/(?P<contributor_id>[0-9]+)$', - views.add_team_member, name='add_team_member'), - - # Graphs - url(r'^create_graph$', views.create_graph, name='create_graph'), - url(r'^graph/(?P<graph_id>[0-9]+)$', views.graph, name='graph'), - url(r'^edit_graph_node/(?P<node_id>[0-9]+)$', - views.edit_graph_node, name='edit_graph_node'), - url(r'^delete_graph_node/(?P<node_id>[0-9]+)$', - views.delete_graph_node, name='delete_graph_node'), - url(r'^api/graph/(?P<graph_id>[0-9]+)$', views.api_graph, name='api_graph'), - - ############################# # Supporting Partners Board # ############################# diff --git a/scipost/views.py b/scipost/views.py index 295f62b52..87c6ccdd4 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -28,7 +28,6 @@ from guardian.shortcuts import assign_perm from .constants import SCIPOST_SUBJECT_AREAS from .models import Contributor, CitationNotification, UnavailabilityPeriod,\ DraftInvitation, RegistrationInvitation, Remark,\ - List, Team, Graph, Node, Arc,\ title_dict, SciPost_from_addresses_dict,\ AuthorshipClaim, SupportingPartner, SPBMembershipAgreement from .forms import AuthenticationForm, DraftInvitationForm, UnavailabilityPeriodForm,\ @@ -36,9 +35,6 @@ from .forms import AuthenticationForm, DraftInvitationForm, UnavailabilityPeriod ModifyPersonalMessageForm, SearchForm, VetRegistrationForm, reg_ref_dict,\ UpdatePersonalDataForm, UpdateUserDataForm, PasswordChangeForm,\ EmailGroupMembersForm, EmailParticularForm, SendPrecookedEmailForm,\ - CreateListForm, CreateTeamForm,\ - AddTeamMemberForm, CreateGraphForm,\ - ManageTeamsForm, CreateNodeForm, CreateArcForm,\ SupportingPartnerForm, SPBMembershipForm,\ FeedbackForm, MotionForm, NominationForm, RemarkForm from .utils import Utils, EMAIL_FOOTER, SCIPOST_SUMMARY_FOOTER, SCIPOST_SUMMARY_FOOTER_HTML @@ -1720,266 +1716,6 @@ def vote_on_motion(request, motion_id, vote): '/#motion_id' + str(motion.id)) -######### -# Lists # -######### - -@permission_required('scipost.add_list', return_403=True) -def create_list(request): - listcreated = False - message = None - if request.method == "POST": - create_list_form = CreateListForm(request.POST) - if create_list_form.is_valid(): - newlist = List(owner=request.user.contributor, - title=create_list_form.cleaned_data['title'], - description=create_list_form.cleaned_data['description'], - private=create_list_form.cleaned_data['private'], - created=timezone.now()) - newlist.save() - listcreated = True - assign_perm('scipost.change_list', request.user, newlist) - assign_perm('scipost.view_list', request.user, newlist) - assign_perm('scipost.delete_list', request.user, newlist) - message = 'List %s was successfully created.' % create_list_form.cleaned_data['title'] - else: - create_list_form = CreateListForm() - context = {'create_list_form': create_list_form, 'listcreated': listcreated, - 'message': message} - return render(request, 'scipost/create_list.html', context) - - -@permission_required_or_403('scipost.view_list', (List, 'id', 'list_id')) -def list(request, list_id): - list = get_object_or_404(List, pk=list_id) - context = {'list': list} - if request.method == "POST": - search_for_list_form = SearchForm(request.POST) - if search_for_list_form.is_valid(): - context.update(documentsSearchResults(search_for_list_form.cleaned_data['query'])) - else: - search_for_list_form = SearchForm() - context.update({'search_for_list_form': search_for_list_form}) - return render(request, 'scipost/list.html', context) - - -@permission_required_or_403('scipost.change_list', (List, 'id', 'list_id')) -def list_add_element(request, list_id, type, element_id): - list = get_object_or_404(List, pk=list_id) - if type == 'C': - commentary = get_object_or_404(Commentary, pk=element_id) - list.commentaries.add(commentary) - elif type == 'S': - submission = get_object_or_404(Submission, pk=element_id) - list.submissions.add(submission) - elif type == 'T': - thesislink = get_object_or_404(ThesisLink, pk=element_id) - list.thesislinks.add(thesislink) - elif type == 'c': - comment = get_object_or_404(Comment, pk=element_id) - list.comments.add(comment) - return redirect(reverse('scipost:list', kwargs={'list_id': list_id})) - - -@permission_required_or_403('scipost.change_list', (List, 'id', 'list_id')) -def list_remove_element(request, list_id, type, element_id): - list = get_object_or_404(List, pk=list_id) - if type == 'C': - commentary = get_object_or_404(Commentary, pk=element_id) - list.commentaries.remove(commentary) - elif type == 'S': - submission = get_object_or_404(Submission, pk=element_id) - list.submissions.remove(submission) - elif type == 'T': - thesislink = get_object_or_404(ThesisLink, pk=element_id) - list.thesislinks.remove(thesislink) - elif type == 'c': - comment = get_object_or_404(Comment, pk=element_id) - list.comments.remove(comment) - return redirect(reverse('scipost:list', kwargs={'list_id': list_id})) - - -######### -# Teams # -######### - -@permission_required('scipost.add_team', return_403=True) -def create_team(request): - if request.method == "POST": - create_team_form = CreateTeamForm(request.POST) - if create_team_form.is_valid(): - newteam = Team(leader=request.user.contributor, - name=create_team_form.cleaned_data['name'], - established=timezone.now()) - newteam.save() - assign_perm('scipost.change_team', request.user, newteam) - assign_perm('scipost.view_team', request.user, newteam) - assign_perm('scipost.delete_team', request.user, newteam) - return redirect(reverse('scipost:add_team_member', kwargs={'team_id': newteam.id})) - else: - create_team_form = CreateTeamForm() - add_team_member_form = AddTeamMemberForm() - context = {'create_team_form': create_team_form, - 'add_team_member_form': add_team_member_form} - return render(request, 'scipost/create_team.html', context) - - -@permission_required_or_403('scipost.change_team', (Team, 'id', 'team_id')) -def add_team_member(request, team_id, contributor_id=None): - team = get_object_or_404(Team, pk=team_id) - contributors_found = None - if contributor_id is not None: - contributor = get_object_or_404(Contributor, pk=contributor_id) - team.members.add(contributor) - team.save() - assign_perm('scipost.view_team', contributor.user, team) - return redirect(reverse('scipost:add_team_member', kwargs={'team_id': team_id})) - if request.method == "POST": - add_team_member_form = AddTeamMemberForm(request.POST) - if add_team_member_form.is_valid(): - contributors_found = Contributor.objects.filter( - user__last_name__icontains=add_team_member_form.cleaned_data['last_name']) - else: - add_team_member_form = AddTeamMemberForm() - context = {'team': team, 'add_team_member_form': add_team_member_form, - 'contributors_found': contributors_found} - return render(request, 'scipost/add_team_member.html', context) - - -########## -# Graphs # -########## - -@permission_required('scipost.add_graph', return_403=True) -def create_graph(request): - graphcreated = False - message = None - if request.method == "POST": - create_graph_form = CreateGraphForm(request.POST) - if create_graph_form.is_valid(): - newgraph = Graph(owner=request.user.contributor, - title=create_graph_form.cleaned_data['title'], - description=create_graph_form.cleaned_data['description'], - private=create_graph_form.cleaned_data['private'], - created=timezone.now()) - newgraph.save() - assign_perm('scipost.change_graph', request.user, newgraph) - assign_perm('scipost.view_graph', request.user, newgraph) - assign_perm('scipost.delete_graph', request.user, newgraph) - graphcreated = True - message = ('Graph ' + create_graph_form.cleaned_data['title'] - + ' was successfully created.') - else: - create_graph_form = CreateGraphForm() - context = {'create_graph_form': create_graph_form, 'graphcreated': graphcreated, - 'message': message} - return render(request, 'scipost/create_graph.html', context) - - -@permission_required_or_403('scipost.view_graph', (Graph, 'id', 'graph_id')) -def graph(request, graph_id): - graph = get_object_or_404(Graph, pk=graph_id) - nodes = Node.objects.filter(graph=graph) - if request.method == "POST": - attach_teams_form = ManageTeamsForm(request.POST, - contributor=request.user.contributor, - initial={ - 'teams_with_access': graph.teams_with_access.all()} - ) - create_node_form = CreateNodeForm(request.POST) - create_arc_form = CreateArcForm(request.POST, graph=graph) - if attach_teams_form.has_changed() and attach_teams_form.is_valid(): - graph.teams_with_access = attach_teams_form.cleaned_data['teams_with_access'] - graph.save() - elif create_node_form.has_changed() and create_node_form.is_valid(): - newnode = Node(graph=graph, - added_by=request.user.contributor, - created=timezone.now(), - name=create_node_form.cleaned_data['name'], - description=create_node_form.cleaned_data['description']) - newnode.save() - elif create_arc_form.has_changed() and create_arc_form.is_valid(): - sourcenode = create_arc_form.cleaned_data['source'] - targetnode = create_arc_form.cleaned_data['target'] - if sourcenode != targetnode: - newarc = Arc(graph=graph, - added_by=request.user.contributor, - created=timezone.now(), - source=sourcenode, - target=targetnode, - length=create_arc_form.cleaned_data['length'] - ) - newarc.save() - else: - attach_teams_form = ManageTeamsForm(contributor=request.user.contributor, - initial={ - 'teams_with_access': graph.teams_with_access.all()} - ) - create_node_form = CreateNodeForm() - create_arc_form = CreateArcForm(graph=graph) - context = {'graph': graph, 'nodes': nodes, - 'attach_teams_form': attach_teams_form, - 'create_node_form': create_node_form, - 'create_arc_form': create_arc_form} - return render(request, 'scipost/graph.html', context) - - -def edit_graph_node(request, node_id): - node = get_object_or_404(Node, pk=node_id) - errormessage = '' - if not request.user.has_perm('scipost.change_graph', node.graph): - errormessage = 'You do not have permission to edit this graph.' - elif request.method == "POST": - edit_node_form = CreateNodeForm(request.POST, instance=node) - if edit_node_form.is_valid(): - node.name = edit_node_form.cleaned_data['name'] - node.description = edit_node_form.cleaned_data['description'] - node.save() - create_node_form = CreateNodeForm() - create_arc_form = CreateArcForm(graph=node.graph) - context = {'create_node_form': create_node_form, - 'create_arc_form': create_arc_form} - return redirect(reverse('scipost:graph', kwargs={'graph_id': node.graph.id}), context) - else: - edit_node_form = CreateNodeForm(instance=node) - context = {'graph': graph, 'node': node, 'edit_node_form': edit_node_form, - 'errormessage': errormessage} - return render(request, 'scipost/edit_graph_node.html', context) - - -def delete_graph_node(request, node_id): - node = get_object_or_404(Node, pk=node_id) - if not request.user.has_perm('scipost.change_graph', node.graph): - raise PermissionDenied - else: - # Remove all the graph arcs - Arc.objects.filter(source=node).delete() - Arc.objects.filter(target=node).delete() - # Delete node itself - node.delete() - return redirect(reverse('scipost:graph', kwargs={'graph_id': node.graph.id})) - - -@permission_required_or_403('scipost.view_graph', (Graph, 'id', 'graph_id')) -def api_graph(request, graph_id): - """ Produce JSON data to plot graph """ - graph = get_object_or_404(Graph, pk=graph_id) - nodes = Node.objects.filter(graph=graph) - arcs = Arc.objects.filter(graph=graph) - nodesjson = [] - arcsjson = [] - - for node in nodes: - nodesjson.append({'name': node.name, 'id': node.id}) - - for arc in arcs: - arcsjson.append({'id': arc.id, - 'source': arc.source.name, 'source_id': arc.source.id, - 'target': arc.target.name, 'target_id': arc.target.id, - 'length': arc.length}) - return JsonResponse({'nodes': nodesjson, 'arcs': arcsjson}, safe=False) - - ############################# # Supporting Partners Board # ############################# -- GitLab