Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty #2

Open
wants to merge 100 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
263dbb6
Initial setup for html template and js
jgadelange Mar 1, 2014
a49736a
Rewrote inline JS to new baseInlineFormset jQuery plugin
wkleinheerenbrink Mar 1, 2014
92f7b3c
Remove unused templatedir
wkleinheerenbrink Mar 1, 2014
9605a03
Do not add form on unRemoveForm if max forms would be exceeded
wkleinheerenbrink Mar 3, 2014
f5b1271
Implemented customizable labels
wkleinheerenbrink Mar 3, 2014
d65491c
Add alternative inline styles
wkleinheerenbrink Mar 3, 2014
130f8f2
Insert new form before the emptyForm
wkleinheerenbrink Mar 3, 2014
2a3d93d
Start using custom stylesheet for inline
wkleinheerenbrink Mar 3, 2014
8542585
Alternate row coloring
wkleinheerenbrink Mar 3, 2014
b053ef9
Style add button
wkleinheerenbrink Mar 3, 2014
502e66a
Style delete button
wkleinheerenbrink Mar 3, 2014
c65ca13
Style removed row
wkleinheerenbrink Mar 3, 2014
3ba2108
Fix toggle 'disabled' class for add button
wkleinheerenbrink Mar 3, 2014
895c483
Styled disabled add button
wkleinheerenbrink Mar 3, 2014
1075682
Fix delete text
wkleinheerenbrink Mar 3, 2014
31d348b
Improved stacked html to show delete buttons for every item
wkleinheerenbrink Mar 3, 2014
0165025
Style removed class for stacked
wkleinheerenbrink Mar 3, 2014
5581ed6
Change 'unremove' label into 'undo remove'
wkleinheerenbrink Mar 3, 2014
b1d6f0e
Make maximum number of objects message translatable
wkleinheerenbrink Mar 3, 2014
c7872c9
Cleanup
wkleinheerenbrink Mar 3, 2014
e6ae578
Define base template
wkleinheerenbrink Mar 3, 2014
da692b4
Add changeForm methods to baseinline
wkleinheerenbrink Mar 4, 2014
ef8857a
Implement edit form
wkleinheerenbrink Mar 4, 2014
3139ba4
Show edit form on add
wkleinheerenbrink Mar 4, 2014
53e3cc6
Fix change button on newly added forms
wkleinheerenbrink Mar 4, 2014
c1a7f83
Implement formatter for item label
wkleinheerenbrink Mar 4, 2014
c528000
Add required missing hidden fields
wkleinheerenbrink Mar 4, 2014
1c50537
Show invalid signs
wkleinheerenbrink Mar 4, 2014
0f72922
Change methodname 'changeForm' into 'showChangeForm' for clarity
wkleinheerenbrink Mar 4, 2014
8e9c89f
Hard remove form on delete if it has no changes yet
wkleinheerenbrink Mar 4, 2014
882293f
Remove form on cancel if it doesnt have any changes yet
wkleinheerenbrink Mar 4, 2014
059314a
Wrap div around inlines in stacked view
wkleinheerenbrink Mar 4, 2014
d0d0e69
Remove unused sepearte js file
wkleinheerenbrink Mar 4, 2014
5892210
Initial setup for html template and js
jgadelange Mar 1, 2014
43d5f2f
Rewrote inline JS to new baseInlineFormset jQuery plugin
wkleinheerenbrink Mar 1, 2014
093e546
Remove unused templatedir
wkleinheerenbrink Mar 1, 2014
790d98b
Do not add form on unRemoveForm if max forms would be exceeded
wkleinheerenbrink Mar 3, 2014
c211531
Implemented customizable labels
wkleinheerenbrink Mar 3, 2014
c830838
Add alternative inline styles
wkleinheerenbrink Mar 3, 2014
3ca0432
Insert new form before the emptyForm
wkleinheerenbrink Mar 3, 2014
bbce5c5
Start using custom stylesheet for inline
wkleinheerenbrink Mar 3, 2014
23c89a4
Alternate row coloring
wkleinheerenbrink Mar 3, 2014
97894fa
Style add button
wkleinheerenbrink Mar 3, 2014
6462662
Style delete button
wkleinheerenbrink Mar 3, 2014
bf1b3d0
Style removed row
wkleinheerenbrink Mar 3, 2014
56fa7ab
Fix toggle 'disabled' class for add button
wkleinheerenbrink Mar 3, 2014
16c475e
Styled disabled add button
wkleinheerenbrink Mar 3, 2014
45d5dcb
Fix delete text
wkleinheerenbrink Mar 3, 2014
32fe4e4
Improved stacked html to show delete buttons for every item
wkleinheerenbrink Mar 3, 2014
7ed4c0b
Style removed class for stacked
wkleinheerenbrink Mar 3, 2014
5ae4e33
Change 'unremove' label into 'undo remove'
wkleinheerenbrink Mar 3, 2014
ae64a93
Make maximum number of objects message translatable
wkleinheerenbrink Mar 3, 2014
b0f163d
Cleanup
wkleinheerenbrink Mar 3, 2014
fd13c5f
Define base template
wkleinheerenbrink Mar 3, 2014
9083b97
Add changeForm methods to baseinline
wkleinheerenbrink Mar 4, 2014
5aad44c
Implement edit form
wkleinheerenbrink Mar 4, 2014
dd5aaa3
Show edit form on add
wkleinheerenbrink Mar 4, 2014
43eb353
Fix change button on newly added forms
wkleinheerenbrink Mar 4, 2014
0bc64ce
Implement formatter for item label
wkleinheerenbrink Mar 4, 2014
19a85b1
Add required missing hidden fields
wkleinheerenbrink Mar 4, 2014
279c26c
Show invalid signs
wkleinheerenbrink Mar 4, 2014
dd82917
Change methodname 'changeForm' into 'showChangeForm' for clarity
wkleinheerenbrink Mar 4, 2014
59c304f
Hard remove form on delete if it has no changes yet
wkleinheerenbrink Mar 4, 2014
8a739af
Remove form on cancel if it doesnt have any changes yet
wkleinheerenbrink Mar 4, 2014
91dcaad
Wrap div around inlines in stacked view
wkleinheerenbrink Mar 4, 2014
7ef6778
Remove unused sepearte js file
wkleinheerenbrink Mar 4, 2014
6475882
Merge branch 'pretty' of github.com:fluxility/pretty-inline into pretty
wkleinheerenbrink Mar 5, 2014
efe2836
Merge branch 'develop' of github.com:fluxility/pretty-inline into pretty
wkleinheerenbrink Mar 5, 2014
596a85f
Reinit datatimeshortcuts as in old inlineadmin
wkleinheerenbrink Mar 5, 2014
bd2d944
Remove south from example project
wkleinheerenbrink Mar 6, 2014
d83a317
Adjust template to reapply inline table editing
wkleinheerenbrink Mar 6, 2014
fef4736
Update JS to support inline table editing instead of external editor
wkleinheerenbrink Mar 6, 2014
83c41a2
Use proper method name for checking if element is equal to emptyform
wkleinheerenbrink Mar 6, 2014
6879307
Append buttonRow to fieldset
wkleinheerenbrink Mar 6, 2014
6312bc6
Add style to inline tabular edit
wkleinheerenbrink Mar 8, 2014
3aa3e52
Use 'OK' instead of save
wkleinheerenbrink Mar 8, 2014
461414b
Disable/enable change and delete on edit
wkleinheerenbrink Mar 8, 2014
a7ea9e2
Hide original, do not add 'hidden' class anymore
wkleinheerenbrink Mar 8, 2014
12cf28a
Render only a substring of 30 in table
wkleinheerenbrink Mar 8, 2014
2ccaf1c
Undo remove if user presses change
wkleinheerenbrink Mar 8, 2014
ad5ab91
Fix handleOpenEditor
wkleinheerenbrink Mar 8, 2014
d52c695
Fix managementform for saving
wkleinheerenbrink Mar 8, 2014
3e991e6
Remove unnecessary height definitions
wkleinheerenbrink Mar 8, 2014
f16a18a
Fix animation settings for activating editor
wkleinheerenbrink Mar 8, 2014
434f361
enable to save the whole item when an inline is still open
wkleinheerenbrink Mar 8, 2014
052597d
Add a second inline to test if library works with multiple inlines
wkleinheerenbrink Mar 8, 2014
32c6ad4
Save the whole form (nonetheless open editors) on submit
wkleinheerenbrink Mar 12, 2014
6b5b4bb
When saving inline form, error class is removed
wkleinheerenbrink Mar 12, 2014
9aacb95
Fix delete buttons for stacked and tabular
wkleinheerenbrink Mar 12, 2014
c12c870
Add border around active fieldset
wkleinheerenbrink Mar 12, 2014
8a87895
Merge pull request #1 from fluxility/intable-editor
wkleinheerenbrink Mar 12, 2014
c16cd0e
Add Django < 1.6 support by adding newer version of jQuery
wkleinheerenbrink Mar 12, 2014
0ba377d
Fix jQuery check
wkleinheerenbrink Mar 12, 2014
c7611d4
Fix compatibility for django < 1.6 by check has_auto_field and needs_…
wkleinheerenbrink Mar 12, 2014
4c03046
Use consistent name 'inline-item' in each inline layout
wkleinheerenbrink Mar 12, 2014
bc3fd31
Apply fix from c7611d4 also to Tabular and Stacked
wkleinheerenbrink Mar 13, 2014
34167cf
Updated labels
jgadelange Mar 15, 2014
8ef87f2
Gave actions column in pretty inline a fixed width
jgadelange Mar 15, 2014
017a4b4
Made 0 by default for all of our inlines
jgadelange Mar 15, 2014
24d24d9
Remove empty form before submitting
jgadelange Sep 11, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions example_project/myapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
from django.contrib import admin
from myapp.models import Author, Book
from pretty_inline import PrettyInline
from myapp.models import Book, Author, AuthorTabular, AuthorStacked, AuthorPretty, Address
from pretty_inline.admin import TabularInline, StackedInline, PrettyInline


