Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Maluco Marinero posted:

You could try using manage.py dumpdata. That dumps all your data into JSON files that can then run into manage.py loaddata.

That way you avoid having to worry about conversion from MySQL to Postgres, however be aware constraints are not relaxed while you use loaddata, so it's important to segment your loaddata json payloads sometimes so you don't get integrity errors on foreign keys. As long as you have a nice environment to run some tests you can just smash away at it til you find a sequence that works.

https://docs.djangoproject.com/en/1.10/ref/django-admin/#dumpdata

Note that you can be very specific dumping single models and apps and things.

Glad I asked, that looks like exactly what I was looking for :)

Thanks Maluco!

e: quoted since we're on a new page

Adbot
ADBOT LOVES YOU

Mo_Steel
Mar 7, 2008

Let's Clock Into The Sunset Together

Fun Shoe
I'm fairly new to Django and playing around with it so this might be the most idiotic implementation, but I've got a models field question. I'm looking to enumerate through a list of files on the server to be displayed as shortcuts on a template page dynamically with some of their file information (for example, log files); here's what I have for models.py:

code:
class Text_Item(models.Model):
    name = models.CharField(max_length=200)
    path = models.FilePathField()
However, I'm not able to add anything in the admin panel for that model for the path:



I've tried manually specifying a path for the field in the model as well e.g. (path='/logs/'), but the field in the admin pane stays blank, can't be typed into and nothing happens when the dropdown is clicked; I can't add an item because the field is required. Should I just be using a normal CharField instead of FilePathField? The info I've found on it from searching online and looking at the fields documentation makes it sound like FilePathField is what I would want for that property, but maybe I'm missing a setup step?

Otherwise finding Django to be pretty slick; I've been working through the CodeSchool courses on it and Python recently and am really enjoying how much it simplifies things.

Mo_Steel fucked around with this message at 06:40 on Nov 6, 2016

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
Two things, the path must be absolute according to the docs, not relative to the working directory, secondly, I'd check your permissions, as Django may just silently fail to get anything if it doesn't actually have permission to read the path.

Reading more, I've never used but the path is a necessary argument. You're not allowed to do your own thing with it, it needs a path to work from, and in the admin it only allows you to choose what it finds. I imagine this is so it can simplify accessing the file referenced.

Mo_Steel
Mar 7, 2008

Let's Clock Into The Sunset Together

Fun Shoe

Maluco Marinero posted:

Two things, the path must be absolute according to the docs, not relative to the working directory, secondly, I'd check your permissions, as Django may just silently fail to get anything if it doesn't actually have permission to read the path.

Reading more, I've never used but the path is a necessary argument. You're not allowed to do your own thing with it, it needs a path to work from, and in the admin it only allows you to choose what it finds. I imagine this is so it can simplify accessing the file referenced.

Yeah, now that I see it in action I understand a bit more:



I was able to get that by pointing the path at settings.BASE_DIR; I think my confusion was I read the documentation as a relative path. I'm on Windows 10, and you can't drop in "C:\files" because the backslashes prevent makemigrations from completing. I also tried "file:///C:/files" which allows migration but doesn't show anything in the field. I assume I'd probably have to do something like how BASE_DIR is defined: os.path.dirname(os.path.dirname(os.path.abspath("C:\files"))) maybe.

Anyway, it looks like this would be more useful if I was looking to let users upload files and specify a directory to put them in from a set of folders as it doesn't show the full path; I'll keep tinkering around and see if CharField isn't more what I'm looking for by just populating it with the name of the folder containing each existing file. Thanks for the help!

Mo_Steel fucked around with this message at 16:15 on Nov 6, 2016

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Has anyone else found that over their Django career they migrated back to function-based views from class-based views?

I used to use CBV's quite extensively, but I've found that I just really value the explicit nature of FBV's and that they seem to better mesh with the "explicit is better than implicit" Python mantra.

It's not that I really find CBV's to be all that bad, I've just slowly grown into this mindset where I find them unnecessary.

Ahz
Jun 17, 2001
PUT MY CART BACK? I'M BETTER THAN THAT AND YOU! WHERE IS MY BUTLER?!

Thermopyle posted:

Has anyone else found that over their Django career they migrated back to function-based views from class-based views?

I used to use CBV's quite extensively, but I've found that I just really value the explicit nature of FBV's and that they seem to better mesh with the "explicit is better than implicit" Python mantra.

