Skip to content

Commit e15b506

Browse files
committed
Merge branch 'release/v1.9.0'
2 parents c3edf08 + 03e1f9e commit e15b506

File tree

84 files changed

+1613
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1613
-434
lines changed

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ endif
2222

2323
all: install startdb run
2424

25-
run: clean
25+
run: clean startdb
2626
. $(ENV) ; python -W ignore::DeprecationWarning manage.py rqworker high default low &
2727
. $(ENV) ; python -W ignore::DeprecationWarning manage.py runserver --nothreading 0.0.0.0:$(PORT)
2828

@@ -109,9 +109,7 @@ test:
109109
make startdb
110110
./manage.py syncdb -v 0 --noinput --traceback --pythonpath=. --settings=app.settings_tests
111111
# Launch test with coverage
112-
-python -W ignore::DeprecationWarning $(COVERAGE) run --source=app.detective ./manage.py test $(TEST) --pythonpath=. --settings=app.settings_tests --traceback
113-
# Send report to coveralls
114-
coveralls
112+
-python -W ignore::DeprecationWarning manage.py test $(TEST) --pythonpath=. --settings=app.settings_tests --traceback
115113
# Stop database in order to restore it
116114
make stopdb
117115
# Remove temporary databases

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[License](https://github.com/jplusplus/detective.io/blob/master/LICENSE)
66
[Test coverage](https://coveralls.io/r/jplusplus/detective.io)
77
[Documentation](http://docs.detective.io/en/latest/)
8-
*Version 1.8.0 Alligator*
8+
*Version 1.9.0 Baboon*
99

1010
## Installation
1111

app/detective/admin.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class TopicAdmin(admin.ModelAdmin):
9898
list_display = ("title", "link", "public","app_label")
9999
list_filter = ("public","featured","author")
100100
readonly_fields = ('entities_count',)
101+
actions = ['duplicate']
101102
suit_form_tabs = (
102103
('general', 'General'),
103104
('advanced', 'Advanced Settings'),
@@ -137,10 +138,33 @@ def get_form(self, request, obj=None, **kwargs):
137138
self.inlines = []
138139
return super(TopicAdmin, self).get_form(request, obj, **kwargs)
139140

141+
def duplicate(self, request, queryset):
142+
import re
143+
for topic in queryset:
144+
exist = True
145+
new_slug = topic.slug
146+
new_title = topic.title
147+
while exist:
148+
match = re.search("-new-(\d+)$", new_slug)
149+
if match:
150+
old_id = match.group(1)
151+
new_slug = new_slug.rstrip(old_id)
152+
new_slug += unicode(int(old_id) + 1)
153+
new_title = new_title.rstrip(old_id)
154+
new_title += unicode(int(old_id) + 1)
155+
else:
156+
new_slug += "-new-1"
157+
new_title += " 1"
158+
exist = Topic.objects.filter(slug=new_slug).exists()
159+
topic.pk = None
160+
topic.title = new_title
161+
topic.slug = new_slug
162+
topic.ontology_as_mod = None
163+
topic.save()
164+
duplicate.short_description = "Duplicate the topic without nodes"
140165

141166
admin.site.register(Topic, TopicAdmin)
142167

143-
144168
class TopicSkeletonForm(forms.ModelForm):
145169
target_plans = forms.MultipleChoiceField(choices=PLANS_CHOICES)
146170

app/detective/fixtures/tests_pillen.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"pk": 4,
55
"fields": {
66
"description": "Test Pillen.",
7-
"title": "Test me",
7+
"title": "Test pillen",
88
"slug": "test-pillen",
99
"ontology_as_json": "[ {\"fields\":[ {\"verbose_name\":\"Name\",\"name\":\"name\",\"type\":\"string\"}, {\"verbose_name\":\"Logo\",\"name\":\"logo\",\"type\":\"string\"}, {\"verbose_name\":\"Picture front\",\"name\":\"image\",\"type\":\"url\"}, {\"verbose_name\":\"Picture back\",\"name\":\"image_back\",\"type\":\"url\"}, {\"verbose_name\":\"Break notch\",\"help_text\":\"DE:Bruchrille\",\"name\":\"break_notch\",\"type\":\"boolean\"}, {\"verbose_name\":\"Color\",\"help_text\":\"DE:Farbe\",\"name\":\"color\",\"type\":\"string\"}, {\"verbose_name\":\"Weight (in milligrams)\",\"help_text\":\"DE:Gewicht. Note: please use dots to separate decimals\",\"name\":\"weight\",\"type\":\"string\"}, {\"verbose_name\":\"Diameter (in millimeters)\",\"help_text\":\"DE:Durchmesser. Note: please use dots to separate decimals\",\"name\":\"diameter\",\"type\":\"string\"}, {\"verbose_name\":\"Thickness (in millimeters)\",\"help_text\":\"DE:Dicke. Note: please use dots to separate decimals\",\"name\":\"thickness\",\"type\":\"string\"}, {\"verbose_name\":\"Place\",\"help_text\":\"DE:Ort\",\"name\":\"place\",\"type\":\"string\"}, {\"verbose_name\":\"Date\",\"help_text\":\"DE:Datum\",\"name\":\"date\",\"type\":\"date\"}, {\"verbose_name\":\"More infos\",\"help_text\":\"DE:Mehr infos. Please, insert a valid URL.\",\"name\":\"more_infos\",\"type\":\"url\"}, {\"verbose_name\":\"Molecules contained\",\"related_name\":\"pills_that_contain_this_molecule\",\"fields\":[ {\"type\":\"string\",\"help_text\":\"Note: please use dots to separate decimals\",\"name\":\"quantity (in milligrams).\" }],\"help_text\":\"All molecules this pills contains\",\"name\":\"molecules_contained\",\"type\":\"relationship\",\"related_model\":\"molecule\" }],\"verbose_name\":\"Pill\",\"name\":\"pill\",\"verbose_name_plural\":\"Pills\"}, {\"fields\":[ {\"verbose_name\":\"Name\",\"name\":\"name\",\"type\":\"string\"}, {\"verbose_name\":\"Toxicity threshold\",\"help_text\":\"Max threshold for one pill. If the threshold is exceeded, a warning can be display.\",\"name\":\"toxicity_threshold\",\"type\":\"string\"}, {\"verbose_name\":\"Description\",\"name\":\"description\",\"type\":\"string\",\"rules\":{\"is_rich\":true } }],\"verbose_name\":\"Molecule\",\"help_text\":\"DE:Molek\u00fcl\",\"name\":\"molecule\",\"verbose_name_plural\":\"Molecules\"}]",
1010
"ontology_as_owl": null,
@@ -16,6 +16,4 @@
1616
"author": 100000
1717
}
1818
}
19-
]
20-
21-
19+
]

app/detective/individual.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from app.detective import register, graph
44
from app.detective.neomatch import Neomatch
55
from app.detective.utils import import_class, to_underscores, get_model_topic, get_leafs_and_edges, get_topic_from_request, get_model_fields
6+
from app.detective.utils import get_model_fields as utils_get_model_fields
67
from app.detective.topics.common.models import FieldSource
78
from app.detective.models import Topic
89
from django.conf.urls import url
@@ -28,6 +29,7 @@
2829
import json
2930
import re
3031
import logging
32+
import bleach
3133

3234
logger = logging.getLogger(__name__)
3335

@@ -510,13 +512,14 @@ def validate(self, data, model=None, allow_missing=False):
510512
# Boolean field must be validate manually
511513
if field.get_internal_type() == 'BooleanField':
512514
if type(data[field_name]) is not bool:
515+
raise ValidationError({field_name: 'Must be a boolean value'})
513516
if not allow_missing:
514517
raise ValidationError({field_name: 'Must be a boolean value'})
515518
# Skip this field
516519
else: continue
517520
cleaned_data[field_name] = data[field_name]
518521
# Only literal values have a _property attribute
519-
if hasattr(field, "_property"):
522+
elif hasattr(field, "_property"):
520523
try:
521524
try:
522525
# Get a single field validator
@@ -583,6 +586,8 @@ def get_patch(self, request, **kwargs):
583586
self.authorized_update_detail(self.get_object_list(bundle.request), bundle)
584587
# Current model
585588
model = self.get_model()
589+
# Fields
590+
fields = { x['name'] : x for x in utils_get_model_fields(model) }
586591
# Get the node's data using the rest API
587592
try: node = connection.nodes.get(pk)
588593
# Node not found
@@ -672,7 +677,17 @@ def get_patch(self, request, **kwargs):
672677
except client.NotFoundError: pass
673678
# We simply update the node property
674679
# (the value is already validated)
675-
else: node.set(field_name, field_value)
680+
else:
681+
if field_name in fields:
682+
if 'is_rich' in fields[field_name]['rules'] and fields[field_name]['rules']['is_rich']:
683+
data[field_name] = field_value = bleach.clean(field_value,
684+
tags=("br", "blockquote", "ul", "ol",
685+
"li", "b", "i", "u", "a", "p"),
686+
attributes={
687+
'*': ("class",),
688+
'a': ("href", "target")
689+
})
690+
node.set(field_name, field_value)
676691

677692
# And returns cleaned data
678693
return self.create_response(request, data)

app/detective/models.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -646,23 +646,19 @@ def update_topic_cache(*args, **kwargs):
646646
# previously stored information related to this topic
647647
utils.topic_cache.incr_version(topic)
648648

649-
def remove_topic_cache(*args, **kwargs):
650-
utils.topic_cache.delete_version(kwargs.get('instance'))
651-
652649
def delete_entity(*args, **kwargs):
653650
fields = utils.get_model_fields(kwargs.get('instance').__class__)
654651
for field in fields:
655-
if field["rel_type"] and "through" in field["rules"]:
652+
if field["rel_type"] and "through" in field["rules"] and field["rules"]["through"] != None:
656653
Properties = field["rules"]["through"]
657654
for info in Properties.objects.all():
658655
info.delete()
659656
update_topic_cache(*args, **kwargs)
660657

661-
signals.post_delete.connect(remove_permissions , sender=Topic)
662658
signals.post_save.connect(user_created , sender=User)
663659
signals.post_save.connect(update_topic_cache , sender=Topic)
664660
signals.post_save.connect(update_permissions , sender=Topic)
665-
signals.pre_delete.connect(remove_topic_cache , sender=Topic)
661+
signals.post_delete.connect(update_topic_cache , sender=Topic)
666662
signals.post_delete.connect(remove_permissions , sender=Topic)
667663

668664
# EOF
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
.login-form {
2-
width:500px;
3-
margin-left:auto;
4-
margin-right:auto;
5-
6-
@media(max-width: @screen-xs-max){ // for mobile
7-
width: 100%;
8-
}
9-
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
html body .account-settings {
2+
.panel-default {
3+
.panel-heading {
4+
background-color: @panel-default-heading-bg;
5+
}
6+
}
7+
.panel {
8+
.btn {
9+
width: 180px;
10+
}
11+
}
12+
}

app/detective/static/detective/css/base.less

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@zindex-header : @zindex-breadcrumb+100;
99
// Header configuration
1010
@header-bg:#FFF;
11+
@header-border-color: #DDD;
1112
@header-height: 50px;
1213
@header-open-speed: 0.4s;
1314
@aside-width: 250px;
@@ -34,6 +35,7 @@
3435
@import './account.login.less';
3536
@import './account.password-reset.confirmation.less';
3637
@import './account.password-reset.less';
38+
@import './account.settings.less';
3739
@import './account.signup.less';
3840
@import './animations.less';
3941
@import './content.less';

app/detective/static/detective/css/bootstrap.panel.less

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
html body .panel {
24
color:@gray-darker;
35
.border-radius(2px);
@@ -21,6 +23,40 @@ html body .panel {
2123
}
2224
}
2325

26+
&-centered {
27+
width:500px;
28+
margin-left:auto;
29+
margin-right:auto;
30+
31+
@media(max-width: @screen-xs-max){ // for mobile
32+
width: 100%;
33+
}
34+
}
35+
.panel-shadow(@color){
36+
@outside-border-color: fade(@color, 50%);
37+
.box-shadow( ~"0 1px 0 @{color} inset, 0px 1px 2px @{outside-border-color}" );
38+
}
39+
&-danger {
40+
border: 0;
41+
.panel-shadow(@brand-danger);
42+
.panel-heading {
43+
color: white;
44+
background-color: @brand-danger;
45+
}
46+
.panel-footer {
47+
border-top: 0;
48+
}
49+
.btn-danger {
50+
color: white;
51+
}
52+
}
53+
&-warning {
54+
border: 0;
55+
.panel-shadow(@brand-warning);
56+
.btn-warning {
57+
color: @gray;
58+
}
59+
}
2460
&.panel-bg {
2561

2662
&.panel-primary {

0 commit comments

Comments
 (0)