Merken

Hunting for Treasure in Django

Zitierlink des Filmsegments
Embed Code

Automatisierte Medienanalyse

Beta
Erkannte Entitäten
Sprachtranskript
work of the of the of the of the of the and the and the and the but a um
thanks for the introduction of them yes and the set I'm Sebastian I am currently in my main profession is dying web developer and I've done some Python of academic work I think the company can't modify in Vancouver in Canada uh which I just moved to it you know about 6 7 months ago and if you want to find the online I usually found as about the shape and this led to the thought that going to be on line on speaker that this is the we clearly have that later on the slides was lost
and the last time from predators and what I mean by that is we all or most of us are familiar with firms and views and all that sort of good things
that gender has to offer and the things that we use general form
but that alone had were those of us that have worked with it for a long time is now so I'm trying to talk
about a little bit more about and the hidden treasures and what I mean by that
is basically um when you look through the code and hang or you come across like utility functions and things like that that are implemented entangled to facilitate all those other features but they might actually be useful in your project of for your use case and you don't have to write and maintain those little pieces of code yourself and the 1st question
around that is where do you find that and the way I found those was
mostly through either looking at the tango source code itself because I wanted to try and understand this or that piece of code or something went wrong and I didn't quite understand what I did wrong so I had to dig into the call to understand it properly class you and they're nested nature are a very good example for that and and obviously working with smart people that were talking to smart people that so far we have no basically this thing that you were doing over here there is something and I know that already does that and you can just use it and this is my personal favorite source of information is uh funky out that I had the pleasure to meet all over and over again that you might find moment and but he's like the the person to to ask questions on IIsi and he's a great resource and but generally I A C is a great resource to ask questions and then there's um sprinting at conferences and that goes back to like meeting smart people and talking to those people learning what other people do and and picking their brains
so when be doing is I'll I'll just pick a few things out that I've been but that I found really useful and point out like how I use them and what might be a good way of uh for for you to use also
1 of my personal favorites probably is and the cash property decorator so it is basically just a
decorator what it does it's all in the name it's a property on a class the return value gets passed so you don't have to read a compute whatever it is in sight that function so this is basically what it looks like you have your class and instead of using the @ property decorator and there is a cast property decorator provided by dying that catches the result of the function this can be useful for other things like very compute heavy properties or a property that you expose that relates to multiple different tables in a database and you have to aggregate data of some sort or you're accessing a another that API and retrieve data that way so sorry um as an example let's take this class of color object and we have and that objects as a hex value and we have this amazing remote API that for any given x value of a caller gives you the name and you expose that as the property which means every time you have that uh you access that property you make a remote call to the API and this is what it looks like you create your color you access the name attribute in this case the property and it makes a request and the next time you request and that property is doing a remote parts of the IPI as well which is obviously not the most efficient way of doing it and then you got to get to the point where you think like OK I can just that somewhere on the object and 1 of the ways i've done Apple for is you haven't on their name on the same object and you check whether that is non or not and then you start at their ends of only return the cash value after that but it can be so much easier it basically comes down to importing the cash property you from a gender neutral functional and then wrapping up property in cash property and it ends up being exactly that you're basically just doing that remote call once and after that you have a cast on the property and internally it's basically just cast in the double under the date the only thing in this specific case to be aware of this query sets which is this thing that has been me once or twice but you create the quotes that you return that and you think of that's Castile I don't hit the database but actually not what happens because the query sets are lazily evaluated which means you're just uh catching the wrapper query the query set as a wrapper and not the actual database call so if you like in this case retrieve a list of objects you have to um turn that into an actual list for into a set or something like that for it to be cast as an actual um list of objects in in the cache property and that's M. and basically all you need to know is gender utils functional In part cast property these links are basically on the slides for the uh if you wanna look into the slides and find some references this references the docks and the sources to so this
is the 1st letter in Annex favorite of
mine something that I've used some like a little bit and found to be used a little bit
is the imports string in third-party projects and what it does is basically you pass it a strange that is adopted PAF and that points to a class or a function and then it validates that that's a valid path and it returns the imported actual function or a class that you point to and in the case of the request library for example you could just passing requests or get as a strain and what you get back from the import string function is the function object and you can use that exactly the same way you would if you do import requesting user requests or get so where is that going to be useful and well as I said in third-party applications where you're providing functionality to another developer and that developer doesn't have access to the internals of your library like there is only monkey patching to extend some very custom functionality of things like that that could do so in this case it comes in very handy to say um in the settings for general like can basically specify a function or a class that has the that complies with a specific API and then I can use that instead of the default so as an example of him in a works for a product is up a uniquely identified by a slot in that's used in the URL and then you also want to provide your users that you have read this is but store framework written for to customize that's like and because I'm a sucker for analogies I want all of my slides to be so I'm using this custom of images like a fire and and internally uh as the person riding that our a piece of webstore framework called I can basically just take that strain and sigh imports strain and get back whatever that user has 4 . developer has written as cost called past the values as defined by my API contract and then return that there is something to earn that I'm not taking into account here input string still raises an import area there's something wrong so you have to catch that yourself but it's something that's really useful because you don't have to provide all those little checks and things like that that you have to go through when you do this manually that's all taken care of by Daniel so gender you tells marginal loading import import string is all that we need to remember well and it's been can't import bypass previously I think it was deprecated in 1 . 6 and it will be removed in 1 . 9 and so there might the some differences in naming there and this is
the 2nd treasure we found that I found how you and
so the next 1 hour look at is the lazy function and the lazy object and we've definitely are
used it and and that's because settings are basically based on that sort of concept I'm not quite sure whether that's the reason why the lazy object thing exists in the 1st place but it's 1 of the most prominent places where it's used and what it does is basically and it provides a of this a way of delaying the execution of an object by wrapping that callable in another object so as I said it's used in the dying functions and 1 of the reasons it exists is because of the way Django is executed when you loaded some of the pieces that you might rely on in other parts of your cold might not be available at that point but know that you executing that function and 1 of the best examples is that having a reverse lookup for a URL in you're on that either the class attribute level or on the module level all of your call because that code is executed as at parse time and you can't really be sure that your URL config is fully loaded at that point this might actually just return an empty string and you don't really know why so for the this is a slightly bad example because there is already a reverse under lazy as well as some some other under lazy function and in general but it's a very easy way to illustrate the sort of problem and on 1 of the uh problems with that uh well I actually have to make Oracle could make good use of that but I just came across recently which is per-user um storage I had a model and uh File Field on that but I wanted to sort all files in a user-specific bucket so I had history and because we don't have for a user search entangled and it was basically in my way of looking after right a little wrapper and provide that but as to me especially the um general storage implementation
FIL over at that point when I was starting to load my application and it was like wow a well it
turned out that um as the S 3 storage would basically but trying to connect to S 3 at the point in time when the father was pairs and then because I didn't have my credentials from the settings file at that point it would just say like I can't really connect without credentials so because I couldn't put it in any other place is the easiest way to get around that was basically having those 3 lines of code in the you write a function that returns the object that you actually want to have and then you create a simple lazy object and as simple as the object will only return and instantiate that object that you return in your function at the point when its axis for the 1st time and then you can just stick your private storage some object the lazy object into your own far-field definition and it just works so that saved me a lot of time and then you'll find best through uh in the utils functional excuse me the the WTO's functional model and it's actually fairly easy to use them and that is our
3rd treasure and then the
last 1 that I'd like to look at is the Request factory that's actually 1 of the things that I has save me quite a bit of time and in testing so it's not something that you would actually use in your day-to-day call and that you're running in your application but it's something that will actually help you during
testing so it's also fairly simple it takes a you out and um there HE sorry the HTTP method that you're trying to use and then that it creates the jungle request object that you're familiar with in your actual called as well so it behaves exactly the same way but you don't have to go through a full and risk request response cycle as you would do with them and something like the client test case and angle so the easiest way of using it is basically it's in the jungle test manual and you just imported from there His that's similar to what you would do with um requests for example you have a get or a and you pass in the URL and the parameters that you use with that ends as I said 1 of the things and that I I've use it for is testing requests related called for example in views and and something like that where you would have to mock quite a lot of the functionality of the request so that it behaves like a request when which basically then ends of you writing a lot of mocking cold just to get that little piece of functionality when there is something that's already there there can constructed so on very good use case for that uh in my experience is also writing and the lower classes where you basically have those requests responses that are getting past in and processed in certain ways and they can get fairly complex so um In this case you're basically you basically just have some middleware where you've got your logic in the process request and it expects a request so you should pass in a request or something that looks extremely similar to what the request looks like and based on that so having the mocking logic and that and can be quite substantial getting around that is basically have your test function input the Request factory and then having creating your request you can even pass inquiry parameters or things like that and then you just passing that request or manipulate that request in some specific way so you were you know all the type of data that you're passing in and you can test against that and then obviously give Prof proceed with your test as you normally would and that's basically it that's the um you find it in general tests and it might make your tests a little bit faster especially when you're sort of looking at them more unit unit test type testing and it saves a lot of time in terms of marking things
and the treasure is now all yours there is an obviously there is a lot of additional uh traders in the Django called base and especially Django utils is but trough of just like also little functions that clean up your strings and and all those types of things that are really really useful um and maybe just for your specific use case but some of them I'm quite well documented in the general docs so I would encourage everyone to just take a peek under the hood and look at some of those little functions and things like that and just to see what is in there and and maybe there is something that you see OK I've actually written this in 5 places maybe I should just use that program and that
got me quicker through my talk than I intended but that gives you a little bit of time for questions thanks it if a I take this of the whom and so I have a question college this term certain that isn't a giant introducing should be placed on the this the patent can think of that should go into other places little about and yes what we're doing it is um I think the swappable models Our a piece of private API that I really like because I had a sort of CMS fighters case them where it was extremely handy you from library perspective to expose um or give the user the user the developer the ability to swap out a little bit of customized uh um functionality without having to go through like multi-table inheritance or things like that this I think that's a that's a very that would be a very nice piece of call to me when I was impossible with less food here it anything I k so you were you mention this rather these things he new tools some of them admittedly with hidden and has become a likable Maltese and officially have to be supported but for those that could have how do we get the message out there is easy just a matter of dropping of line in the doc servers it is going to get lost the to the stuff to me uh well the ones that I've tried to pick shear as well are the ones that have public documentation are considered public API and so the documentation is there and I'm not quite sure what the best way would be to be more prominent about here is like has property I think last property is actually 1 of the things that quite a few people know all the kids um I think and you can you bring full royal role to package that basically provides that functionality outside of jangle so there must be demand of using it outside of jangle as well um and some people must know that it exists and I wanna knowledge it's probably just like telling people more about it and like pointing out when you see somewhere in in an open source package that someone's writing something that actually has existing general functionality saying like by the way you don't have to maintain that you can remove dolls 15 5 20 lines of code thanks the the the so there are probably a dumb question that everybody else knows hinted to vital so along the mentioned earlier only good places to find treasure was teaching go higher sea channel and where is that um so the IITs you that I assume general is on of free knowledge is faster well past general for the jangle room and and there is a gazillion and chat lines out there that support piracy there is that it depends on like this sort of operating system that you're working on what your preferences whether you prefer working in a text environment or the more you wide-eyed the environment but there I think if you're the best way probably is to just certifier C on the in the dangled arts and there is a reference there somewhere where to find it and how to set it up yeah chart here we go I just want to share 1 of my will spot for hidden treasures which is a lot of these functions that exposed to the template tags and filters are also really useful elsewhere in your code have nothing to do with display templates like you need to store solidified values new database for something you can easily go from Django default filters of course quantified and use that against your 1st mylastname or whatever and what list of technical terms can be imported used the same way outside temple and yes yes thank you all some great thank you thank you and me so that I can he might be and and my my
Rechenschieber
Softwareentwickler
Shape <Informatik>
Menge
Rechenschieber
Web-Designer
Twitter <Softwareplattform>
Gerade
Computeranimation
Bildschirmmaske
URN
Sichtenkonzept
Geschlecht <Mathematik>
Güte der Anpassung
Modelltheorie
Sichtenkonzept
Quick-Sort
Computeranimation
Lineares Funktional
Bit
Code
Besprechung/Interview
Softwarewerkzeug
Bildschirmsymbol
Code
Open Source
Lesezeichen <Internet>
Momentenproblem
Verbandstheorie
Natürliche Zahl
Klasse <Mathematik>
Systemaufruf
Information
Quellcode
Code
Chipkarte
Lesezeichen <Internet>
Punkt
Kategorie <Mathematik>
Besprechung/Interview
Resultante
Information Retrieval
Retrievalsprache
Punkt
Sechsecknetz
Klasse <Mathematik>
Lesezeichen <Internet>
Wrapper <Programmierung>
Attributierte Grammatik
Caching
Lineares Funktional
Sechsecknetz
Kategorie <Mathematik>
Datenhaltung
Softwarewerkzeug
Abfrage
Systemaufruf
Mailing-Liste
Quellcode
Instantiierung
Binder <Informatik>
Menge
Auswahlverfahren
Objekt <Kategorie>
Rechenschieber
Menge
Geschlecht <Mathematik>
Caching
Mereologie
Kategorie <Mathematik>
Kantenfärbung
Tabelle <Informatik>
Proxy Server
Subtraktion
Bit
Konfiguration <Informatik>
Punkt
Klasse <Mathematik>
Besprechung/Interview
Kartesische Koordinaten
Framework <Informatik>
W3C-Standard
Last
Programmbibliothek
Biprodukt
Softwareentwickler
Speicher <Informatik>
Default
Bildgebendes Verfahren
Analogieschluss
Implementierung
Lineares Funktional
Ein-Ausgabe
Biprodukt
Objektklasse
Design by Contract
Rechenschieber
Objekt <Kategorie>
Flächeninhalt
Funktion <Mathematik>
Projektive Ebene
Zeichenkette
Punkt
Klasse <Mathematik>
Besprechung/Interview
Implementierung
Parser
Code
Übergang
Informationsmodellierung
Syntaktische Analyse
Reverse Engineering
Speicherabzug
Speicher <Informatik>
Konfigurationsraum
Attributierte Grammatik
Lineares Funktional
Reverse Engineering
Unicode
Speicher <Informatik>
Systemaufruf
Elektronische Publikation
Quick-Sort
Objekt <Kategorie>
Zeichenkette
Datenfeld
Verschränkter Zustand
Menge
Mereologie
Zeichenkette
Lineares Funktional
Punkt
Softwarewerkzeug
Knotenpunkt
Speicher <Informatik>
Kartesische Koordinaten
Elektronische Publikation
Code
Objekt <Kategorie>
Informationsmodellierung
Menge
Speicher <Informatik>
Gerade
Softwaretest
Bit
Besprechung/Interview
Systemaufruf
Faktor <Algebra>
Kartesische Koordinaten
Bit
Komponententest
Prozess <Physik>
Klasse <Mathematik>
Besprechung/Interview
Term
Mathematische Logik
Middleware
Client
Softwaretest
Einheit <Mathematik>
Code
Faktor <Algebra>
Endogene Variable
Datentyp
URL
Umwandlungsenthalpie
Softwaretest
Parametersystem
Lineares Funktional
Distributionenraum
Sichtenkonzept
Winkel
Güte der Anpassung
Ein-Ausgabe
Quick-Sort
Objekt <Kategorie>
Middleware
Dreiecksfreier Graph
Faktor <Algebra>
Hill-Differentialgleichung
URL
Message-Passing
Bit
Datensichtgerät
Besprechung/Interview
Term
Code
Eins
Informationsmodellierung
Perspektive
Canadian Mathematical Society
Vererbungshierarchie
Programmbibliothek
Softwareentwickler
Default
Gerade
Lineares Funktional
Filter <Stochastik>
Scherbeanspruchung
Kategorie <Mathematik>
Template
Open Source
Datenhaltung
Softwarepiraterie
Systemaufruf
Mailing-Liste
Physikalisches System
Quick-Sort
Chatten <Kommunikation>
Server
Programmierumgebung
Message-Passing

