Skip to content

Commit

Permalink
edit entries #10
Browse files Browse the repository at this point in the history
  • Loading branch information
cbertelegni committed Sep 4, 2014
1 parent 9d98740 commit 2c2a8ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crowdataapp/admin.py
Expand Up @@ -350,7 +350,7 @@ class DocumentSetFormEntryInline(admin.TabularInline):
extra = 0

def answers(self, obj):
field_template = "<li><input type=\"checkbox\" data-change-url=\"%s\" data-field-entry=\"%d\" data-document=\"%d\" data-entry-value=\"%s\" %s><span class=\"%s\">%s</span>: <strong>%s</strong> - <em>%s</em></li>"
field_template = "<li><input type=\"checkbox\" data-change-url=\"%s\" data-field-entry=\"%d\" data-document=\"%d\" data-entry-value=\"%s\" %s><span class=\"%s\">%s</span>: <a href=\"/admin/crowdataapp/documentsetfieldentry/%s\"><strong>%s</strong></a> - <em>%s</em></li>"
rv = '<ul>'
form_fields = obj.form.fields.order_by('id').all()
rv += ''.join([field_template % (reverse('admin:document_set_field_entry_change', args=(obj.document.pk, e.pk,)),
Expand All @@ -360,15 +360,14 @@ def answers(self, obj):
'checked' if e.verified else '',
'verify' if f.verify else '',
f.label,
e.pk,
e.value,
e.assigned_canonical_value())
for f, e in zip(form_fields,
obj.fields.order_by('field_id').all())])
rv += '</ul>'

return mark_safe(rv)


def user_link(self, obj):
url = reverse('admin:auth_user_change', args=(obj.user.id,))
return mark_safe('<a href="%s">%s</a>' % (url, obj.user.get_full_name()))
Expand Down Expand Up @@ -488,13 +487,21 @@ class Media:

readonly_fields = ('last_login', 'date_joined', )

class DocumentSetFieldEntryAdmin(admin.ModelAdmin):
def get_model_perms(self, request):
"""
Return empty perms dict thus hiding the model from admin index.
"""
return {}

admin.site.register(models.DocumentSet, DocumentSetAdmin)
admin.site.register(models.Document, DocumentAdmin)
admin.site.unregister(forms_builder.forms.models.Form)

admin.site.register(models.CanonicalFieldEntryLabel, CanonicalFieldEntryLabelAdmin)

admin.site.register(models.DocumentSetFieldEntry, DocumentSetFieldEntryAdmin)

admin.site.unregister(User)
admin.site.register(User, CrowDataUserAdmin)

Expand Down
11 changes: 11 additions & 0 deletions crowdataapp/models.py
Expand Up @@ -209,6 +209,10 @@ class DocumentSetForm(forms_builder.forms.models.AbstractForm):
def get_absolute_url(self):
return ('crowdata_form_detail', (), { 'slug': self.slug })

# def __unicode__(self):
# return self.document_set.name


class DocumentSetFormFieldManager(models.Manager):
"""
Only show visible fields when displaying actual form..
Expand Down Expand Up @@ -288,6 +292,10 @@ def force_verify(self):
self.document.verified = True
self.document.save()

# def __unicode__(self):
# return self.value


class DocumentSetFieldEntry(forms_builder.forms.models.AbstractFieldEntry):
entry = models.ForeignKey("DocumentSetFormEntry", related_name="fields")
verified = models.BooleanField(default=False, null=False)
Expand Down Expand Up @@ -647,3 +655,6 @@ def reassign_entries_to(self, new_canon):
for entry in self.fields.all():
entry.canonical_label = new_canon
entry.save_without_setting_canon()

def __unicode__(self):
return self.value

0 comments on commit 2c2a8ca

Please sign in to comment.