Skip to content

Commit

Permalink
Merge branch 'release/1.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
pirhoo committed Feb 2, 2014
2 parents 4fe629d + f3f10ef commit 986b523
Show file tree
Hide file tree
Showing 27 changed files with 862 additions and 306 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ before_install:
- ./install_local_neo4j.bash $NEO4J_VERSION
- ./lib/neo4j/bin/neo4j start || ( cat ./lib/neo4j/data/log/*.log && exit 1 )
- curl http://localhost:$NEO4J_PORT/db/data/
- curl -X DELETE 'http://localhost:7474/cleandb/supersecretdebugkey!'
install:
- pip install --use-mirrors -r test_requirements.txt
- pip install --use-mirrors coveralls
- python ./manage.py syncdb --pythonpath=. --noinput
- python ./manage.py loaddata app/detective/fixtures/search_terms.json
env:
- NEO4J_VERSION="1.9.1"
matrix:
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ ENV = `pwd`/.env
run: clear
. $(ENV) ; python manage.py runserver --nothreading

install:
virtualenv:
virtualenv venv --no-site-packages --distribute --prompt=Detective.io
# Install pip packages
. $(ENV) ; pip install -r requirements.txt

install:
make virtualenv
# Install npm packages
cat npm_requirements.txt | echo $1
# Install bower packages
Expand Down
100 changes: 92 additions & 8 deletions app/detective/admin.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,108 @@
from django.contrib import admin
from app.detective.models import QuoteRequest, Topic, RelationshipSearch, Article
from app.detective import utils
from app.detective.models import QuoteRequest, Topic, SearchTerm, Article
from django.conf import settings
from django.contrib import admin
from django.db.models import CharField

class QuoteRequestAdmin(admin.ModelAdmin):
list_filter = ("employer", "records", "users", "public", )
save_on_top = True
list_filter = ("employer", "records", "users", "public", )
search_fields = ("name", "employer", "domain", "email", "comment",)

admin.site.register(QuoteRequest, QuoteRequestAdmin)

class RelationshipSearchInline(admin.TabularInline):
model = RelationshipSearch
extra = 1
# Display relationship admin panel only on debug mode
if settings.DEBUG:
class SearchTermAdmin(admin.ModelAdmin):
list_display = ("name", "label", "subject", "topic", "type",)
admin.site.register(SearchTerm, SearchTermAdmin)


class SearchTermInline(admin.TabularInline):
model = SearchTerm
extra = 0

def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == 'name':
# We add temporary choices for this field so
# it will be threaded as a selectbox
choices = ( (None, "Will be replaced"), )
db_field = CharField(
name=db_field.name,
verbose_name=db_field.verbose_name,
primary_key=db_field.primary_key,
max_length=db_field.max_length,
blank=db_field.blank,
rel=db_field.rel,
default=db_field.default,
editable=db_field.editable,
serialize=db_field.serialize,
unique_for_date=db_field.unique_for_date,
unique_for_year=db_field.unique_for_year,
help_text=db_field.help_text,
db_column=db_field.db_column,
db_tablespace=db_field.db_tablespace,
auto_created=db_field.auto_created,
db_index=db_field.db_index,
validators=db_field.validators,
# The ony field we don't copy
choices=choices
)

return super(SearchTermInline, self).formfield_for_dbfield(db_field, **kwargs)

def formfield_for_choice_field(self, db_field, request, **kwargs):
if db_field.name == 'name' and hasattr(request, "topic_id"):
# We add choices for this field using the current topic's models
kwargs["choices"] = []
# Get the current topic with the ID set into the parent form
topic = Topic.objects.get(id=request.topic_id)
# Get the topic's models
models = utils.get_topic_models(topic)
for model in models:
model_name = getattr(model._meta, "verbose_name").title()
subset = []
# Retreive every relationship field for this model
for field in utils.get_model_fields(model):
if field["type"] != 'AutoField':
choice = [ field["name"], field["verbose_name"].title(), ]
# Add ... at the end ot the relationship field
if field["type"] == 'Relationship': choice[1] += "..."
subset.append(choice)
# Add the choice subset only if it contains elements
if len(subset): kwargs["choices"].append( (model_name, subset,) )
return super(SearchTermInline, self).formfield_for_choice_field(db_field, request,**kwargs)

class TopicAdmin(admin.ModelAdmin):
save_on_top = True
prepopulated_fields = {'slug': ('title',)}
list_display = ("title", "link", "public", )
list_display = ("title", "link", "public", )
fieldsets = (
(None, {
'fields': ( ('title', 'slug',), 'ontology', 'module', 'public')
}),
('Advanced options', {
'classes': ('collapse',),
'fields': ( 'description', 'about', 'background', )
}),
)

def get_form(self, request, obj=None, **kwargs):
if hasattr(obj, "id"):
# Save the topic id into the request to retreive it into inline form
setattr(request, 'topic_id', obj.id)
# Add inlice SearchTerm only for saved object
self.inlines = (SearchTermInline,)
else:
self.inlines = []
return super(TopicAdmin, self).get_form(request, obj, **kwargs)


admin.site.register(Topic, TopicAdmin)

class ArticleAdmin(admin.ModelAdmin):
save_on_top = True
prepopulated_fields = {'slug': ('title',)}
list_display = ("title", "link", "created_at", "public", )
list_display = ("title", "link", "created_at", "public", )

admin.site.register(Article, ArticleAdmin)
Loading

0 comments on commit 986b523

Please sign in to comment.