class BookInline(PrettyInline):
class BookRegularTabularInline(admin.StackedInline):
model = Book
max_num = 5


class AuthorAdmin(admin.ModelAdmin):
inlines = [BookInline, ]
class BookTabularInline(TabularInline):
model = Book
max_num = 5


class BookStackedInline(StackedInline):
model = Book
max_num = 5


class BookPrettyInline(PrettyInline):
model = Book
max_num = 5


class AddressPrettyInline(PrettyInline):
model = Address


class AuthorTabularAdmin(admin.ModelAdmin):
inlines = [BookTabularInline, ]


class AuthorStackedAdmin(admin.ModelAdmin):
inlines = [BookStackedInline, ]


class AuthorRegularTabularAdmin(admin.ModelAdmin):
inlines = [BookRegularTabularInline]


class AuthorPrettyAdmin(admin.ModelAdmin):
inlines = [BookPrettyInline, AddressPrettyInline]

admin.site.register(Author, AuthorAdmin)
admin.site.register(AuthorTabular, AuthorTabularAdmin)
admin.site.register(AuthorStacked, AuthorStackedAdmin)
admin.site.register(AuthorPretty, AuthorPrettyAdmin)
admin.site.register(Author, AuthorRegularTabularAdmin)
admin.site.register(Book)
24 changes: 24 additions & 0 deletions example_project/myapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,29 @@ class Author(models.Model):