It's not that I really find CBV's to be all that bad, I've just slowly grown into this mindset where I find them unnecessary.

I think the best-case for CBVs are a fairly slim set of scenarios (massive derivative CRUDs) and add unnecessary complexity to an app. I don't think I've ever set up a series of views and then later ever considered refactoring them into CBVs for any benefit whatsoever. But I have created some CBVs or worked with CBVs where later I thought to myself, "WTF is this? what plugs into this?" and spent some effort refactoring into FBVs.

porksmash
Sep 30, 2008
Not that I have much of a Django career since it's a hobby for me, but I hate CBVs. Having so much hidden functionality makes it extremely hard to know what's happening and why, or what specific function you need to overload to get it to work how you want. After all that it feels like fighting it more than working with it.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

porksmash posted:

Not that I have much of a Django career since it's a hobby for me, but I hate CBVs. Having so much hidden functionality makes it extremely hard to know what's happening and why, or what specific function you need to overload to get it to work how you want. After all that it feels like fighting it more than working with it.

I agree with all of this, but just in case you don't know about it, this site helps to a degree: https://ccbv.co.uk/

Data Graham
Dec 28, 2009

📈📊🍪😋



Thermopyle posted:

Has anyone else found that over their Django career they migrated back to function-based views from class-based views?

I used to use CBV's quite extensively, but I've found that I just really value the explicit nature of FBV's and that they seem to better mesh with the "explicit is better than implicit" Python mantra.

It's not that I really find CBV's to be all that bad, I've just slowly grown into this mindset where I find them unnecessary.

drat I'm glad you said this.

I always feel like I'm doing something dirty by wiring up views one-to-one with URLs and building explicit dicts for my return objects, but six months later if I have to tinker with something it makes it a billion times easier. And what if your app does more than basic CRUD, where oh I dunno you have like three or four different kinds of mutate actions that operate on an object (or several different objects that aren't all that separable) instead of just one obvious "update"? CBVs seem like a case of designing around the happy path and then trimming out all the flexibility to do non-happy-path things.

I don't think anyone's first exposure to DRF serializers and ViewsSets should be when they have to reverse-engineer someone else's beautiful perfect CRUD API to jimmy in a new piece of functionality that doesn't fit quite so neatly into that pattern, meaning they have to rip the whole thing apart to expose all the nuts and bolts they need.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Is there a more graceful way to handle enumerated values than what I am doing now? I am finding it very tedious to work with them with the Django REST Framework. I started out with Python 2.7, but I have been able to since move up to Python 3.5, so I have Enums now officially. I wonder if Django has some built-ins to exploit.

The model has stuff like this:
code:
MY_PROTO_SHIT_ENUM = (
    ('y', "Yes I know it's awful"),
    ('b', "But I couldn't find"),
    ('a', "a better Python 2.7 solution"),
    ('s', "since I didn't see anything using 2.7 Enum"),
)

class ThisGuyHasAnEnumInIt(models.Model):
    ...
    whatsup = models.CharField(max_length=1, choices=MY_PROTO_SHIT_ENUM, verbose_name="Come on I can do this better, right?")
    ...
The DRF serialization has to do some custom crap to decode it like:
code:
# Serializers define the API representation.
class ThisGuySerializes(serializers.HyperlinkedModelSerializer):

    whatsup = serializers.SerializerMethodField()

    class Meta:
        model = ThisGuyHasAnEnumInIt
        fields = ('whatsup')

    def get_whatsup(self, obj):
        for tuple in MY_PROTO_SHIT_ENUM:
            if obj.test_class == tuple[0]:
                return tuple[1]
        return "Unknown"

That does manage it, but it seems really bulky, and I have to do this a lot. I could write something to help, but I can't help but imagine something already about out there. This doesn't even get into setting the values.


...It has occurred to me while vomiting this out that maybe what I want is ChoiceField in my model. Yes?

Edit: Oh hey, should I be looking at django-enumfield and drf-enumfield instead?

Rocko Bonaparte fucked around with this message at 00:34 on Nov 9, 2016

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Thermopyle posted:

Has anyone else found that over their Django career they migrated back to function-based views from class-based views?

I used to use CBV's quite extensively, but I've found that I just really value the explicit nature of FBV's and that they seem to better mesh with the "explicit is better than implicit" Python mantra.

It's not that I really find CBV's to be all that bad, I've just slowly grown into this mindset where I find them unnecessary.