Metadaten

Formale Metadaten

Titel Hunting for Treasure in Django
Serientitel DjangoCon US 2015
Teil 07
Anzahl der Teile 46
Autor Vetter, Sebastian
Mitwirkende Confreaks, LLC
Lizenz CC-Namensnennung 3.0 Unported:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen.
DOI 10.5446/32768
Herausgeber DjangoCon US
Erscheinungsjahr 2015
Sprache Englisch

Inhaltliche Metadaten

Fachgebiet Informatik
Abstract Django is a comprehensive web framework that provides well-defined concepts such as request, response, middleware and view that make our lives as perfectionists with deadlines much easier. What many of us are not aware of is the rich collection of utilities and tooling around these concepts that are part of the famework. Decorators, helper functions and context managers that are used internally but can make life as a developer much easier as well. Introduction (~ 2 mins) A little bit about me. Why am I talking about this? Django's Hidden Treasures (~ 4 mins) The reason for this talks. What do I consider hidden treasures? Which Django modules are interesting? Are they documented and were do I find it? Examples of hidden treasures: A quick introduction of the module. What's a possible use case for it? How does it solve it? Where is it used in the Django? cached property (~ 2 mins) import string (~ 2 mins) lazy, LazyObject and lazy property (~ 3 mins) decorators module (~ 4 mins) classonlymethod decorator from middleware update wrapper and wraps (technically not Django) django.views (~ 4 mins) debug.cleanse setting decorators.debug.sensitive parameters decorators.debug.sensitive post parameters Wrapping up (~ 2 mins) Django documentation links. Some suggestions for further investigation.

Ähnliche Filme

Loading...