class Book(models.Model):
author = models.ForeignKey(Author)
title = models.CharField(max_length=255)
eancode = models.CharField(max_length=255)
description = models.TextField()
language = models.CharField(max_length=7, choices=[("dutch", "Dutch"), ("english", "English")])


class Address(models.Model):
author = models.ForeignKey(Author)
street = models.CharField(max_length=100)
postal = models.CharField(max_length=100)
city = models.CharField(max_length=100)

class AuthorTabular(Author):
class Meta:
proxy = True


class AuthorStacked(Author):
class Meta:
proxy = True


class AuthorPretty(Author):
class Meta:
proxy = True
40 changes: 34 additions & 6 deletions pretty_inline/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
from django.conf import settings
from django.contrib.admin.options import InlineModelAdmin
from django.contrib.admin.templatetags.admin_static import static
from django.contrib.admin import TabularInline as BaseTabularInline
from django.contrib.admin import StackedInline as BaseStackedInline
from django.forms import forms


class PrettyInline(InlineModelAdmin):
template = 'pretty_inline/edit_inline/pretty.html'

class BaseInlineModelAdmin(InlineModelAdmin):
@property
def media(self):
js = super(PrettyInline, self).media
js.add_js([static('pretty_inline/js/%s' % 'pretty_inline.js'), ])
return js
from django import VERSION as DJANGO_VERSION

