So I’m trying to do a site with user editable tags on items. I want users to be able to edit tags on the page only if they are logged in, but everyone should be able to view the page. The edits are done through a modelform. I can’t use the login_required decorator on the whole view because then on…
Tag: python
PyCharm noinspection for whole file?
Is it possible to disable an inspection for the whole file in PyCharm? The reason this is needed is when dealing with py.test. It uses fixtures which appear to shadow function parameters, and at the same time cause unresolved references. e.g.: There is also other warnings from py.test, such as using pytest.ra…
Best way of linking to a page in Django
I managed to create a URL tag for my index. But right now I’m confused how to add links to other pages. I put this on my urls.py The next thing I put this tag into the href: But what if I wanted to create a new page and would be linking to it. How would I do it the
Calculate Time Difference Between Two Pandas Columns in Hours and Minutes
I have two columns, fromdate and todate, in a dataframe. I add a new column, diff, to find the difference between the two dates using I get the diff column, but it contains days, when there’s more than 24 hours. How do I convert my results to only hours and minutes (i.e. days are converted to hours)? An…
py.test Tracebacks: Highlight my code, fold frames of framework
Tracebacks of my tests are too long since I use pytest. Pytests includes surrounding code lines and a lot of other information. I like to see this information if the traceback line (frame) is from my code. But I don’t want to see it, if it is from a library or framework. I could not find a way to filter
How do you set up Pycharm to debug a Fabric fabfile on Windows?
Is is possible to set up Pycharm to step through a a Fabric fabfile.py? It seems like this would be doable with the run/debug configuration editor but I can’t seem to get the settings just right. The editor is asking for a script to run and I’ve tried the fab-script.py file it is just giving me th…
How do I slice a numpy array to get both the first and last two rows
As far as I can see it, it isn’t covered in the indexing, slicing and iterating scipy tutorial, so let me ask it here: Say I’ve How do I slice the array in order get both the first and last rows: Answer I don’t know if there’s a slick way to do that. You could list the indices explicit…
How to unpack a Series of tuples in Pandas?
Sometimes I end up with a series of tuples/lists when using Pandas. This is common when, for example, doing a group-by and passing a function that has multiple return values: What is the correct way to “unpack” this structure so that I get a DataFrame with two columns? A related question is how I …
How to have clusters of stacked bars
So here is how my data set looks like : I want to have stacked bar plot for each dataframe but since they have same index, I’d like to have 2 stacked bars per index. I’ve tried to plot both on the same axes : But it overlaps. Then I tried to concat the two dataset first : but here
python random mouse movements
I would like to make random mouse movements in specified rectangle area (limited with coordinates x1, y1, x2, y2, x3, y3, x4, y4). Movements should be smooth, random, not just straight lines, go randomly up/down/left/right/etc for specified time duration. Could you give me a hand or working example I can lear…