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

Pass args and kwargs around so that the get_file() method can respond to URL parameters. #121

Closed
wants to merge 4 commits into from

Conversation

willson556
Copy link

Resolves #120.

@benoitbryon
Copy link
Collaborator

benoitbryon commented May 30, 2016

Hi @willson556,

the get_file() method can respond to URL parameters

What about using view's self.args and self.kwargs in get_file() method?

View's attributes such as request, args, and kwargs are set by Django's as_view() magic: see https://github.com/django/django/blob/1.9.6/django/views/generic/base.py#L66-L67

As an example, if URLConf looks like:

year_view = sampleviews.YearDownloadView.as_view()

urlpatterns = [
    url(r'^files/(?P<year>[0-9]{4})/$', year_view),
]

... then you should be able to use "year" from self.kwargs:

class YearDownloadView(VirtualDownloadView):
    def get_file(self):
        year = self.kwargs['year']
        # ... Do something with year...

Does it apply to your use case? Else can you tell me more about the situation where *args and **kwargs are mandatory?

def __init__(self, file_instance, attachment=True, basename=None,
status=200, content_type=None, file_mimetype=None,
file_encoding=None):
file_encoding=None, extra_headers=None, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does **kwargs come from #109 ?
Is it really related to the use of args and kwargs in get_file()?

About extra_headers, I don't see the relationship with args and kwargs in get_file(). If it is another feature, can you create another pull-request for this particular change?

Copy link
Author

Choose a reason for hiding this comment

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

You're right, those are unrelated. **kwargs did come in from #109 and isn't necessary. And extra_headers came from some preliminary work on #122 that I didn't intend to include. I'll remove those unrelated changes.

@willson556
Copy link
Author

I had missed that Django saves the args and kwargs as instance variables. That does resolve my specific use case.

With that knowledge, my only argument for including this PR would be consistency with other CBV's in Django which almost all pass the args and kwargs around (for better or worse) to almost all commonly overriden methods.

@Natim Natim closed this Jan 7, 2020
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.

Pass args & kwargs around so that get_file() can implement URL-based logic.
3 participants