media = super(BaseInlineModelAdmin, self).media

if DJANGO_VERSION[0] is 1 and DJANGO_VERSION[1] < 6:
media.add_js(['//code.jquery.com/jquery-1.11.0.min.js'])

media.add_css({
"all": [static('pretty_inline/css/baseInlineFormset.css')]
})
media.add_js([static('libs/jquery.fix.clone.js')])
media.add_js([static('pretty_inline/js/baseInlineFormset.js')])


return media


class TabularInline(BaseInlineModelAdmin, BaseTabularInline):
template = 'pretty_inline/edit_inline/tabular.html'


class StackedInline(BaseInlineModelAdmin, BaseStackedInline):
template = 'pretty_inline/edit_inline/stacked.html'


class PrettyInline(BaseInlineModelAdmin):
template = 'pretty_inline/edit_inline/pretty.html'
extra = 0

27 changes: 27 additions & 0 deletions pretty_inline/static/libs/jquery.fix.clone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Textarea and select clone() bug workaround | Spencer Tipping
// Licensed under the terms of the MIT source code license

// Motivation.
// jQuery's clone() method works in most cases, but it fails to copy the value of textareas and select elements. This patch replaces jQuery's clone() method with a wrapper that fills in the
// values after the fact.

// An interesting error case submitted by Piotr Przybył: If two <select> options had the same value, the clone() method would select the wrong one in the cloned box. The fix, suggested by Piotr
// and implemented here, is to use the selectedIndex property on the <select> box itself rather than relying on jQuery's value-based val().

(function ($) {
var original = $.fn.clone;
$.fn.clone = function () {
var result = original.apply(this, arguments),
my_textareas = this.find('textarea').add(this.filter('textarea')),
result_textareas = result.find('textarea').add(result.filter('textarea')),
my_selects = this.find('select').add(this.filter('select')),
result_selects = result.find('select').add(result.filter('select'));

for (var i = 0, l = my_textareas.length; i < l; ++i) $(result_textareas[i]).val($(my_textareas[i]).val());
for (var i = 0, l = my_selects.length; i < l; ++i) result_selects[i].selectedIndex = my_selects[i].selectedIndex;

return result;
};
})(django.jQuery);

// Generated by SDoc
204 changes: 204 additions & 0 deletions pretty_inline/static/pretty_inline/css/baseInlineFormset.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
.inline-group td {
line-height: 34px;
}

.inline-group .form-row:nth-child(odd) {
background: #EDF3FE;
}

.inline-group .add-button {
background: url('../../admin/img/icon_addlink.gif') 0 50% no-repeat;
margin-left: 10px;
padding-left: 15px;
border: 0;
color: #5b80b2;
cursor: pointer;
}

