These are chat archives for django/django

6th
Jun 2018
Tom Victor
@Tomvictor
Jun 06 2018 06:45

can anyone help me out on password rest,

view.py

       this_user = get_object_or_404(User, username=curr_username)
        this_user.set_password(new_password)
        this_user.save()
i am able to run this success, but unable to login using the new password !
can anyone suggest proper method to reset password ?
Pieter Stokkink
@forkerino
Jun 06 2018 09:09
Anyone online? Got a question on urls
Luke-VideoLibre
@LukeVideo
Jun 06 2018 09:53
Go for it
Pieter Stokkink
@forkerino
Jun 06 2018 10:03
I got a change_form where I added a button that directs to a page where I can upload a csv with some data. That page works, but the change_form page from which it links now gives a NoReverseMatch error.
def get_urls(self):
        urls = super(SiteAdmin, self).get_urls()
        my_urls = [
            path('<int:bron_site_id>/change/add-outputs/', self.add_outputs_view, name='add_outputs'),
        ]
        return my_urls + urls
it seems the more general <int:bron_site_id>/change/ url is not found anywhere anymore, while this was working properly before I added the other page (and this get_urls function)
Reverse for 'add_outputs' with no arguments not found
Pieter Stokkink
@forkerino
Jun 06 2018 10:15
@LukeVideo
:)
Pieter Stokkink
@forkerino
Jun 06 2018 12:09
Fixed it! @LukeVideo , I gave the wrong keyword arguments in the custom template with the button. :smile:
Guess I learned something today.
Luke-VideoLibre
@LukeVideo
Jun 06 2018 12:09
As long as you learn something!
Pieter Stokkink
@forkerino
Jun 06 2018 12:16
Indeed
matrixbot
@matrixbot
Jun 06 2018 13:29
Synekal Can anyone help me mock my User model so that I can unittest using test.Client().post("/signup/") and check if User.profile.some_function() was called?
Synekal This is what my test looks like now
@patch('core.models.Profile')
    def test_signup(self, mock_profile):

        mock_profile.some_function.return_value = {
            'id': 'test_id'
        }
        self.test_client = Client()
        self.test_client.post('/accounts/signup/', self.credentials, follow=True)
        mock_profile.some_function.assert_called()
Synekal The assertion doesn't work in this case. I guess that my patch is wrong - I need to find the place where Profile is instantiated and mock that?
Synekal (Profile is a custom model w/ a one-to-one rel with auth.User)
matrixbot
@matrixbot
Jun 06 2018 13:34
Synekal integration test*, I guess. This isn't really a unit-test
prinxy
@prinxy
Jun 06 2018 21:32
Hello guys, i changed my view from functional view to ListView. After the changes, my login_required decorator stopped working...
please can i need help on this
Dharwin Perez
@dhararon
Jun 06 2018 21:37

You can use login_required in the urls.py
https://docs.djangoproject.com/en/dev/topics/class-based-views/intro/#decorating-in-urlconf

or you can add it to the class
https://docs.djangoproject.com/en/dev/topics/class-based-views/intro/#decorating-the-class

prinxy
@prinxy
Jun 06 2018 22:08
@dhararon thanks alot for your response, but after adding the decorator to the dispatch method, when i try to access a page as an unauthenticated user, i still get a page 404. what i want is to be redirected to a login page instead of the page 404 error that gets displayed
Dharwin Perez
@dhararon
Jun 06 2018 23:07
@prinxy do you have a custom setting of LOGIN_URL? or do you add the parameter login_url in login_required function?
prinxy
@prinxy
Jun 06 2018 23:09
i don't have a LOGIN_URL in my setting.... i will add it now.
LOGIN_URL = '/accounts/login/'
added that but still getting the page 404 error
Dharwin Perez
@dhararon
Jun 06 2018 23:19
@prinxy may you share us you code urls.py and class where are you applying login_required pls
prinxy
@prinxy
Jun 06 2018 23:21
Ok, i will be passing the link to my pastebin soon
prinxy
@prinxy
Jun 06 2018 23:29
@dhararon here is the link to the pastebin