#django

/

      • mar77i
        .template_name
      • kezabelle
        in what way was a template not defined?
      • apollo13
        mar77i: why do you need .template_name?
      • koniiiik is a bit behind, finally making sense of what was written earlier. :)
      • dodobas
        what is the preferred way to sanitize user input in Django ?
      • kezabelle
        template_name is only used if you set one. otherwise a template name is derived by get_template_names() (which is the whole point of that method)
      • mar77i
        apollo13: the plan was to use the automatic .template_names everyhwere.
      • graphene has quit
      • kezabelle
        the automatic template name for a createview would be something like app/modelname_form.html (based on apollo13's mention of the suffix) I think, so ... you can that?
      • mar77i
        kezabelle: yeah, but createview doesn't get a template name from get_template_names(), because self.object is None there and the model would be in self.form.model
      • it's just inconsequential.
      • kezabelle
        ... so set the model on the view
      • apollo13
        mar77i: you'd set the model on the view class
      • graphene joined the channel
      • koniiiik
        dodobas: Sanitizing input is not the best way to look at the problem, really – it's better to ensure that you properly render any unsafe values on the output in a way that makes sense for that particular output.
      • mar77i
        that's what I'm doing. it just confused me because the way I was reading the code up to that point suggested that for form-like views the model was available through self.form.model.
      • kezabelle
        dodobas: santizing in what way?
      • mar77i
        only that it's being missed out by get_template_names()...
      • koniiiik
        dodobas: Unless, of course, you're talking about validation of user input, which is a different thing. :)
      • kezabelle
        is there ever a self.form?
      • mar77i
        look, the fact is that SingleObjectTemplateResponseMixin is not written with edit.py in mind, and that's an oversight.
      • kezabelle
        why is that an oversight?
      • it's already generic to a single-object, and derives its templates from that
      • dodobas
        kezabelle: it's a 7years old project that is abusing mark_safe/safe to render chunks of templates and JS, so ... it's not perfect
      • mar77i
        because all other edit.py views are perfectly fine not specifying a model because there's self.object, which get_template_names() takes care of.
      • dodobas
        koniiiik: yeah, validation also works
      • roadie has quit
      • mar77i
        only createview doesn't, and hence needs a model and it really took me a long time to figure out why the view wasn't configured correctly (missing a model, and therefore missing a template name).
      • dodobas
        just want to stop saving junk in the database, which might render somewhere ... :)
      • kezabelle
        dodobas: bleach for HTML, probably.
      • dodobas
        no one wants to crate a company named `<script>alert('XSS attack!');</script>` until they do :)
      • mar77i
        bleach is nice.
      • koniiiik
        mar77i: So what you mean is that you'd like for ModelFormMixin.get_template_names to also include a fallback in case there's no model defined directly on the view class, but there is a form_class, and it happens to be a ModelForm, to use the model from that as the model class?
      • mar77i
        koniiiik: you understood the problem, but I think you're also touching the topic of it being a bit contrived. I think for ModelFormViews there might be a second subclass of SingleObjectTemplateResponseMixin, or even a simple @property model(): return self.form_class.model, as I suggested earlier.
      • koniiiik
        mar77i: The property thing does not sound like a particularly good idea, since model is already used as the class attribute that you as the user override to configure the form class.
      • I mean the view class.
      • Dang. Too sleepy.
      • mar77i
        yes, but overriding it wouldn't actually do anything. it just wouldn't be needed.
      • emihir0
        again why do you not want to specify model at the view?
      • kezabelle
        mar77i: but then you can't automatically generate a modelform, because to do so depends on the model, which depends on the form_class, which depends on the model
      • schubmma joined the channel
      • mar77i
        hmm. interesting. so therefore the CreateView example includes a model, while the FormView example doesn't. https://docs.djangoproject.com/en/2.1/ref/class...
      • kezabelle
        because a FormView doesn't have anything to do with it being a ModelForm
      • koniiiik
        FormView is for generic forms, not necessarily for ModelForms.
      • emihir0
        https://ccbv.co.uk/projects/Django/2.0/django.v... -- you *need* the model in order to generate a ModelForm in CreateView...
      • RCStef has quit
      • RCStef joined the channel
      • koniiiik
        Unless it's already set as cls.form_class, though.
      • mar77i
        I think I transitioned from one to the other without reading further. Okay, I probably shouldn't expect django to cater my bad reading habits.
      • cryptopian has quit
      • luxeve has quit
      • LiftLeft2 has quit
      • webbyfox joined the channel
      • inad922 has quit
      • kapil___ joined the channel
      • govg joined the channel
      • cryptopian joined the channel
      • esrse has quit
      • CtrlC joined the channel
      • schubmma has quit
      • fikka has quit
      • Katharsis
        https://pastebin.com/raw/ub2j50zd what does this ModuleNotFoundError exception means in the context of Django test execution?
      • dziadekludojadek joined the channel
      • fikka joined the channel
      • jtiai
        Please do not use pastebin.com as instructed in the topic.
      • kezabelle
        Katharsis: its an ImportError subclass, so it means it couldn't locate your urlconf
      • Katharsis
        which one? the main urls.py?
      • kezabelle
        maybe? could be any of them tbh
      • but probably your main one would be a good place to start debugging
      • Katharsis
        I have demo project without custom apps with Django admin panel only
      • kezabelle
        whats your tests_settings look like?
      • ... and whatever runtests.py does, I guess
      • Katharsis
        kezabelle: from .settings import * and custom DATABASES
      • dziadekludojadek has quit
      • moldy
        Katharsis: can you show us runtests.py?
      • dodobas
        did you know that there is a band called Django Django, #artrock ? :)
      • Katharsis
        sure
      • geekodour08 has quit
      • kezabelle
        yeah, comes up frequently when I type django/django into my address bar before the autofill to master turns up :\
      • moldy
        Katharsis: ehm... you copied that file into your project?
      • Katharsis: that file is for running django's internal tests, not for running your own tests.
      • Katharsis: what happens when you run `./manage.py test --settings=demo_app.tests_settings`?
      • Katharsis
        I want to run these tests for my custom django backend which is a copy of PostgreSQL DB backend
      • moldy
        ahh
      • Katharsis
        Ran 0 tests in 0.000s
      • OK
      • kezabelle
        well, that runtests quite clearly includes a urlconf of "urls", and there's a urls.py next to it, so I'm guessing you don't have that ...
      • moldy
        i'm not familiar with django's internal test suite, but it wouldn't surprise if you have to run runtests.py from a specific location
      • kezabelle
        moldy: yeah, `cd tests; runtests.py`
      • crCr62U0 joined the channel
      • geekodour08 joined the channel
      • jalalsfs has quit
      • webbyfox has quit
      • luxeve joined the channel
      • K-ballo joined the channel
      • csotelo joined the channel
      • jalalsfs joined the channel
      • xliiv joined the channel
      • BPL joined the channel
      • adsworth has quit
      • encod3 joined the channel
      • eperzhand has quit
      • DarlingBooster joined the channel
      • DarlingJ joined the channel
      • inad922 joined the channel
      • xall joined the channel
      • csotelo_ joined the channel
      • csotelo has quit
      • k_sze[work] has quit
      • jaddison has quit
      • aossama has quit
      • DodgeThis has quit
      • giarc joined the channel
      • aossama joined the channel
      • inad922 has quit
      • crCr62U0 has quit
      • geekodour08 has quit
      • geekodour08 joined the channel
      • Xorg has quit
      • DarlingJ joined the channel
      • csotelo__ joined the channel
      • cryptopian has quit
      • csotelo__ has quit
      • pwrentch joined the channel
      • csotelo__ joined the channel
      • crs has quit
      • csotelo_ has quit
      • crs joined the channel
      • csotelo__ has quit
      • csotelo__ joined the channel
      • inad922 joined the channel
      • Leeds joined the channel
      • jtiai_ joined the channel
      • dodobas has quit
      • jtiai has quit
      • dodobas joined the channel
      • Meraki joined the channel
      • ggj joined the channel
      • VikingHoarder joined the channel
      • Meraki
        How do I implement multiple tokens per user authentication in djangorestframework
      • Myk267 has quit
      • azulakina has quit
      • zeus1 has quit
      • jtiai__ joined the channel
      • cgfuh joined the channel
      • jalalsfs has quit
      • azulakina joined the channel
      • LogoS[ES] joined the channel