.inline-group .add-button:hover,
.inline-group .add-button:focus {
color: #036;
}

.inline-group .change-button {
background: url('../../admin/img/icon_changelink.gif') 0 50% no-repeat;
margin-left: 10px;
padding-left: 15px;
border: 0;
color: #5b80b2;
cursor: pointer;
}

.inline-group .change-button:hover,
.inline-group .change-button:focus {
color: #036;
}

.inline-group .change-button.disabled {
opacity: 0.2;
color: #999;
}

.inline-group .delete-button {
background: url('../../admin/img/icon_deletelink.gif') 0 50% no-repeat;
margin-left: 10px;
padding-left: 15px;
border: 0;
color: #CC3434;
cursor: pointer;
}

.inline-group .delete-button:hover,
.inline-group .delete-button:focus {
color: #993333;
}

.inline-group .delete-button.disabled {
opacity: 0.2;
color: #999;
}

.inline-group .save-button {
border: 2px solid #5b80b2;
background: #7CA0C7 url(../../admin/img/default-bg.gif) bottom repeat-x;
font-weight: bold;
color: white;
padding-left: 12px;
padding-right: 12px;
}

.inline-group .cancel-button {
background: white url(../../admin/img/nav-bg.gif) bottom repeat-x;
padding: 3px 5px;
color: black;
border: 1px solid #bbb;
border-color: #ddd #aaa #aaa #ddd;
}

.inline-group .button-row {
padding-left: 115px;
padding-top: 20px;
padding-bottom: 40px;
}


.inline-group .form-row.removed,
.inline-group .removed .form-row {
background: #FFF4F9;
}

.inline-group .removed .form-row:nth-child(odd),
.inline-group .form-row:nth-child(odd).removed {
background: #FFECF4;
}

.inline-group .removed * {
text-decoration: line-through;
}

.inline-group .removed button.delete-button,
.inline-group .removed button.change-button {
text-decoration: none;
}

.inline-group .add-button.disabled {
color: #ddd;
}

.inline-group .form-row.errors {
background: #FFC;
border: 1px solid #F00;
}

/* Stacked */
.inline-group.stacked-inline .delete-button {
padding: 0 0 0 15px;
}

.inline-group .hidden {
display: none;
}

/* Pretty */
.inline-group.pretty .overview {
position: relative;
opacity: 1;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}

.inline-group.pretty .editor {
opacity: 0;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}

.inline-group.pretty.editor-active .overview {
display: none;
position: absolute;
}

.inline-group.pretty.editor-active .editor {
opacity: 1;
}

.inline-group.pretty.editor-active .add-button {
display: none;
}

.inline-group.pretty .form-row.errors .item {
background: #FFC url('../../admin/img/icon_error.gif') 5px 50% no-repeat;
padding-left: 25px;
}

.inline-group.pretty .change-form td {
overflow: hidden;
}

.inline-group.pretty .change-form fieldset {
-webkit-transition: all 200ms;
-moz-transition: all 200ms;
-ms-transition: all 200ms;
-o-transition: all 200ms;
transition: all 200ms;
overflow: hidden;
margin: -50% auto 50px;
width: 90%;

}

.inline-group.pretty .change-form.original {
display: none;
}

.inline-group.pretty .change-form.original fieldset {
display: none;
}

.inline-group.pretty .change-form.active {
background: #F5F8FF;
}

.inline-group.pretty .change-form.active fieldset {
margin: 0 auto 50px;
}

.inline-group.pretty .change-form.active .form-row:nth-child(odd) {
background: #FFF;
}

.inline-group.pretty .change-form.active > td {
padding: 0;
}

.inline-group.pretty .change-form.active fieldset {
border-left: 1px solid #ddd;
border-bottom: 1px solid #ddd;
border-right: 1px solid #ddd;
}
Loading