Absolutely, I much prefer function and composition/decorators to class based views after a brief fling with them early on.

MonkeyMaker
May 22, 2006

What's your poison, sir?

Thermopyle posted:

Has anyone else found that over their Django career they migrated back to function-based views from class-based views?

I used to use CBV's quite extensively, but I've found that I just really value the explicit nature of FBV's and that they seem to better mesh with the "explicit is better than implicit" Python mantra.

It's not that I really find CBV's to be all that bad, I've just slowly grown into this mindset where I find them unnecessary.

I still use CBVs whenever I build things with Django but that has become very rare since I started teaching full time. Honestly, though, I don't really care one way or the other. Views are views.

Dr. Dos
Aug 5, 2005

YAAAAAAAY!
I used the excuse of having to change hosting providers to start porting all my sites to use Python 3 instead of 2 and get them all running on the latest version of Django and so far everything has gone very smoothly with one exception.

I can't for the life of me find an openid library that supports Python 3 and is up to date enough to not call a bunch of deprecated/removed django functions. Does anybody know of one that's up to date (for a consumer only, specifically logging in to a site via Steam)

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Dr. Dos posted:

I used the excuse of having to change hosting providers to start porting all my sites to use Python 3 instead of 2 and get them all running on the latest version of Django and so far everything has gone very smoothly with one exception.

I can't for the life of me find an openid library that supports Python 3 and is up to date enough to not call a bunch of deprecated/removed django functions. Does anybody know of one that's up to date (for a consumer only, specifically logging in to a site via Steam)

I use python-social-auth with Python 3 and the latest version of Django & Django Rest Framework. It "just works" and I have never had to fiddle with it.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Where do you guys put your signals code and how do you make sure it gets imported?

I want to stick mine in a separate signals.py file and came across this solution but wasn't sure if that's the right way to go

MonkeyMaker
May 22, 2006

What's your poison, sir?

fletcher posted:

Where do you guys put your signals code and how do you make sure it gets imported?

I want to stick mine in a separate signals.py file and came across this solution but wasn't sure if that's the right way to go

That's the official solution, AFAIK. One of my students was trying to use that for their own project, though, and having some problems, so proceed with caution?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

fletcher posted:

Where do you guys put your signals code and how do you make sure it gets imported?

I want to stick mine in a separate signals.py file and came across this solution but wasn't sure if that's the right way to go

Yeah, this is the way to go.

Make sure you follow all the steps! I often forget to put the default_app_config part in app/__init__.py

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Thermopyle posted:

Yeah, this is the way to go.

Make sure you follow all the steps! I often forget to put the default_app_config part in app/__init__.py

Apparently they tell you to avoid setting default_app_config now, and instead just list it in INSTALLED_APPLICATIONS: https://docs.djangoproject.com/en/1.9/ref/applications/#configuring-applications

It seems to all be working now...just seems a little hacky :)

And my signals are definitely being registered multiple times now (as warned in the docs), fortunately they are idempotent though.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I'm trying to figure out how to handle some stuff with the Django REST Framework. I have a master record format in one model that is made up of other objects in other models. I would like to create a new one of these, but I want to override how this is done. In particular, I want the creation API to take specific terms for looking up the other objects that make up the record, rather than the user having to vomit all that raw information in their request. Here's what I understand I have to do:

1. Override create() in my serializer for this master record object that I first created when I got it working in the REST framework.
2. Do my massaging to get the actual objects based on the custom inputs.
3. Have that massaged data then get pumped into MyMasterRecord.objects.create_method_i_wrote(properties=this,other_properties=that...)
4. Add a models.Manager subclass that describes create_method_i_wrote. I don't see how this connects anywhere. I just kind of declared the class and the method and just assume elf magic hooks it up.

I figured that in my create() method that I could take the validated JSON and do all the lookups. This appears to be false. Heck, my unit test doesn't even run any of the above code. It's puking out because it's claiming that two of my fields are missing. They are definitely there, but their models are objects themselves with compound data, rather than the simple strings I'm passing in. I figure I'd be able to retrieve those strings, derive a lookup based on them, and transform them into the actual objects I want. So do I have to do something like write my own validator for the create requests?

Is there a better way to get this stuff? Can I add stuff to all these other Models that let me recall them based on some criteria other than their primary key?

Ahz
Jun 17, 2001
PUT MY CART BACK? I'M BETTER THAN THAT AND YOU! WHERE IS MY BUTLER?!

Rocko Bonaparte posted:

