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
Hed
Mar 31, 2004

Fun Shoe
Anyone have experience playing with Django and Google Apps? I'm in the design stages of an application for a domain that has business hosted Gmail. I'd love it if there's a way to authenticate users with Google Accounts but Google's single sign on documentation isn't exactly clear on this subject unless I'm explicitly using Google App Engine or something that appears to support Django 0.97.

Adbot
ADBOT LOVES YOU

Hed
Mar 31, 2004

Fun Shoe
I was never able to get the live streams working from the office. Any idea on how soon until the sessions are posted on Blip? It seems like it has taken a few weeks in the past.

Hed
Mar 31, 2004

Fun Shoe
Do you guys have any rules of thumb between where you separate your view and template logic? I am building what should be a straightforward app for time reporting and display and I feel really confident about my models. For the views, I can get it to work but it feels clunky. For example, for a given reporting period (month) I'm pulling back all of the records and for unique charge codes in a week I'm building a table (list of lists), and displaying it out. Sounds straightforward enough, but getting things into stuff that's "easy" for the template to spit out (tabular data in lists) is a real pain to do additional things with later, such as refer to attributes that I could have in the code with a simple dictionary. For example, when I want to add row-wise hourly totals or label the charge codes with descriptions from my models, the template language has to be blown up and what I write feels really odd, which usually means I'm doing it wrong.

In fact, I'm pretty sure I'm doing a poor job of it because I have considered just making weeks packaged responses in JSON and coding up javascript to control how to view the data.

Hed
Mar 31, 2004

Fun Shoe
You need to install python flup. Once you can import that, set up lighttpd to talk fastcgi on a specific port (not your external web port), then run manage.py in fastcgi mode to talk to the same port. I think the Django docs on this should get you there.

Hed
Mar 31, 2004

Fun Shoe
I'm working on a project for fun and I have a model in particular:
Python code:
class ChargeEntry(models.Model):
    """Time Charge Entry"""
    charge_code = models.ForeignKey(ChargeCode)
    hours = models.DecimalField(max_digits=3,decimal_places=1)
    charge_date = models.DateField(help_text="""Date of Charge""")
    user = models.ForeignKey(User)

    datetime_added = models.DateTimeField(auto_now_add=True)
    datetime_updated = models.DateTimeField(auto_now=True)

    objects = ChargeEntryManager()
I am finding myself repeating a pattern of:
  • go get ChargeEntry model in the period specified (usually a month)
  • bin the set into weeks
  • for each week show me the unique charge codes used
  • amalgamate this into a large view of the month with weekly grids (say, tables with each row as a charge code and the days of the week as the columns)

For viewing I have a view function that does a lot of the heavy lifting like steps 2-3 and packages this stuff into a custom data type that I have a custom templatetag pick up and parse.

Now I find myself thinking about the editing part, where I'd like to have all of this be a form where you can edit the values for a month. I could do a formset of formsets thing for the month-week-codes, but this sounds like an awful lot of repeating myself.

Should I load up the ChargeEntryManager with some custom functions to return packages of data in the format I need? I'm really having trouble wrapping my head around a container for all of these objects that I will eventually be slicing different ways... while not repeating myself and not making redundant queries to the db.

Hed
Mar 31, 2004

Fun Shoe
A few months ago some big Python/Django person wrote a blog post about integrating AngularJS into their Django apps. Does anyone know what I'm talking about and have a link? I'm at a loss.

Hed
Mar 31, 2004

Fun Shoe
Today I started getting a few "Invalid HTTP_HOST header:" that point back to my Amazon AWS external IP. Should I be concerned about this? Django is running through WSGI to nginx on a local tcp socket.

From quick googling it looks like something not to worry about (just spoofers) but wanted to make sure and kind of understand what's going on here. Are people just forging headers with a from address of my public IP?

Hed fucked around with this message at 01:16 on Jun 21, 2014

Hed
Mar 31, 2004

Fun Shoe
I've done it on a few projects and one that my company depends on every day. You definitely aren't alone.

Hed
Mar 31, 2004

Fun Shoe
I may be misunderstanding your question but is this what you want?

code:

Airfield.objects.exclude(surface='').filter(runway__length__gte=8000)

Hed
Mar 31, 2004

Fun Shoe
Can you paste your whole server block? There could be other matchings going on.
Can you set only the static location block on and put autoindex on and browse the directory?

Nginx normally runs as nobody but the files need to be readable by a set user (default www-data) in order for the web server to see them. I didn't think an error there was a 404 though.

Hed
Mar 31, 2004

Fun Shoe
I think one of the problems we're having with answering that question is it generally doesn't make sense to filter things in the serializer. Another way of thinking about that is that your UserProfile serializer should know how to serialize/deserialize UserProfile objects well, and nothing else.

So in that sense your UserProfileSerializer looks fine if a little verbose. To restrict your GET to whatever, then the most straightforward way is to filter your view in the manner fletcher suggested:

Python code:
# views.py
class NonStaffUserProfileList(generics.ListAPIView):
    serializer_class = UserProfileSerializer

    def get_queryset(self):
        return UserProfile.objects.filter(is_staff=False)

Hed
Mar 31, 2004

Fun Shoe
I had a problem a few weeks ago where I had an app either without templates or something with higher in the app order list and it seemed like the framework just stopped checking after that. I didn't mess with it enough to debug that issue because I had already wasted enough time on it. Anyway, you might try shuffling your app order and seeing if the problem returns.

Hed
Mar 31, 2004

Fun Shoe
I'm going to wait for 3.1 after messing around with it a bit yesterday for some of the nested/related field goodness to work a bit more to my liking.

supermikhail posted:

But I'm not sure what exactly it wants from me. And whether I can do anything. If I understand it correctly, it receives a unicode string which it needs to convert to ascii, but there is no such character in ascii?

Can you paste your view code or whatever actually generates the error? It looks like the error you're having is caused by a string encoded in UTF-8 being decoded through ASCII.

Hed
Mar 31, 2004

Fun Shoe

ufarn posted:

The people at work use Drupal for e-commerce client solutions, but as I hate Drupal, I was wondering what the best Django module - that isn't straight-up Shopify - would be?

There has to be a better way than goddamn Drupal ...

I really like Mezzanine/cartridge

Hed
Mar 31, 2004

Fun Shoe
What packages do you guys use for instance-level security? I'm thinking of something like where I can set security bits on an object and have a QuerySet only return rows that a user can see, as well as ensure DetailViews don't work for forbidden objects.

Hed
Mar 31, 2004

Fun Shoe
Cheers!

Hed
Mar 31, 2004

Fun Shoe

xpander posted:

The system I'm working on subclasses django-extensions' TimeStampedModel. I'm making some minor additions to a template that is using this model, including putting the "modified" field on the page for the user to see. However, it never seems to have a value when used in the template - it's always blank. I've been able to print the value to the console, but that field doesn't seem to be inside the context object. Does Django not automatically pass fields from abstract base classes to context objects or something? Using {{ model.other_field }} works fine for anything listed on the model, but {{ model.modified }} does not. I can't quite seem to figure out the disconnect here.

Are you able to print it to the debug console from the view (e.g. context['model'] from a generic view's context) or just in the Django shell? What you're talking about should work just fine in the template. The only other thing I can think of is if you had somehow coerced your model into something that responds to key lookups with an empty string or None.

Hed
Mar 31, 2004

Fun Shoe
I have a project where I'm ingesting a large amount of data, and for this project it makes sense to map each dataset into its own database.

In order to automate the "awareness" of a new database a bit better, I was going to move the DATABASES setting in the production settings.py out to JSON, then when I label a new dataset, fill in the db alias, write out the json, then kick the supervisord to restart the WSGI processes. How bad of an idea is this?

Hed
Mar 31, 2004

Fun Shoe

2nd Rate Poster posted:

great suggestions for databases

:cheers: thanks! I'm picking this back up at work this week so I think I'll put in your suggestion. Making it at worst one db lookup (to figure out the DB routing) per request is actually a great bargain, and not having to kick over a production server and cross your fingers that it comes back up is even better.

Hed
Mar 31, 2004

Fun Shoe
Use django-debug-toolbar with something approximating real data on your dev/test server

Hed
Mar 31, 2004

Fun Shoe

Thermopyle posted:

I haven't done much Django except a little maintenance since 1.6 was the newest version. Getting ready to dive into some new projects and was just wondering if anyone has been keeping up with the 2 Scoops of Django books and if they do a good job of covering the best practices that have changed since 1.6? I've always liked the books but it's been a couple years since I picked up a copy...

Also if anyone has anything to say about changes since 1.6, I'll listen.

Y'know I got the 1.8 book because why not but I really haven't referred to it all that much. I think the stuff I've used is mainly their thoughts on caching frameworks and the new Postgres-specific features. There is some good stuff on deploying to SaaS/IaaS places but I think you have that down.

Hed
Mar 31, 2004

Fun Shoe
It's hard to tell if you've gone too far without knowing the reason for your optimizing. Really major sites that use Django, you can bet everything in settings has earned its place there. If it's just a fun obsession, then that's fine. But it's the equivalent of those people who remove Aero or whatever theme Windows ships with because "that stuff is slowing my computer down :argh:"

Hed
Mar 31, 2004

Fun Shoe
Some of the defaults for middleware handle sessions, the redirection to have slashes at the end (which is always a style question when running DRF), and some caching stuff that the client can pay attention to. I do think CSRF protection won't work without the middleware there injecting into the response and processing the requests. I'd be interested if all of that works as expected still. Still, it's kind of fun to see what can work.

Hed
Mar 31, 2004

Fun Shoe
For example db creds, API keys. If you had a storefront you might have a development and testing settings.py with test PayPal/Stripe keys and a db with no creds, but in production you will obviously have your real API keys and database creds. It's a lot easier to set in the environment or other state, and as mentioned keeps it out of source control.

Hed
Mar 31, 2004

Fun Shoe
Is there an app that will plug in advanced search? I basically want this:
  • if someone puts "asdf" in the search field, do an icontains for asdf across several model fields and OR them (can do this pretty easily with Q objects in the query set)
  • if someone puts something like "remark:asdf" in the search field, just do an icontains in the model's remarks field

It would be straightforward enough to code in a mixin or whatever, but I'm surprised I haven't found anything searching so far.

Hed
Mar 31, 2004

Fun Shoe
Yes I have bought every edition and like he says it's great reference for the corners of the framework you don't use every day.

Hed
Mar 31, 2004

Fun Shoe
Maybe less a Django question but I'm usually interested in implementing it in a Django context.

Is there a list of strategies for keeping change history in fields? I've had a couple toy projects where it would be useful to have snapshots in time, or history when portions were edited. I've played around with having archive flags and creating new objects to link together, but they all have drawbacks.

If this is a more general SQL thing I'd be interested in reading up, but haven't hit upon the correct phrase / terms yet.

Hed
Mar 31, 2004

Fun Shoe
It works super well, it just sucks at scaling.

Hed
Mar 31, 2004

Fun Shoe

Thermopyle posted:

Yes, it's dope and that poo poo is the future.

RabbitMQ/Celery is not a problem, you just have to have it running on a persistent server somewhere.

This looks neat but I'm having trouble figuring out where the persistent store of data is in a stateless thing like this. Do you bring up Amazon RDS and then all your lambda workers query that? Do you have to start optimizing for instantiation time now that overhead of spinning up your request (e.g. loading modules) is non-negligible?

Hed
Mar 31, 2004

Fun Shoe
I think you need to use one of the components underneath the wrapper to use it that way. I remember the docs being tricky with that. I can look tomorrow, but also try doing a dir() on that wrapper object to see what your options are.

Hed
Mar 31, 2004

Fun Shoe
Should be able to set this: https://docs.djangoproject.com/en/2.0/ref/settings/#append-slash

Hed
Mar 31, 2004

Fun Shoe
Django would work and is great, but if you don’t need a DB with modeled objects (the ORM) it would probably be easier to just use bottle or flask IF you don’t already have experience with Django.

To the second part I really think web sites are easier to design and dork around with than any GUI toolkit these days.

Hed
Mar 31, 2004

Fun Shoe

NtotheTC posted:

Is there a go-to e-commerce library for django that you guys use? Theres any number of them on django packages and django-oscar appears to be winning but popularity does not always trump experience

I really enjoyed cartridge when I was building those. I thought it was easy to implement, customize, and extend. Haven’t used it since 2015 but might be worth a look.

Hed
Mar 31, 2004

Fun Shoe
Has anyone been deploying on AWS lambda? Seems cool but I’m a little unclear if best practice is still to mess with Cookiecutter templates then install Zappa or just go with the default

Hed
Mar 31, 2004

Fun Shoe
What are people's opinions on using UUIDs everywhere as the primary key?

I'm starting a new Django project and while the framework has made it easy for a long time, I've seen mixed ideas on the Internet: that using UUIDs is both terrible and fine. For now I'm giving models that are going to be on my REST interface (which is most of them) an additional field that is based on the ShortUUID from Django extensions. Still, carting both around and dorking around with Django-REST-Framework to use both PKs and UUIDs seems a little silly.

Hed
Mar 31, 2004

Fun Shoe
Since pytest was brought up in the other thread, I wanted to see what I was missing here.

I get that just writing assert statements is more elegant than self.assertBlah() all over, but it looks like if I do Django tests that require DB access, I have to put decorators everywhere, and it doesn’t look nice to me. Am I missing something?

Nothing to do with pytest but looking at my testing more rigorously did give me the excuse to grok factoryboy and faker, though, so that has cleaned up my tests significantly. They are much easier to reason about now.

Hed
Mar 31, 2004

Fun Shoe
I had it installed but was following the OG pytest docs. Now I'm off to the races, 100% natural testing with 20% less boilerplate. Thanks!

Hed
Mar 31, 2004

Fun Shoe
I was going to build an app on to a project where users can design arbitrary questionnaires / polls. Since a dynamic schema can be a little tricky, has anyone used Entity-attribute-value package like django-eav2? I'm considering using that to store the data to tie back to a Django object.

Alternatively I could just use JSON(B) fields. Given that I want to run calculations and eventually report on these I'm trying to see if anyone has anything that worked well for them in the past.

Hed
Mar 31, 2004

Fun Shoe
Thanks guys, after thinking a bit more about it you’re both right. I was getting hung up on how people could dynamically assign questions to questionnaires and went looking for complicated solutions instead of back to fundamentals.

Adbot
ADBOT LOVES YOU

Hed
Mar 31, 2004

Fun Shoe
What's a good basic blog app to use on a project in 2020? I see from django-packages mezzanine is still around but feels kind of heavyweight. I really just need basic formatting with image insertion, posts, tags, and permalinks.

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