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

Making easy to add new views to a ModelAdmin2 - implemented AdminView #218

Merged
merged 11 commits into from Jul 27, 2013

Conversation

andrewsmedina
Copy link
Contributor

it fix the #142.

@pydanny
Copy link
Member

pydanny commented Jun 30, 2013

Apologies for not reviewing this sooner. I'm pushing it to the 0.5.0 release (0.4.0 is coming out today) and will review it very soon.

@andrewsmedina
Copy link
Contributor Author

@pydanny no problem :)

@ghost ghost assigned andrewsmedina Jul 6, 2013
create_view = views.AdminView(r'^create/$', views.ModelAddFormView, name='create')
update_view = views.AdminView(r'^(?P<pk>[0-9]+)/$', views.ModelEditFormView, name='update')
detail_view = views.AdminView(r'^(?P<pk>[0-9]+)/update/$', views.ModelDetailView, name='detail')
delete_view = views.AdminView(r'^(?P<pk>[0-9]+)/delete/$', views.ModelDeleteView, name='delete')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewsmedina - Can you explain the reasoning for this method for URL definition instead of the earlier one? Some concerns that I have:

  1. Performance
  2. Scoping issues with multiple users acting on the same or unrelated views.

For reference, I'm not opposed, I'm just looking at this and worrying about the implications. I will admit I haven't had all the time necessary to properly evaluate your code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just using the new AdminView for all 'admin views'. With it, is easier to replace an admin model view.

About performance, I will make a benchmark to measure the impact. Ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, performance isn't as much an issue as the second one, which is the scope concern.

I'm still trying to be certain about the scope and thread safety involved. Remember, the reason why Django didn't get CBVs for a long time was because this is a hard problem. Heck, Marty Alchin even got it wrong in 1st edition Pro-Django. You've got a neat idea, I'm just trying to be certain it's safe. And checking for safety in this case isn't easy. 🍂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pydanny, I remember the CBV case and the as_view was the solution for thread safety. I will check this possible problem :)

@pydanny pydanny mentioned this pull request Jul 8, 2013
class ModelAdmin2(object):
"""
Warning: This class is targeted for reduction.
It's bloated and ugly.
"""
__metaclass__ = ModelAdminBase2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested your code on Python 3? The syntax for metaclasses has changed in Python 3. You might want to use the six library to support Python 2 and 3.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. In fact, at some point soon we should add Python 3 as a Travis environment.

@gregmuellegger
Copy link
Contributor

Nice one! I reviewed the patch and approve the changes from my side. I just added on inline comment regarding Python 3.

However some documentation about the view definitions would be reeeally sweet 🍩

@pydanny
Copy link
Member

pydanny commented Jul 26, 2013

@gregmuellegger What about concerns on thread safety? That's my bottleneck for this one. I keep meaning to find the time to really dig in and analyze it.

I agree with you on documentation. For example:

  1. How do I add a new View?
  2. Can I drop an existing view?

@gregmuellegger
Copy link
Contributor

I don't see any issues with thread safety. See https://github.com/pydanny/django-admin2/pull/218/files#L4R181 the line is:

view = model_admin.update_view.view.as_view(
             **model_admin.get_update_kwargs())

The view is instantiated via as_view like any other django-core-based CBV as well. The thing is that the attributes on the ModelAdmin2 class only hold references to the classes of the CBV. Not of their instances. So the patch doesn't change any logic of where the as_view method of the CBV is called.

Hope it's clear what I mean. Just hit me with a stick and I'll try to write it down again in more detail.

@pydanny
Copy link
Member

pydanny commented Jul 26, 2013

That's what I thought. Digging in too and it's doing what we think it's doing. I wanted more eyes on this so thanks!

@andrewsmedina Want to update to the current code base and fill out some of the docs? 🍷

@andrewsmedina
Copy link
Contributor Author

@gregmuellegger and @pydanny thanks for this review! :)

@pydanny I will update the code base today. I was thinking of sending the documentation in another pull request. What do you think?

@pydanny
Copy link
Member

pydanny commented Jul 26, 2013

Same pull request please!

On Fri, Jul 26, 2013 at 8:41 PM, Andrews Medina notifications@github.comwrote:

@gregmuellegger https://github.com/gregmuellegger and @pydannyhttps://github.com/pydannythanks for this review! :)

@pydanny https://github.com/pydanny I will update the code base today.
I was thinking of sending the documentation in another pull request. What
do you think?


Reply to this email directly or view it on GitHubhttps://github.com//pull/218#issuecomment-21640037
.

'Knowledge is Power'
Daniel Greenfeld
Principal at Cartwheel Web; co-author of Two Scoops of Django
cartwheelweb.com | pydanny.com | django.2scoops.org

@andrewsmedina
Copy link
Contributor Author

@pydanny roger that!

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 3c7fc0f on andrewsmedina:admin_view into 1b7b803 on pydanny:develop.

@andrewsmedina
Copy link
Contributor Author

@pydanny docs and the python3 fix commited.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling b7b0d9b on andrewsmedina:admin_view into 1b7b803 on pydanny:develop.

@pydanny pydanny merged commit b7b0d9b into jazzband:develop Jul 27, 2013
@pydanny
Copy link
Member

pydanny commented Jul 27, 2013

Wahoo!!! Awesome work:exclamation: :fire: :fireworks:

@andrewsmedina andrewsmedina deleted the admin_view branch July 27, 2013 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants