Back to the video

Lightning Talks II

Transcript

By Speaker 1, Speaker 2, Speaker 3, Speaker 4, Speaker 5, Speaker 6, Speaker 7, Speaker 8. From DjangoCon Europe 2018. Published May 24, 2018.

Watch the video Markdown version 7,200 words · auto-generated · en

Summary

The lightning talks cover practical Django-adjacent projects and lessons: Peter Kierner explains C3VOC’s Python/GStreamer-based system for mixing, recording, streaming, and automating conference video; Arne Delat shows how a Django application manages cosmic-ray detector data used by schools; and Lacey Williams Henschel gives concrete advice for finding ideas, reading CFPs, writing proposals, and getting feedback. Leila Verhoeven describes building a blue Python-powered clock despite hardware and memory constraints, Lorenzo Peña presents a proof-of-concept combining django-tenants and django-polymorphic for multi-tenant user hierarchies, and Daniel Hepper demonstrates custom Django 2.0 path converters that can resolve URL parameters directly to model instances. The event’s running catering story provides comic transitions between speakers and ends with a pun about why the Australian stand has no queue for drinks.

Transcript

Automatically transcribed, so expect mistakes in names and technical terms. Filler words are removed.

0:00 Lightning Talks Introduction

Speaker 1

As a last point today, we have lightning talks again and I think we were all looking forward to that. So I'll just hand it off to Russ again.

Speaker 2

Alright, it's time for lightning talks again. So we all remember from yesterday what the deal is. Five minutes, no more. But can be less if you want to, and we do like people who do less because it means we get more talks through. There is a gong over here that will be attended to by my lovely assistant who will make sure that whoever is over here gets the message whenever their time is up. There is a timer down here we're keeping time to and wh while we sit here and wait for people to get their AV set up, I get to regale you with delightful stories about The individual yesterday who went was dealing with the wasps after meeting the head of the WASP con as a as an expert wasp observer. Got involved with the organization of WASPCON and catering is a very big important

part of any conference as we all know. But stories of this will progress first up on stage we have Peter Kierner talking about recording lectures with Python and G streamer. Everyone please welcome

1:20 Lecture Recording with Python and GStreamer

Speaker 3

I Peter, I would like to give you a small introduction to the soft and hardware we are using here in this venue and a lot of other conferences to record live streams of lectures and doing live streaming and recording. I can switch my slides. I'm from C3 Rock. We are the video operations center of the CCC. You can find a tons of information about video recording and streaming and production and distribution in our wiki and it's really not all that cleaned up but it contains tons of information you can find me personally at under this nick on twitter and This is part of our pipe of our pipeline. It's only half of it. The upper half is concerned with capturing

video signals from speaker notebooks and audio and video signals from the cameras around the lecture room All those signals are then fed into Vocdomix, that's these parts, and it's a Python and GStreamer-based mixer solution. You can see from the schematic that it's basically split into two halves. One is VoctuCore, it's the like a headless server, and the other one is VoktuGUI. This is the streaming diagram, block diagram of VoctoCore. It basically acts as a network server accepting and providing video feeds on TCP ports. The mixing pipeline we implemented is very specific for lecture recording. You can transmit a nice pause animation and some elevator music during a break while continuing to recording

the actual content so if you accidentally miss hitting the go live button you still have a useful recording. The mixing pipeline also can handle multiple audio feeds for live translations for example And it probably can be extended to do other nifty crazy stuff. From a code perspective, it basically looks like this. We are plugging together GStreamer pipelines in Python are strings and then giving them to GStreamer to parse them. GStreamer then implements builds a multimedia pipeline from it. It's like Lego for audio and video. You stick together the pieces you need. The UI looks like this. It connects to VoctuCore via TCP network, and when you press a button, it sends commands over there over a simple line-based protocol.

So writing new GUIs or other interfaces is quite easy. You can literally mix video with Netcat and Telnet. It's really trivial to automate. Just one example is are these little guys, we have them here on our cameras. They are Raspberry Pis that connect to the VoctoCore and receive the line-based protocol and turn the light on the LED on whenever the camera is live. You can find all the code and a lot of the documentation in GitHub. And if you want to talk to us and have questions, please visit us. We are upstairs there. If you go upstairs, please be a little bit quiet. Oh they're winking. Rink again. Way If you go upstairs please be quiet, but you can al always talk to us and we're really open and welcome to explain to you

What we're doing. And because we have a really nice setup here, I have some pictures, this is the main camera that's right there in the middle of you. We have a second camera above there. And we also have like this is a really nice view from our mixing console upstairs. So thank you very much. And if you have any questions, please approach us and we will explain you how to set up your own video recording for your own conferences Thank you very much.

Speaker 2

Thank you very much, Peter. While we get our next speaker set up. So he gets this guy gets the job to organize the conference catering and so he goes out to like essentially a conference to go and for get f where all the vendors turn up and show their wares and talk about what they what they can do and what they can provide for your conference. And then this place has got tents set up and every vendor has their own tent where they can you know demonstrate how they can serve food and how much food they can serve and what have you. And so he turns up and he sort of walks into the first tent. And the first tent is selling essentially German-themed food. There's like there's a selection of Wurst and sauerkraut and homemade mustards and There's some decent cues, people drunk lining up to get in there. And then there's some really, really long cues because they're also serving beer in the tent, and the you know the longest cue

is to get to the beer. So this guy stands there, he tries the food. He says, Yeah, this is all very good food, but you know the cues are a bit of a problem, particularly the long lines for the drinks. People are willing to wait for you know food for a little bit, but you know you really don't want to get 'em waiting too long for a drink. So okay, maybe I'll I'll I'll try again. I'll I'll try and try another location, another one of the tents and see where maybe where that's going to be better suited to our needs So he goes on to the to the next tent. The next tent is an American barbecue themed tent. They've got all sorts of different barbecues, a southern barbecue, a Texas barbecue. Kansas barbecue that are all very don't ever get into a barbecue discussion with an American. They get very, very touchy about barbecue. And so there's all this barbecue and there's fresh coleslaw.

And there's no some decent cues again, people lining up and getting their food, getting their barbecue. But then there's then there's some freshly squeezed lemonade is the sort of the drink that they're offering there. Again, really long cues for this fresh squeeze lemonade, but because it's really good, but also it just takes a while to produce to get a good glass of lemonade. So there's these long cues and The guy's in there and he tries it out and the food's really good. Barbecue's really good. Good selection of barbecue and the coleslaw that goes with it's really good as well. And still going, all right. The but and the again the lemonade is refreshing and it's and it's tasty, but again, long, really long lines getting to get this get yourself a drink. So okay, this is probably not gonna be the one for us. Are we nope?

Alright, so he tries the next tent. This is I'm moving through far too many of my tents here. I'm gonna have to invent some new tents. He gets through the next tent, and the next tent is a different type of barbecue, this is Brazilian barbecue So Brazilian barbecue, if you don't know, is basically all about meat. Brazilians really do like their meat. So he goes in and he says, okay, yes, here we go. Some. beautiful meat on the on the on the great big skewers. If you've ever been to Turoshia, it's a fantastic way of having sort of Brazilian barbecue. And the vendors there are slicing big pieces of meat off of the off of the skewers and serving to each of the individual patrons as they turn up. Being Brazilian though there is no salad that goes with it, it's just the meat. And they've also got

still waiting for yeah, okay, we're still going. We he's going through the they've they've got a caprinha station there 'cause the Brazilians they do make a very good caprinha made out of you know really good imported cachaça Delicious, but again, reasonable cues for the food. They can get the food out going out relatively quickly. But the drink station it takes a while to mix a good c caprina, so there's a there's really long lines for the for the caprinias. And so he moves on this to the next tent. Next tent is Italian themed tent. Have we got an ETA at all? I'm whether we're kicking EHR.

Yeah, so it's an Italian themed tent. And it so it goes in there and it's as you predict the sort of the pastas and meals like that with some nice salads on the side as well. This was not the agreed pattern. This is gonna turn into a five-minute joke in between all the other da all the others. Alright, so we're getting another laptop lineup. So it's the Italian themed booth we have the Italian the Italian themed meal. We've got the pastas and the pastas are all there and there's some salads. And of course it's Italian, so we've got some good red wine there and they've got the red wine coming out. But again, decent cues for the food.

People are moving the food through relatively quickly, but then the lines for the for the for the for the drinks for this red wines. Really, really long lines as everybody gets their gets the gets the gets their drinks This is a possibility. I might get a breather here. We're getting we're getting close. Flashes. Oh, we're waiting for flashes. Okay sorry okay the guy organizing this conference is starting to get a little bit concerned. It seems to be a recurring theme here. We sort of go into all these boo booths, really, really good creative food vendors producing really tasty food but there's long lines at every drink station that they turn up to. And that's full screen either.

Speaker 4

And S D R G L

Speaker 2

and That's the line up there. Yeah, there we go. Alright. But he can tell that that he's gonna have to keep looking. I'm gonna have to keep looking as well. To see if he can find the vendor that's going to be right for him. And are we get downloaded first? We've got to download the whole okay.

Speaker 4

And then it would work.

10:54 Cosmic Ray Research with Django

Speaker 2

There you go. There we go. Alright. So The search will continue after the break. Next we have right up here on stage now we have Arne Delat with cosmic ray research with data analysis via Django and some astroparticle physics. Take it away, Arni.

Speaker 5

Good afternoon. I now work at Localo doing web development. My previous job was doing astroparticle physics. Astroparticle physics at NICEF in Amsterdam. There I analyzed stuff with supernova. So this is an image of a supernova explosion where a star explodes. The shell of particles being ejected by the supernova accelerates particles which are just out there in space. It picks them up and accelerates them and using big magnets it keeps them until they're fast enough and then injects them all throughout space. Some of those particles moving at almost the speed of light hit the Earth. Then this happens.

There's a particle at the top and it hits another particle in our atmosphere and there's so much energy that they create more particles and those particles have enough energy to collide again and create more particles until you have on the ground maybe between one and several billion particles. Those are just electrons, muons, which are the slightly heavier version of electrons. And there's yeah at High Spark we detect those particles. So in the top right you see a scintillator which glows a bit if those particles go through it. We wrap those in light tight plastic and then we put them in those keyboxes. and there are photomultipliers connected

which see the scintillator glow and they convert that to a strong elektrisch signal. Then you have the little box on the lower right left and it converts the elektrische signals into bits and bytes and it continuously reads out the signal every two and a half nanoseconds so you get this really sharp signal. And then we put several of those detectors very close together so you can see if multiple of them are hit then you have are dealing with one of those air showers. If only one sees something then it's probably some background radiation. Not interesting. So this is how the network looks like you have huge things in space which shoot out these cosmic rays these cosmic rays interact in our atmosphere

and we have several detector stations and they detect These events, all the data is sent to the NICAF in Amsterdam where we do a bunch of data analysis, and there's this nice Django application which does all the bookkeeping and manages all this. So there are about a hundred of these detection stations. Most of them are at high schools. So it's an outreach project. High school students build these detectors, they put them on the roof of their schools. They can then work with the data from their station, from all the other stations, and do nice experiments, see what they can learn about relativity, quantum physics, and other interesting stuff. This is an example of an event at the Science Park in Amsterdam

where there are several stations very close together. The color indicates the arrival time, so more blue is earlier, redder is later. So you have this one particle coming from outer space, it creates all these new particles and they all go at the speed of light. So you basically if you Take a snapshot, it's all these particles in the flat plane. So they also hit the ground in that plane in that plane. So first they hit on the right and then a bit later there and there and there and there. So using that timing difference you can get a sense of the direction of this air shower and using the number of particles which is indicated by the size of the blobs. You can guess where the center of the core was and then you know something about the energy of the air shower, you know something about the energy of the cosmic ray and you might guess where it came from

with the direction. It's all very interesting. So we have a lot of teaching material and tools for these high school students to work with this data. A lot of documentation, all the code is open source, so the code running on the detection stations, the Django that's Managing all the data coming in. This project has been running since 2004. There's about six billion events that have been detected which is about six terabytes of data which is then reduced reconstructed and all that data is made available via nice apis and we provide a nice JavaScript tools to do stuff with it and Python framework to also do analysis with it. It's all very nice.

And yeah, this used to be a movie, but now it's a PDF because it was on my laptop. But maybe I can show it quickly and but yeah. Oh, where's the slash there?

Speaker 2

Alrighty, thank you very much, Anne. Okay, so whilst our next speaker gets set up, the search continues for the purpose perfect conference food. And so having been to the German tent and the Italian tent and the Brazilian tent the and the US barbecue tent, the guy walks on to the next tent. The next tent is a Mexican tent. And so they've got a little essentially little taco truck set up in there So they've got the people behind the counter furiously making tacos for everybody and they're beautiful. I have fish tacos and chicken tacos and beef tacos, and they're all fantastic. And then I've got a little margarita stand on the side, so they're making margaritas for everybody to drink while they're at it. And are we good to go Yeah, so again, I think we've got the long lines for the margaritas, but the rest of the food goes through well. But the long lines are a problem. Need to look somewhere else.

17:14 Proposing a Conference Talk

Speaker 2

Our next speaker is Lacey Williams Henshill talking about how to propose a talk. We went like a welcome.

Speaker 6

I have to figure out where to stand because I'm really short But I don't have a clicker either. So yeah, I wanna talk to you about how to propose a conference talk because I work on conferences and I speak at conferences and so I've I've done this a few times. I need to stay over here though so the mic catches me So the first thing that you need to do a conference talk, oh, there's the timer over there, that's nice, is an idea, right? And so where do you get ideas? So you can think about what have you learned recently. My personal opinion is that the most qualified person to speak on a given topic is the person who was most recently completely perplexed by that topic. Because you know what you had to do to get over that hump to figure out how to understand that. Sometimes you have really strong opinions about something, like you think that testing should be done a very particular way, or you think that code should be organized in this very, very specific way.

You can share those very strong opinions with a group Sometimes something that that really confused you now makes sense to you. And so again, this is related to one, but it's it's also its own separate thing. So there's learning a new thing. But then there's taking a thing that you kind of understood before, and then finally you really, really, really understand it. For example, Katie's talk about the ORM. Then you need to think about your talk a little bit. So you want to think about is your how broad is your topic? So like I said, for example, testing You really can't just give a talk about testing in about half an hour, right? Like a general topic, a general conference talk is about 25 to 30 minutes. So think about can I sum up this topic in two minutes to someone who doesn't know very much about it? Like hit my high points.

Get my arc, and then you know, okay, I've got a decent idea. Once you have an idea and you're thinking, I am ready, I want to propose this talk, You want to find the CFP. CFP stands for Call for Proposals. And the first thing that you want to do is read that CFP carefully. Not all CFPs are created equal. They all have their own special requirements. They also all have deadlines and it is very unfortunate as an organizer whenever someone emails you and they said, Oh, I'm so sorry, I just missed the deadline, I had it wrong in my calendar. You don't want that to be you, so you want to pay very close attention to the deadline and also attention to the time zone that the deadline is in Finally, you want to make sure that you know what the anonymity requirements are, right? So a lot of CFPs require an anonymous submission.

So you might be tempted in your talk to talk about your credentials, and there's certainly place for you to do that, but you want to make sure that if this is an anonymous review process, that you're not putting identifiable information in the body of your proposal. Finally, or not finally, the next step is you actually have to write the CFP, right? You have to write your proposal, get it ready to submit. In general, you're going to want a short abstract, which it gets printed in the program or put on the website that's about 300 characters. Then you'll want a longer description that gives the organizers a chance to see that that you're you're prepared to talk on this topic, that you know what you're doing. Sometimes you want an outline. Some conferences even want you to have an outline that includes the time. So you, you know, you're gonna spend one minute on the introduction and you're gonna spend three minutes talking about this.

Those are kind of annoying, but you have to do it anyway. So make sure, again, read the CFP closely and make sure that you're following their prescription. Then you want to write your bio. And this is the thing that really trips people up. It is really hard to write about yourself, like it sucks a lot. So there are some tools online that can help you. I will tweet those later on, and you'll notice that my Twitter and a couple of other Twitter accounts are at the bottom there. So yeah, you'll want to prepare some kind of statement about yourself that again gets put on the website, maybe printed in the program to let people know who you are. Then you'll want to edit your CFP. So this is before you submit. Don't just type it all into the window and then hit submit. You want to run this by somebody. So you can run this by your friends, you can run this by colleagues at the place where you work or people that you've worked with before.

A lot of times conferences will have speaker mentors, so you can go to the website or email the conference and see if that's something that you can take advantage of. You can reach out on Twitter and say, hey, I want to submit a talk on this topic. Will someone review this? And people will say yes. They will just say, hey, send me the link and they will give you feedback. Also, Slacks that you're in are a really great opportunity Then you actually hit submit, and this is a really proud moment, right? But you might have some concerns about speaking at conferences. So for example, you might wonder if you know enough to present on a topic, and the answer is yes that you do You also might be worried about how much it costs. A lot of conferences have financial aid. You might be concerned about your work and whether they'll support you. You should just ask. My experience is that a lot of bosses, if you're if you're speaking, will say yes. And you might wonder if you'll get rejected.

So I if you have spoken at a conference ever, raise your hand. If you have never been rejected from a conference, keep your hand up. Or like I guess oh I'm sorry, I did that wrong because I'm running out of time. But basically there are two CFPs that are open right now. I have two seconds left. Take a picture of this slide, DjangoCon AU and DjangoCon.

Speaker 2

Thank you very much, Lacey. Okay, so we've Mexican didn't work out, so our Next speaker next vendor that he tries out is the Spanish, Spanish vendor. And inside the Spanish tent they've they've got a little tapas bar set up. So you know pick up your own little pieces of tapas from the from the from the selections that are there. And there's a you know really wide selection of tapas, quite impressive. Not too bad cues going on with what's there and the drinks is they they're serving sangria, which is you know lovely, but again, really long cues on the sangria. So this is gonna be a problem. It seems to be a recurring theme. It's like the food doesn't seem to be an issue. People can get the food out relatively quickly. But the but the but the drinks lines are becoming a bit of a concern.

Are we good to go? Yes, we're good to go. Alright, so our next speaker is I made a clock in Python, Leila Verhogen Take it away.

23:22 Building a Clock in Python

Speaker 7

Hello. Well hello, my name is Leila and I will talk to you about making a clock in Python. So a few months ago my clock was broken, just like this one. And I wanted a new one. With a few basic requirement requirements. it had to be blue and the time had to be visible when it was dark. After searching a lot and only finding red and green and or green ones, I finally decided to make it myself. To make this clock I used an M0 Twin Cat R T C module and a blue squad seven segment display on its driver. I also used a breadboard and a lot of wires.

As you can see, I used a medium and a small whiteboard. On the top it's a secret page, it's the secret without component. And on the bottom, the thing in the middle, it's three from three volt to five volt one way logic converter because the data sheet say the OTC and display drivers needed 5 volts and the twinket outputs 3. 3 volt But I should have a two-way logic converter to this to this to work and I didn't have one. In the end, it turns out both the RTC and the display driver

work fine with a three point three vote signal, so I got with of the logic converter altogether. At this point I also decided to use a single radium breadboard so I had to make a new circuit Both Ltc and DisplayDriver come with their own Python module, but both modules don't fit in memory at once. So I had to write my own dead time management library to under the RTC module to and save some memory As you can see on this photo, the clock finally works after four days of making circuits and two hours of writing code. And it was very, very satisfying to see it work

Well, after my success with the small clock I now want a bigger one. A slightly different one. I decided to make one with pizza boxes and NeoPixels. If you don't know, Neopixels are bright LGB lead. Right now this project is still work in progress because I haven't time to finish yet but I think I will work on it after this conf. If I talk to you about this clock today it's because I know that sometimes We want to give up, but I also know that if we preserve we can climb mountains and even more Thank you.

Speaker 2

Thank you very much. Okay, can yep, let me take a station then. Here we go. Yep, all right, there we go. We have another speaker. So The search continues. We've tried Mexican, we've tried the Spanish, we've tried the American barbecue, we've tried Brazilian barbecue, we've tr The German All got the same basic problem going on here. So we start next okay, we're going to the there's an Indian tent in the Indian subcontinent India that all sorts of curries, so it's you know large, large sort of bamarie trays filled with all sorts of aromatic curries and you know add a bonus some of these a lot of these are vegetarian, they're all still really, really great food. And you know big one big b bowl of rice to serve out as well. So Relatively fast moving cues getting to all of the all of all of the curries that are there. But then there's the drink station. They

're making mango lassies, yogurt, yogurt drinks and again, really long cues on the on the Mango Lassie for some reason. So okay, so this probably isn't going to be the one we've we've got a problem with the long cues again. So the search continues. Our next speaker is Lorenzo Peña talking about multi-tenant polymorphic users

27:42 Multi-Tenant Polymorphic Users

Speaker 8

Okay. Hi everyone. My name is Lorenzo Peña. I am Laurincos at Twitter, GitHub, Facebook, Gmail, and pretty much everywhere. I come from Holging, Cuba, and it's a great privilege to be here today. Big thanks to the YangoCon crew. This is my first YangoCon ever, my first time in Europe, my second time outside of Cuba. My first time publicly speaking in English and my ninth year in the exciting world of Yango. I somehow expect that nine to compensate for all the former ones and twos The code name for this lining talk is MTPU, which stands for multi-tenant polymorphic users, which in turn is the fanciest name I could find to summarize the otherwise longer Quick recipe for creating a simple software as a service with user hierarchies that gratefully downcast based on the current tenant. So big dicks disclaimer, this is just a recipe.

I didn't create any of the ingredients myself. This is Only intended as a fun experiment. This is no silver bullet for anything. Consult your doctor before attempting this on production environment. Ready? Okay, here we go. Suppose we own shiny domain. com and we want to build a shiny software as a service using a single Django project. At www. shinidomain. com we're going to have the corporate side where our customers will acquire private space at whatever name they choose, shinidomain. com So far so good. Now come the users. For most practical cases, we might not want to store the same information for our possible user types in a project like this. Think of it at the W site. We're going to have our corporate users who should be dealing with tenant management, customer service, all sort of super cool enterprise cover operations and hopefully payment processing And at any subdomain chinidomain.

com we're going to have the user structure that makes sense at the application level we are offering as a service and isolated users. It could be a single user type or it could actually be a hierarchy of user types. Yango Contrib Alth comes with default user model and in order to store all relevant information depending on the user type, we could fall back to using profile models with one-to-one relationship to the user. as is still suggested somewhere in the Yango Docs. However, that would take all the fun out of this experiment. Besides, there is another implicit way of creating one-to-one field. So we are going to use a custom user model actually a custom concrete base user model that other user models will inherit to create a hierarchy so cooking time Here are our selected ingredients for the MTPU recipe. For solving the multi-tenancy problem in a single Yango project, we're going to use Yango tenants.

It relies on Postgres schemas to isolate tenant tables within a single database. And as other packages that rely on post-grid schemas, it creates a new schema for every new tenant while keeping all shared tables in default public schema. For more ingredients like this Can be found at the fresh market, aka Django Packages. com under the multi-tenancy grid. And for handling not too complex model hierarchies, we're going to use Django Polymorphic. With this package, if we define models that That use concrete inertance, we can query the parent models and get the downcasted instances. So if we have places, restaurants and bistros where place is the base class for restaurants and bistros We can query places and get not just places instances as vanilla Yango returns, but the actual type of existing instances. This comes at the cost of some extra joints, some drag in performance, and a little bit of dark magic.

But shouldn't be a great problem if the hierarchy is not super complicated model tree. Again, more ingredients like this can be found on the model inheritance grid of YangoPackages. com. So how these ingredients work together first Forgetting polymorphic users, we just need to define a custom user model and inherit polymorphic model. We might want to inherit also abstract base user to incorporate common user functionality. Just make sure polymorphic model is the first one in the list so that polymorphic behavior actually works We must also define a manager that needed its polymorphic manager and uses default manager for the base user model. For Yango tenants to work properly, there are some preliminary steps we need to take. like creating the tenant and domain models. However, we are going to spare the details here for the sake of time. The only thing we are going to cover here is tenant and shared application. They're not tenants As the concept of shared apps and tenant apps. With this the regular settings for install apps become just another union of the former

models in shared apps will live in the default schema while models in models in tenant apps will live in every other schema that is created for a tenant. If the same app is provided both in shared and tenant apps Its models will live in all schemas, but notice in the context of any tenant tables in tenant schemas will take precedence over those in the public schema. There is more to talk about this. We can skip the correct details for now. So all you we just have to do is know where to place everything and since we don't have time anymore and this we could be in the side inside the cage I'm just going to leave here proof of concept if you want to see it in action. Thank you very much.

Speaker 2

Thank you very much. All right, we have our one last lightning speaker to talk to talk today while they get set up. Our intrepid wasp expert is starting to get a little bit desperate. He is really trying to look for a The perfect cuisine that is going to work and be able to be served quickly to a you know the large wasp enthusiast audience. And he finally comes across the Australian tent. The Australian tent is sort of this weird Asian fusion thing, so it's like kangaroo carpaccio or kangaroo and there's there's emu satay. and all sorts of weird combinations of Australian foo, Australian native animals that are done in a sort of a vaguely Asian sort of style, which is And it's sort of unusual. It's but he you know there's still there's still people here, so obviously it can't be bad. So he lines up and he

gets in the queue and this food's really, really good. It's been expertly prepared and it comes out quickly. And so okay, so and then he goes over and looks for the drink situation. And there's a there's a they 're serving a fruit punch, there's a native Australian fruit punch, which okay sound sounds good, but there's n there's no line. There's no line at all This is this is weird, so I s I have to work out what's going on here. Our next speaker is the is Daniel Hepper talking about the hidden powers of custom Django path converters. Thank you very much.

33:44 Custom Django Path Converters

Speaker 3

Hi, I'm Daniel and I want to show you a somewhat obscure feature I

Speaker 8

that's new in Django two point zero So who read the release notes? What's new in Django two point oh? Yay, no more regular expressions in URLs. We have a simplified URL routing syntax instead of using URL with a path with a regular expression in it, you use the path method with a capturing and to capture an URL argument you use angle brackets and After the column that's the name of the argument and before the column that's a so-called path converter, which you can define. So path converter converts. So it in this case it converts the argument into an integer so your view will actually get an integer and not a string as it used to be. So there are a couple of built-in path converters.

Under the hood they still use a regular expression so string, integers, slug, path, and also UUID. But now you might say, wait a minute, that's not really feature equivalent. The regular expression that accepts exactly four digits and an integer can be like any number of digits, basically. So that's where custom path converters come into play. It's a plain class that has again

Speaker 3

a regular expression. So if you hate regular expression, kind of bad news. And it has a two-Python method, which handles the converting from the URL to the Python object, and it has a two

Speaker 8

URL method which handles the reversal. So now we for our four gig URL pattern that's the you the custom path converter. To use it you have to register it and give it a name and the name is what you then use in URL. So far so good. That's all in the documentation. But this line caught my eye. what happens when that value error gets raised. You might expect that you get a server error or something like that, but actually the conversion is part of the matching.

Speaker 3

So if a value error gets raised the path just doesn't match. So how can we use it? Let's say we have a URL which gets an ID and then you have an a view which gets an object or returns a 4 by 404 and you also have a URL tag in a template that does the rehearsal.

Speaker 8

Now you can write a custom converter class which fetches the object in the toPython method and raises

Speaker 3

a value error if the object doesn't exist. and

Speaker 8

the two

Speaker 3

URL method just takes returns the ID of the object. You register that converter and give it a name. In this case I was not very creative so it's a question converter And now your

Speaker 8

view receives a question object and you can also just pass a question object to your r URL reversal.

Speaker 3

Now you don't want to write a converter for each model obviously, so you can generalize that and I wrote a register model converter method which dynamically builds a model converter class. Which you can use like this. And by default it just uses the name of the model as the name of the converter. Then I came up with a couple of other useful features like passing an optional name and using a different field for lookup and different using a different base class. If your

Speaker 5

for example your primary key is a UE ID, you can also pass a query set.

Speaker 3

That's where the advertising part starts. I packaged that in a Python package which you can just install with pip install Django model path converter. And then you just do register model

Speaker 6

converter. with your model class. And then you have views in your

Speaker 8

models in your view. Here

Speaker 3

are the links to the PyPy and GitHub and also my Twitter and my email if you want to tell me why that's a bad idea. Thank you

Speaker 2

very much. The Lightning Talks for today. Thank you very much to all the Lightning Talk speakers. Thank you very much to our delightful gonging person who didn't have a great deal of need to gong because everybody was under time. That's wonderful. One last issue that we have to work out though is why was the Australian queue able to why were they able to get through the drinks so quickly? And so the guy who's organizing WASPCON comes up to the goes to find the manager of the Australian tents says, so what's the story here? What's going on? Like everyone else, I've been to all these other tents, I've been to Mexican tents, I've been to American tents, I've been to Brazilian tents. They've all got, you know, good rates of throughput for the food, but they've they've got huge, huge lines for the drinks. And I come in here and you're serving this delicious punch, which is, you know, it's it's fantastic, but there's there's no cue. So what's the story? And the so the Australian manager turns to turns to the guy and looks him straight in the eye and says, why would there be a punchline?