I'm trying to figure out how to handle some stuff with the Django REST Framework. I have a master record format in one model that is made up of other objects in other models. I would like to create a new one of these, but I want to override how this is done. In particular, I want the creation API to take specific terms for looking up the other objects that make up the record, rather than the user having to vomit all that raw information in their request. Here's what I understand I have to do:

1. Override create() in my serializer for this master record object that I first created when I got it working in the REST framework.
2. Do my massaging to get the actual objects based on the custom inputs.
3. Have that massaged data then get pumped into MyMasterRecord.objects.create_method_i_wrote(properties=this,other_properties=that...)
4. Add a models.Manager subclass that describes create_method_i_wrote. I don't see how this connects anywhere. I just kind of declared the class and the method and just assume elf magic hooks it up.

I figured that in my create() method that I could take the validated JSON and do all the lookups. This appears to be false. Heck, my unit test doesn't even run any of the above code. It's puking out because it's claiming that two of my fields are missing. They are definitely there, but their models are objects themselves with compound data, rather than the simple strings I'm passing in. I figure I'd be able to retrieve those strings, derive a lookup based on them, and transform them into the actual objects I want. So do I have to do something like write my own validator for the create requests?

Is there a better way to get this stuff? Can I add stuff to all these other Models that let me recall them based on some criteria other than their primary key?

The time you spend figuring out how to override and dig into the 'magic' inside the framework, you could just do everything manually with plain old Django models then serialize/deserialize the set separately. I mean you could rig the framework to do what you want, spend some time, pat yourself on the back for a clever solution with some complex inheritance/mixin thing, but the things you learn are pretty specific to how one guy made this one framework and not transferrable skills.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Here's something I do that I always feel "iffy" about....

For simplicity sake say I've got a todo app site. Users come along and register their own accounts.

My TodoList and ToDo models have a `user` FK field to the Django User model.

In my views and forms I need to check request.user against object.user and make sure not only that the user owns the object at the current url, but also that I'm filtering the queryset for various related fields on the forms on that page so that when the user selected a related object in those form fields they're only able to select objects that they own.

On the model side I need to make sure that only objects with the same user can be saved as related.

This all requires a little bit of code in a lot of places. I can simplify it via the use of custom mixins or decorators, but I've still got to remember to use them. I try to use tests to make sure these constraints are met.

What other ways of approaching this problem do you like to use? Is there a way to force a constraint on user must equal user at the DB level for these related objects?

porksmash
Sep 30, 2008
You can use a per-object permissions package like django-guardian

Ahz
Jun 17, 2001
PUT MY CART BACK? I'M BETTER THAN THAT AND YOU! WHERE IS MY BUTLER?!

Thermopyle posted:

Here's something I do that I always feel "iffy" about....

For simplicity sake say I've got a todo app site. Users come along and register their own accounts.

My TodoList and ToDo models have a `user` FK field to the Django User model.

In my views and forms I need to check request.user against object.user and make sure not only that the user owns the object at the current url, but also that I'm filtering the queryset for various related fields on the forms on that page so that when the user selected a related object in those form fields they're only able to select objects that they own.

On the model side I need to make sure that only objects with the same user can be saved as related.

This all requires a little bit of code in a lot of places. I can simplify it via the use of custom mixins or decorators, but I've still got to remember to use them. I try to use tests to make sure these constraints are met.

What other ways of approaching this problem do you like to use? Is there a way to force a constraint on user must equal user at the DB level for these related objects?

Depends on your model design. It's pretty simple if you keep things normalized and then manage single reusable abstracted entry points for querying/saving/updating. Other alternatives includes overriding the save methods and ensuring there any save call is done by a related /owning user.

epswing
Nov 4, 2003

Soiled Meat
I'm having some trouble with inline formsets. I have a parent-child (one-to-many) relationship. I want a single page where I can edit the properties of an parent, while also adding/editing/deleting the children.

Displaying a parent along with it's children works fine. However when I save, I get the error

quote:

ManagementForm data is missing or has been tampered with

Edit: The problem was my template was missing the 'header' part of the formset:

HTML code:
<input id="id_ticket_set-TOTAL_FORMS" name="ticket_set-TOTAL_FORMS" type="hidden" value="6"/>
<input id="id_ticket_set-INITIAL_FORMS" name="ticket_set-INITIAL_FORMS" type="hidden" value="3"/>
<input id="id_ticket_set-MIN_NUM_FORMS" name="ticket_set-MIN_NUM_FORMS" type="hidden" value="0"/>
<input id="id_ticket_set-MAX_NUM_FORMS" name="ticket_set-MAX_NUM_FORMS" type="hidden" value="1000"/>
I needed to call {{ formset.management_form }} in the template.

