accessing multiple dbs?

2009-07-15 Thread Richard E. Cooke

The answer is not jumping out at me, so I'm going to post it here in
case its a simple answer.

I want to access an existing DB on a remote server using Postgres.  My
boss is not crazy about having Django "polluting" this existing -
large - db with its internal guts.

But I don't see how to specify a SECOND db connection in Django.
There is only one Settings.py file.

Can I instantiate a second connector?  And will doing so allow me to
take advantage of the admin interface?

Or, if I make my own connection, and use Django's db models (assuming
I can even do that without conflict) will I still be able to
"comfortably" program the Django way?

Or maybe if I make a second connection, it has to be all by hand -
using my own classes.  No tie-in to Django's niceties.

Or is this a "deal breaker"?  Where Django really only works if all
"application" data is in the same db as all "site" data?


Thanks in Advance!
Richard Cooke
Turnkey Automation Inc.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: accessing multiple dbs?

2009-07-15 Thread Richard E. Cooke

OK.  Before I get flamed!

I neglected to search THIS group before I posted.


So, I see some chatter about being able to instansiate a second DB
connector.  Great.

Now, how about where the best examples of that are?

And what impact, if any, does this have on the rest of Django?

My boss is starting to weaken too:  "Maybe its not so bad having
Django tables added"



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: accessing multiple dbs?

2009-07-17 Thread Richard E. Cooke

Thanks for the replies!

Happily I have managed to avoid the issue.  We will just make one
Django site per database.  Using a web page to post all the different
sites, thus making it "look" like its accessing multiple dbs..

Cheap shot I know, but I'm very lazy.

Plus I figure by the time I really get forced to deal with this issue,
GSOC will have helped out enough it won't be "hard" or tricky
anymore

By the way,when I was evaluating different packages to choose I was
torn between Django and TurboGears2.  It was the fact Django has GSOC
working on the multi-DB issue that made me choose it.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Can I change the restriction on "username" without breaking anything?

2009-11-11 Thread Richard E. Cooke

My client wants to use e-mail addresses for user names.


the contrib.auth application does not have a restriction in its
model.  But the form code has put a regex on the field that disallows
the ampersand (@).

What would be the easiest way to override that form field definition
so its global?

And is there something someplace that will break if user names are e-
mail addresses?


Thanks in advance.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can I change the restriction on "username" without breaking anything?

2009-11-12 Thread Richard E. Cooke
Thanks.  Sorry.  I have got to stop posting when I'm tired...

For punishment, I read the Wikipedia article on the "@" character:
http://en.wikipedia.org/wiki/@

No, I did not do a google search because I ass-umed the truly relevant
info would be in this list.  really.

The first Google hit is a Django snippet, and while the solution might
not be global like I want it does point out a potential problem.  In
that there already is an e-mail field and having duplicate data in the
two fields could break some applications.

Which makes me wonder if the "right" way is to use a custom user
validation system, likely with the e-mail field dropped, or maybe just
aliased to the username so things that expect e-mail address find one.


--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




Re: Can I change the restriction on "username" without breaking anything?

2009-11-13 Thread Richard E. Cooke
Thanks David!  I was wondering about doing the same thing!  I had not
thought of your idea of soft-switching the login name from username to
email.  Interesting idea.  I was toying with making my own class +
auth backenend so I could change the DB layout to drop email.  But I
could see that having issues in places that expect an email field

I'm going to setup a spike of your idea this morning and see how it
goes.

One wrinkle I can see is the contrib.auth.forms has a regex filter on
username that prevents the "@" symbol.  Although I have to go see if
the Admin system over-rides that anyway - I think it does.


If anybody else has a clever idea, I'm listening!

Thanks again all!


--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




Re: Can I change the restriction on "username" without breaking anything?

2009-11-13 Thread Richard E. Cooke
I get nervous when all the examples and code snippets I find are
several year old.

This code snippet: http://www.djangosnippets.org/snippets/74/

works in principal, but relies on a regular expression test that is no
longer defined n Django.

I changed it to use a regex I use in server-side mail handlers to
verify proper RFC formatted FROM lines (part of anti spam system).
And its works perfect in testing so far.  Will have to expand testing
to my custom code (I've only done the admin site so far).

I just hope I'm not missing some recent boolean flag added recently I
just need to set to True...

The code I added is:
import re

# vem = Verify E-Mail.  This regular expression is from
http://www.regular-expressions.info/email.html
# and is designed to detect anything that meets the RFC-2822 standard.
vem = re.compile(r"""(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*
+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-
\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-
z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|
[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-
z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\
[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])""", re.I)

and change this line to use "vem":
if vem.search(username):

I'm trying to load the revised code as a comment on the snippet page,
but I had to apply for an account, and they have not sent me my
confirmation e-mail


Rich.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




Does anybody have ADMIN rights to "djangosnippets.org"?

2009-11-13 Thread Richard E. Cooke
I'm trying to get an ID on this system and its stuck trying to e-mail
me an "activation" e-mail!


I'm using SPF on my server to reduce spam (very effective) but the
underlying server they are using is not configured properly.  The
error message is:


Nov 13 17:53:45 mail4.local.scom.ca postfix/smtpd[17044]: NOQUEUE:
reject: RCPT from unknown[69.30.202.190]: 450 4.7.1 : Client host rejected: Message deferred due to: SPF
Temporary Error: DNS Timeout. Please see
http://www.openspf.org/Why?s=helo;id=gypsyhosting.com;ip=69.30.202.190;r=richard.co...@turnkeyautomation.net;
from=
to= proto=ESMTP
helo=

Its a timeout trying to get SPF info from their server.  Its been
doing it for 6 hours, so I don't think its going to work without a
little outside help...


Thanks in Advance!

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




Setting up private temperature sensor system?

2023-01-26 Thread Richard E. Cooke
Where I want to see my temperature sensor data does not have an internet 
connection.

So I need to set up my own system using LHT65N sensors and LPS8N gateway(s).

Reading some older user manuals, I noticed at one time they included The 
Things Network stack in firmware!  Thats cool!  Is that a package I can add 
back to my current LPS8N gateway?

Also, if I have a sensor too far from my LPS8N, how can I extend my range?  
I'm out in the middle of nowhere, nothing and nobody around.

I saw a photo of a "mesh" Lora network.  But it did not say which device 
models?

Thanks in Advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/234ff9ab-f7b9-4b6e-8fde-e13e5f7f15e9n%40googlegroups.com.


I need help doing a linked lookup in admin

2013-04-26 Thread Richard E. Cooke
I used the *django-contacts *project as my starting point for a company 
contact database.  Its really cool, it keeps "addresses", "phone numbers", 
etc in seperate db table so you can associate as many as you need to each 
company or person record.  It uses *django.contrib.contenttype*s for its 
relations.  Which is also pretty cool since that lets you attach comments 
to any other record!

Anyway, I want to build on this by adding an Inventory and Purchasing 
system.

In my Inventory model I have a field for supplier:

  supplier = models.ForeignKey('contacts.Company', blank=True, null=True)

Which works perfect, you get a pop-up list to pick the lucky vendor from.  
Later I might add a filter to limit the choices to a particular type of 
company - like vendors.  But this is fine for now.

A company record can (and will) have multiple "StreetAddresses" records 
associated with it through a GenericRelation.  For the PO I want to be able 
to select one out of that set of addresses.

So for a test, I tried:

  ship_to = models.ForeignKey('contacts.StreetAddress', 
limit_choices_to={'content_type':27, 'object_id':1, 'location':'shipto'}, 
blank=True, null=True)

"content_type", "object_id" are the content types fields used to control 
the Generic Relation.  And those values correspond to pk=1 for records of 
type "company".  And the "location" field indicates the type of address 
record.

This works.  I get a list of "ship to" addresses for the company (pk=1).

So, now I want to re-jig this to use the current PO record's setting for 
"supplier" to automatically limit the address selection.

There might be a way to capitalize on the fact that *supplier.street_address
*  is a *GenericRelatedObjectManager* seeded with the right values.  

In shell, I read in a PO record with *a = PO.objects.get(pk=1)*
Then I enter *a.supplier.street_address.filter(location="shipto")* I get a 
list of all the "shipto" addresses for the supplier!  Exactly the list I 
want to be able to pick one from.

But I haven't a clue how to make use of this in the Admin system.  Any 
ideas appreciated!

I tried making a ForeignKey field to the StreetAddress db, and filter it 
using values from the supplier record currently in memory:
  ship_to = models.ForeignKey('contacts.StreetAddress', 
limit_choices_to={'content_type':F('po__supplier__street_address__content_type__id'),
 
'object_id':F('po__supplier__pk'),}, blank=True, null=True)

In Admin, this returns an empty list of addresses.  

To debug, I went into shell, and tried:
b = 
StreetAddress.objects.filter(content_type=F('po__supplier__street_address__content_type__id'))
  

>>> b
[]

does "F()" write a log someplace that will tell me where this falls apart?  
Well, I don't see how it would know what PO record to get "supplier" from.  
Or maybe its better to say I don't understand how it determines where to 
get any of its data from when your walking relations.The Django manual 
entry for 1.4 is pretty vague on details. 

Or, is there a better way to do this?

Thanks in Advance!



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: I need help doing a linked lookup in admin

2013-04-29 Thread Richard E. Cooke
I'm getting closer!  

First I found this note in the Content Types docs that explains why what I 
was doing does NOT work:
https://docs.djangoproject.com/en/1.4/ref/contrib/contenttypes/#django.contrib.contenttypes.generic.GenericForeignKey

*Due to the way 
GenericForeignKeyis
 implemented, you cannot use such fields directly with filters (
filter() and exclude(), for example) via the database API.*


Then I found this sample code in the admin docs:
https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey


That I adapted to this for my admin form:
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "ship_to":
kwargs["queryset"] = 
StreetAddress.objects.filter(po__supplier__street_address__location="shipto")
return super(POAdmin, self).formfield_for_foreignkey(db_field, 
request, **kwargs)

Note that while this is my "PO" data model, I used the model belonging to 
the address data "StreetAddress".  This is because which model does the 
object.filter() is the one whose __unicode__ function is called to get a 
representation of each record found for the list selection dialogue.  Which 
means, for my PO database, it describes each address by its PO number 
(which are the same number) making it hard to tell the addresses apart!  By 
using the StreetAddress model, it uses its __unicode__ instead, which makes 
a mini-summary of each address.  Much clearer.


This is not a perfect solution though because when I try to SAVE an edited 
PO record I get an error:

MultipleObjectsReturned: get() returned more than one StreetAddress -- it 
returned 2! Lookup parameters were {'id': u'2'}


I'm going to go back to letting it list all "ship to" addresses for all 
companies until I figure out what this error even means!

Another problem is its listing both address choices with the same 
description.  Another mystery to ponder.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Multi Client Django System

2013-05-22 Thread Richard E. Cooke
Frank!

You appear to have figured out what I spent most of today trying to figure 
out:  How to get access to the current logged in user from INSIDE a custom 
data manager!

Can you clarify something in your code?

In your custom manager you define "by_user", which takes "user" as an 
input.  But in your class you just name your custom data manager in place 
of the default "object" manager.

How do you ( a ) get the system to call your "by user" query?  And ( b ) 
how do you get the system to send in the current "user"?

I was thinking there might be a link through the site.model reference 
Managers get.  Or maybe a way to pull it from session, but I keep get stuck 
on the fact this isn't a view, so it has no obvious access to a "request" 
object

Thanks in advance!



On Monday, February 25, 2013 4:18:50 AM UTC-5, Frank Bieniek wrote:
>
> We achived the second level auth, by tying an extended group to a company, 
> all company members are part of this group, so we can leverage the 
> normal auth mechanismen. 
>
> Hope this gives you an idea. 
>
> Thanks 
> Frank 
>
> class CompanyManager(models.Manager): 
>  filter_by_user_limit_field = None 
>
>  def by_user(self, user): 
>  """ 
>  Extension for filtering organization objects (also related 
> objects) by 
>  the groups of a user. 
>  Avoiding that a user can touch other organization objects. 
> Superusers and 
>  Partner Administrators are able to see all organizations. 
>  """ 
>  # if the user is not logged in - no data 
>  if not user.is_authenticated(): 
>  return self.none() 
>  # TODO: optimization: would be nice to find a way to make 
> by_user chainable like .filter(), ... 
>  return self.limit_queryset_by_user( 
>  self.get_query_set(), 
>  user, 
>  self.model.filter_by_user_limit_field 
>  ) 
>
>  @staticmethod 
>  def limit_queryset_by_user(qs, user, field_key): 
>  if user.is_superuser.count()>0: 
>  return qs 
>  kwargs = {} 
>  if field_key and user.groups.count() > 0: 
>  kwargs[field_key] = [u['id'] for u in 
> user.groups.values('id')] 
>  return qs.filter(**kwargs) 
>
> And in the model 
>
> class Company(ExtendedModel): 
>  name = models.CharField(max_length=64, unique=True) 
>  slug = models.SlugField(unique=True) 
>  is_active = models.BooleanField(null=False, blank=False, 
> default=True) 
>
>  filter_by_user_limit_field = "organizationgroup__in" 
>  objects = CompanyManager() 
>
> class CompanyGroup(Group): 
>  """ 
>  User group of the Organization 
>  """ 
>  organization = models.OneToOneField(Organization) 
>
>
> Am 23.02.2013 17:00, schrieb Gabriel - Iulian Dumbrava: 
> > How I would do it would be to have a special column (foreign key) in 
> each table (model) called Company (company_id) and change all default 
> managers to filter on company_id = logged_in_user.company_id. 
> > 
> > In this way you are sure tha users only see what belongs to their 
> company. 
> > 
> > You would have to pass the company_id to models, probably with a 
> middleware which gets it from the logged in user and saves it somewhere. 
> > 
> > And you also have to save the default value of company_id to each newly 
> created entry in every table, probably from the same source as above. 
> > 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




How to access request/session information from model.clean?

2013-06-21 Thread Richard E. Cooke
 I'm trying to pass the request object, which includes the session object, 
to a chunk of Django 1.5 code that is tied to the model (model.clean). When 
running the Admin app, it does not have access to the request object.

So I tried stashing it in RAM using thread.local(), only to get a crash 
course in how "shared" RAM is between active sessions!

I have several choices I'm trying to figure out the one with the least 
amount of work. I would not be working in Automation if I weren't lazy.

My goal is to auto-fill the company division the current session belongs 
to. This allows us to use the same business software for multiple 
divisions. Django 1.4 and 1.5 Admin has a lovely built-in easy method to 
filter records before they are displayed (ModelAdmin.queryset), the example 
given in the docs shows how to limit records to the user that "owns" them. 
I just changed that to "company division" (the list is stored in Site 
database), and presto! All data displayed anyplace inside the admin is 
restricted and the operation is totally transparent to the user. 

What I need to do now is have an automatic method to populate each record's 
"site" field with the "site" value inside the current session.  Note that 
this is different from how the "site" framework and "SITE_ID" field are 
used.

   1. I can copy the admin view and make changes to it. Since it is passed 
   the request, I can access the session object to get the seed value. This 
   would be the "best practice" when I (eventually) get approval to replace 
   the admin with our own task-based system. But I suspect its a lot of work 
   to try it inside of the admin framework, It might have a domino effect 
   resulting in the editing of a lot more related files. The html templates, 
   for example.
   2. Which brings me to copying just the templates and changing them, 
   since I think they are sent the session data as part of the request object. 
   I have not learned how to work with templates, so I cannot judge how much 
   effort this represents.
   3. Find some other mechanism within the admin framework. Find a place 
   where I have access to both the data instance and the session data. Or a 
   way I can pass one or the other to some code where I can make use of it.

Its the 3rd possibility I'm trolling for here. Since I don't have time to 
do choice #1 - at least the full custom version. And I dunno about #2.

There is another Django 1.4/1.5 feature I might be able to use: 
ModelAdmin.get_form. This is called to "get" the add, change or delete 
form. And it is passed the request object. I just have to learn if it also 
has access to the data instance. Or maybe I can pass "default" values as a 
keyword argument? I have a vague memory reading something about that. Have 
to dig back into the Admin docs and/or read the source code

As always, any input, thoughts, or suggestions welcome!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to access request/session information from model.clean?

2013-06-23 Thread Richard E. Cooke
Thanks Jason!

I hunted through your links, and while I was setting up a test I stumbled 
upon this in the Django 1.5 Admin docs:

 - 
https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model

and this:

 - 
https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_formset

Changing my "ThreadLocal" middle ware to store the "company site" in the 
session information, I am testing this:

def save_model(self, request, obj, form, change):
if change:
if obj.site.id != request.session['site'].id:
logger.debug("Contacts.Company.save_model: replacing site 
(%s) with (%s) " % (repr(obj.site), repr(request.session['site'])) )
else:
logger.debug("Contacts.Company.save_model: setting site (%s)" % 
(repr(request.session['site'])) )
obj.site = request.session['site']
obj.user = request.user

def save_formset(self, request, form, formset, change):
  instances = formset.save(commit=False)
  for instance in instances:
if change:
if instance.site.id != request.session['site'].id:
logger.debug("Contacts.Company.save_model: replacing site 
(%s) with (%s) " % (repr(instance.site), repr(request.session['site'])) )
else:
logger.debug("Contacts.Company.save_model: setting site (%s)" % 
(repr(request.session['site'])) )
instance.site = request.session['site']
instance.user = request.user
instance.save()
  formset.save_m2m()


This is added to your admin.py as part of your ModelAdmin class.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




How do I change a global setting from inside middleware?

2013-06-23 Thread Richard E. Cooke
I'm using Grappelli to spruce up my Admin interface.

I would like to customize the site name (and web page tittle).

I have this in my project settings.py file:

# http://django-grappelli.readthedocs.org/en/latest/customization.html
GRAPPELLI_ADMIN_TITLE = "The Default Company"


And in my middle ware I try to change it to match the company name of the 
connecting user:
(This code snipped is abbreviated, don't try and copy and paste it into a 
file and run it!)

from django.conf import settings
def process_request(self, request):
settings.GRAPPELLI_ADMIN_TITLE = request.user.myuser.site.name

But it seems to be a crap shoot if the title gets changed to the right 
value, or changed at all!

More shared memory consequences?

I could not find a "best practice" for this.  So, I suspect there is a 
"better way" I'm hoping somebody can enlighten me.

Thanks in advance,
Rich.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How do I change a global setting from inside middleware?

2013-06-23 Thread Richard E. Cooke
Thanks Mr. Spaolonzi!

I guess its time to read some template docs.  I'll post back what I come up 
with so others can use it.


Rich.


On Sunday, June 23, 2013 3:20:24 PM UTC-4, Serge G. Spaolonzi wrote:
>
> Django settings cant be changed on the fly. 
> From the official documentation:
> > You shouldn’t alter settings in your applications at runtime. For 
> example, don’t do this in a view:
>
> I think the solution for your problem is to set or update 
>  'grappelli_admin_title'  context variable from the middleware or from a 
> custom context processor.
>
> Looking at Grappellis code it seems this is the relevant code for your 
> problem:
> grappelli/templates/admin/base.html
> {% if grappelli_admin_title %}{{ 
> grappelli_admin_title }}{% else %}{% get_admin_title %}{% endif %}
>
>
> Using context processors is the best practice for this kind of problems. 
> For example:
>
> def admin_title(request):
> """
> Adds media-related context variables to the context.
> """
> user_company_name = request.user.company_name
> return {'grappelli_admin_title': user_company_name, }
>
>
> Regards
>
>
>
> On Sun, Jun 23, 2013 at 3:47 PM, Richard E. Cooke 
> 
> > wrote:
>
>> I'm using Grappelli to spruce up my Admin interface.
>>
>> I would like to customize the site name (and web page tittle).
>>
>> I have this in my project settings.py file:
>>
>> # http://django-grappelli.readthedocs.org/en/latest/customization.html
>> GRAPPELLI_ADMIN_TITLE = "The Default Company"
>>
>>
>> And in my middle ware I try to change it to match the company name of the 
>> connecting user:
>> (This code snipped is abbreviated, don't try and copy and paste it into a 
>> file and run it!)
>>
>> from django.conf import settings
>> def process_request(self, request):
>> settings.GRAPPELLI_ADMIN_TITLE = request.user.myuser.site.name
>>
>> But it seems to be a crap shoot if the title gets changed to the right 
>> value, or changed at all!
>>
>> More shared memory consequences?
>>
>> I could not find a "best practice" for this.  So, I suspect there is a 
>> "better way" I'm hoping somebody can enlighten me.
>>
>> Thanks in advance,
>> Rich.
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Serge G. Spaolonzi
> Cobalys Systems
> http://www.cobalys.com
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




How do I find out how many AdminSites exist?

2013-08-07 Thread Richard E. Cooke
I want to use Grappelli and Django-extensions with my Admin site.  But I 
also need to use modelAdmin.queryset to restrict my records.

Both Grappelli and Django-extensions Auto Complete Lookups use the model's 
base queryset.

I want to put in a request to change the code, which is easy - so long as I 
can determine WHICH admin site the data model is registered with.

I just thought of another wrinklye - it could be registered with multiple 
sites.

Here are links to my other discussions on this topic.

All suggestions truly appreciated!

Thanks in advance,
Rich.

Django-extensions (soon to be extinct pull request):
 - https://github.com/django-extensions/django-extensions/pull/354

Grappelli discussion on this topic:
 - https://github.com/sehmaschine/django-grappelli/issues/362



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django 1.5.1 and clearsessions

2013-08-07 Thread Richard E. Cooke
Works fine for me.  Must be a path issue.



On Wednesday, August 7, 2013 9:41:37 AM UTC-4, Derrick Jackson wrote:
>
> Hmm...
>
> When I attempt to run django-admin.py clearsessions while using django 
> 1.5.1 I am told that clearsessions is an unknown command.  Has anyone 
> successfully used clearsessions as of yet?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




System check Framework error checking Admin Fieldsets in 2.1

2018-08-31 Thread Richard E. Cooke
This Field set definition:

fieldsets = (
('Job Work Sheet', {
'fields': (
('number', 'job_history', 'hw_customer',),
('status', 'contracted_out',),
('adn_parts_required', 'atn_required', 'atn_tech', 
'cancel_job',),
('date_quoted', 'po_number', 'tag',),
('date_in', 'priority',),
('hw_description', 'hw_make', 'hw_model', 'hw_serial', 
),
('technician', 'bin', ),
('assessment_time', 'hours_worked',),
('parts_cost', 'parts_shipping',),
('problem',),
)
}),
('Hardware Details', {
'classes': ('grp-collapse grp-closed',),
'fields': (('hw_customer', 'hardware', ), ('hw_description', 
'hw_make', 'hw_model', 'hw_serial',), ('hw_comments',),)
}),
('Repair Details', {
'fields': (('work_done',), ('comments',),)
}),
)

Gets no errors with Django 2.0.6, but with 2.1 I get:

(dj21py37) $ ./manage.py check
SystemCheckError: System check identified some issues:

ERRORS:
: (admin.E012) There are duplicate field(s) 
in 'fieldsets[1][1]'.
: (admin.E012) There are duplicate field(s) 
in 'fieldsets[2][1]'.

System check identified 2 issues (0 silenced).



I presume its complaining about the field 'hw_customer', but since it is in 
readonly_fields this should not be an error, correct?

Rich.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5c78dd4e-d86a-4367-8c09-de2c34773f69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


System check Framework error checking Admin Fieldsets in 2.1

2018-09-04 Thread Richard E. Cooke
This Field set definition:


fieldsets = (
('Job Work Sheet', {
'fields': (
('number', 'job_history', 'hw_customer',),
('status', 'contracted_out',),
('adn_parts_required', 'atn_required', 'atn_tech', 
'cancel_job',),
('date_quoted', 'po_number', 'tag',),
('date_in', 'priority',),
('hw_description', 'hw_make', 'hw_model', 'hw_serial', 
),
('technician', 'bin', ),
('assessment_time', 'hours_worked',),
('parts_cost', 'parts_shipping',),
('problem',),
)
}),
('Hardware Details', {
'classes': ('grp-collapse grp-closed',),
'fields': (('hw_customer', 'hardware', ), ('hw_description', 
'hw_make', 'hw_model', 'hw_serial',), ('hw_comments',),)
}),
('Repair Details', {
'fields': (('work_done',), ('comments',),)
}),
)


Gets no errors with Django 2.0.6, but with 2.1 I get:


(dj21py37) $ ./manage.py check
SystemCheckError: System check identified some issues:

ERRORS:
: (admin.E012) There are duplicate field(s) 
in 'fieldsets[1][1]'.
: (admin.E012) There are duplicate field(s) 
in 'fieldsets[2][1]'.

System check identified 2 issues (0 silenced).



I presume its complaining about the field 'hw_customer', but since it is in 
readonly_fields this should not be an error.  Nothing in the docs about not 
being able to have a read only field display twice.

Has a bug been introduced to the latest checker?

Rich.





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5f97f1d5-0da6-4900-9332-364a3bca9e5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.