https://docs.djangoproject.com/en/1.10/topics/forms/formsets/#understanding-the-managementform

epswing fucked around with this message at 19:13 on Nov 29, 2016

epswing
Nov 4, 2003

Soiled Meat
What the best way these days for a Django app to generate PDF files?

The docs point to ReportLab, but after a couple days I'm finding it hard to work with, and I find the ReportLab documentation pretty awful.

There's the django-wkhtmltopdf wrapper around wkhtmltopdf, but requiring a 40mb dependency doesn't make me feel warm and fuzzy the way a django app should.

There's django-easy-pdf but github readme says it depends on xhtml2pdf and reportlab.

I'm not seeing any obviously good options. Any suggestions? What do you use?

epswing fucked around with this message at 19:15 on Nov 29, 2016

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I was having a great time with my project until I started dealing with user accounts. The code size has doubled overall, although a lot of that is on the front end. I am trying to figure out the mechanics behind it on the back end. Say, I am particularly trying to get Angular to handle logging into my REST API c/o the Django REST Framework. In particular, I see a few examples like this:


https://richardtier.com/2014/03/15/authenticate-using-django-rest-framework-endpoint-and-angularjs/amp/

Ignoring the JavaScript for a bit--although I am having my fair share of trouble interpreting what tha is doing--what is that APIView trying to do? This and another site just casually declare a UserSerializer, which is only a thing in the Django REST Framework tutorials. Maybe I keep missing mention of that in these articles. I have my own that tacks on some data, sure, but it is working on full User Models. I guess I look the User up and serialize that instead?

In particular, how would I unit test such a thing? If I use APIClient and post to the login URL with my authentication data, will that preserve my credentials for the next post afterwards?

This is where me being new to web stuff really gets me into trouble.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

My favorite way to do user stuff when building a REST API with a JavaScript front-end is JWT. There's even a nice Django package for doing it. Google Django JWT.

porksmash
Sep 30, 2008
EDIT: Ignore everything. Apparently soft reloading wsgi instead of fully restarting caused some sort of issue.

I've run into some issues with the logging configuration on my server. I wanted to make sure I understand how to see what exactly Django thinks the logging config is.

According to the docs, there's a default logging configuration that gets merged with a LOGGING dict specified in your settings, and this is what is used while Django is running. I am fine with the default logging setup, so I have not specified anything in my settings.py. There is no LOGGING = xxx or LOGGING_CONFIG = xxxx in my settings at all.

I'm not really sure how to find what exactly the final configuration for logging Django is using, though. It's apparently not using the supposed defaults. I know my email settings are correct because I receive emails sent with send_mail() or mail_admins(). I'm basically at a loss here because I can't tell what's going on internally.

porksmash fucked around with this message at 21:44 on Dec 14, 2016

WINNINGHARD
Oct 4, 2014

Rocko Bonaparte posted:


In particular, how would I unit test such a thing? If I use APIClient and post to the login URL with my authentication data, will that preserve my credentials for the next post afterwards?


Are you asking about how to unit test controllers that require some level of authentication/authorization? In my unit tests I use force_authenticate when I'm not testing the login controller itself.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

WINNINGHARD posted:

Are you asking about how to unit test controllers that require some level of authentication/authorization? In my unit tests I use force_authenticate when I'm not testing the login controller itself.

In this case, I would want to actually test that the mechanics of authentication worked. It looks like I got it. I have a test that will 403 on a POST after logging off.

galenanorth
May 19, 2016

If you set null=True and default=0 on the same field, is the null=True setting ignored? I had written some of my optional fields with "blank=True, null=True, default=0", so I was going back through them and changing them.

Gounads
Mar 13, 2013

Where am I?
How did I get here?

galenanorth posted:

If you set null=True and default=0 on the same field, is the null=True setting ignored? I had written some of my optional fields with "blank=True, null=True, default=0", so I was going back through them and changing them.

Not ignored, it would let you set the field to null, either explicitly during creation or on a later update.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Anyone used more than one of the various django social auth packages and have anything to say about which they like the most?

epswing
Nov 4, 2003

Soiled Meat

Thermopyle posted:

Anyone used more than one of the various django social auth packages and have anything to say about which they like the most?

I'm interested in this as well, as I'll soon be integrating with Facebook login. There seem to be several deprecated packages out there, some more popular than others.

Data Graham
Dec 28, 2009

📈📊🍪😋



Got a rather interesting problem here.

I got this model, see. I want the id to be a BigAutoField, and I want it to be a randomly generated integer, not sequential. Purpose being that I don't want it to be easily guessable or predictable. And because I'm going to be using a Base## method to shorten it for URL exposure, I don't want the ID to be a long or alphanumeric thing like a UUID.

So I'm doing this:

code:
id = models.BigAutoField(primary_key=True, default=generate_pk)

def generate_pk():
    return random.randrange(2147483647) # just to keep it to 32 bit for now
And this is fine for generating the random key I need. However, what do I do when I inevitably get collisions? I figure I would like to override the save() method on the model, and trap IntegrityError and regenerate the ID in that case (perhaps in a while loop until it finds an empty slot); but I'm having trouble seeing how or where to do that.

If I do something like:

code:
    def save(self, *args, **kwargs):
        try:
            super(MyModel, self).save(*args, **kwargs)
        except:
            self.pk = generate_pk()
            super(MyModel, self).save(*args, **kwargs)
—Then it gives me a TransactionManagementError: "An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.", coming from deep in the db backend.

I feel like I'm barking up the wrong tree here. Any ideas on what I ought to be doing?



Edit: looks like this might get me past it; leaving it here in case it helps anybody:

http://stackoverflow.com/questions/21458387/transactionmanagementerror-you-cant-execute-queries-until-the-end-of-the-atom

Data Graham fucked around with this message at 06:31 on Jan 2, 2017

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Thermopyle posted:

Anyone used more than one of the various django social auth packages and have anything to say about which they like the most?
I used django-allauth recently on a project and recommend it as the best social auth plugin. It supports almost any social auth provider you can think of, and you can configure it via the Django admin panel.

The worst part of it is the sheer number of templates it uses. If you need to add translations or customize the overall layout or the like then you're looking at copy-pasting and modifying almost two dozen HTML files.

Aside from that I'd still recommend it as it was the most comprehensive and, outside of editing so many templates, I was able to get social auth integrated in with minimal fuss to my backend code.

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane

IAmKale posted:

I used django-allauth recently on a project and recommend it as the best social auth plugin. It supports almost any social auth provider you can think of, and you can configure it via the Django admin panel.

The worst part of it is the sheer number of templates it uses. If you need to add translations or customize the overall layout or the like then you're looking at copy-pasting and modifying almost two dozen HTML files.

Aside from that I'd still recommend it as it was the most comprehensive and, outside of editing so many templates, I was able to get social auth integrated in with minimal fuss to my backend code.

I agree with this post (the good and the bad...)

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I just came across intercooler.js, which Django users might be interested in.

Sometimes you want to do AJAX-y stuff but it can be a lot of trouble to wire up django-rest-framework. This thing uses attributes on elements to hit your server and replaces those elements with the HTML it gets back.

So, you can just do something like this in one of your templates:

code:
 <a ic-post-to="/mouse_entered" ic-trigger-on="mouseenter">Mouse Over Me!</a>
And the library will POST to /mouse_entered on your server and the contents with whatever it gets back.

So...dynamic, AJAX-y pages with just regular templates.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Thermopyle posted:

I just came across intercooler.js, which Django users might be interested in.

This is pretty cool, thanks for sharing! Kinda reminds me of JSF :D

Adbot
ADBOT LOVES YOU

Dominoes
Sep 20, 2007

Hey dudes: How do I access files (like a pdf or w/e) from code in a django app on Heroku? I've been pulling my hair out regarding this!!


-Works locally
-When I clone, the file's there, so it is getting pushed to Heroku
-Static files like Javascript and css work fine; dj-static configured.


I've tried dumping the file I need the code to access everywhere; main proj and app static, staticfiles directories, the main proj directory, the main app directory. Nothing, and no leads on troubleshooting since it's only reproducible when deployed. You should see my commit log! I get a standard FileNotFound Error.

Based on my weak understanding of serving static files, this is one one in the trad sense; it's accessed by the code, not the user.


edit: Got it working, after dropping the file in about ~10 locations simultaneously; no idea which one was correct!

Dominoes fucked around with this message at 11:50 on Feb 6, 2017

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply