Re: authenticate a user without databse

2016-06-07 Thread Daniel Wilcox
Two options:

1. Tie into Django Authentication

You can make a custom authentication backend and do whatever you want for
authentication -- including talk over a named pipe and get the OK for users
if you like.

With that you'll be able to use the login_required decorator.  To make a
authentication backend you will also need some kind of User object to pass
to the built-in login and logout functions -- which take care of marking
the session appropriately.

Of course that bring up a couple other things like storing your session
data -- I presume it is happening currently a cached session then?  Or is
there a solution for getting sessions data elsewhere?  Anyway typically
only the session-id is stored in the cookie and the value is a pickled
dictionary if you need to dig into that.

2. c++ is handling users, and auth... and maybe sessions

It sounds like this may be your situation.  In which case the appropriate
thing to do is to decorate your view functions to check if the requesting
session is logged in, and either redirect to login or call the view
function decorated.  You could use memcache or something like that to store
login creds somewhere django can read them directly -- otherwise you'll
probably be calling out to your named pipe on every request to one of these
views.

>From what I'm reading you'd want something like this -- where you fill in a
function to call out to your named pipe in 'named_pipe_auth_ok'.

def my_required_login(view_func):
def return_func(*args, **kwargs):
assert args[0]
request = args[0]
session_id = request.session.session_id
if named_pipe_auth_ok(session_id):
return view_func(*args, **kwargs)
else:
return redirect('/some/login/url')
return return_func

Sounds like fun, cheers,

Daniel

On Mon, Jun 6, 2016 at 10:55 PM, prabhat jha 
wrote:

> hey bro thanx,but i am not using django authentication pattern.
> so @login required will not work in my condition.
>
>>
>> --
> 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/ab5a26dc-16a8-4638-9350-8f8ad26bf83d%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGq7Khri22_2F7X%2B_R6ZTvwFHnKpSroN6784UeKhZXijWc%3DKQQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: inventory in Django

2016-04-08 Thread Daniel Wilcox
>
> Sorry if this question seems basic, but I'm having trouble figuring out
> the best way to approach this on a high level.
>
> I'm at the beginning stages of building an ecommerce site,. Inventory
> changes regularly, and photos and descriptions need to be easy to update
> for my client. Is this an ajax problem or can this be done in views?  What
> are some elegant ways to approach this? I know this is a very common
> problem, which is great - direction would be helpful.
>
> Thank you.
>
> Becka
>
>
Hello, I don't know if there is an elegant way to approach this exactly...
but here are some thoughts.  I typically move from more pages to fewer as I
get messaging and more javascript working.  I recommend a similar approach
so you have something working the whole time (tests help) and can get a
feel for what is missing; maybe even bounce it off the client to see what
they think.

The other thing is that is you know what you're client is using it for --
just imagine using the product for the required processes and what is
needed at each step (read page) and draw the page on a piece of paper.
That'll help fill in your requirements.  Like, theoretically, "does the
loading dock staff need to update quantities?"  OK what would that look
like; 1) login, 2) create shipment 'object', 3) update product A through F
while shipment X is selected.  Stuff like that.


First get your models worked out -- figure out all the fields you'll need
for a product (this may be a client question).  You can put photos 'in' (I
use this term loosely, it stores a file path) the product listing model
itself to help associate the two.  Versatileimage does a great job -- and
down the road you can make the site fully responsive quite easily as it
supports resizing on the fly (and caches the result).

You have to think of how the data needs be stored to support the kind of
queries you want.  Like for inventory can a quantity of a product be a
discrete number?  It depends on the kind of product you're building -- for
a store, probably unless it is huge, but for a warehouse, probably not.  In
this case the decision is creating a 'Shipment' object or something of that
sort with relations to products or just having an IntegerField on a product
called 'quantity'.

Create some M->1 relations, or many to many if you need many categories per
product, between products and categories, production and shipments or some
other organizing principle.  You can always start with model views and then
theme them up.

Creating a store that can be updated is about the same.  You'll basically
do similar things to the admin console; for a product you'll have a form
input per field and use the most natural one you can -- the admin console
does a great job at this so you can look there for guidance on specific
form field types (date pickers, file upload, multi-select inputs, etc).

Ajax is kinda an old way to refer to the strategy but yes you can add that
at any point.  It might be helpful to define the pages that you want first
and you can always make views that return XML, or JSON, later.  Unless of
course you have a big ball of javascript already starting out in which case
serializers are your friend but not always.

In any case once you start serializing I find it helps define some ToDict()
methods on your models, or a top level abstract model for your app.  The
method should do what it sounds like -- clean up the object for
serialization (replace foreign keys with 'id' attributes, cast things to
string as necessary, the serializer will complain you'll know).


A little ramble-y but hope that helps, cheers,

=D

-- 
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/CAGq7KhqNUzMBSHXpO7h%2B436GyW2r6PY_xPAb3tVfLK2k-_z6LQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


django-extensions: dumpscript/runscript manytomany with through= broken?

2016-04-02 Thread Daniel Wilcox
Hello, I was wondering if anyone knows a good way to handle restoring a
backup taken with a m2m intermediary model.

I'm trying to upgrade from my sqlite database to a real database and would
like to keep the data that was created thus far.

Basically the models look like this:

class Message(models.Model):
subject = models.CharField(max_length=64)
...
recipients = models.ManyToManyField(User, through='SentRecord',
blank=True)

class SentRecord(models.Model):
message = models.ForeignKey(Message)
recipient = models.ForeignKey(User)
sent_at = models.DateTimeField(auto_now=True)

So I've tried both dumpdata/loaddata and dumpscript/runscript.  The former
basically quietly ignores the records but everything else is OK -- but no
Messages or SentRecords.

So I've tried two approaches -- first problem was regarding the fact that
SentRecord and Message refer to one another and so one has to be created
first. dumpscript picked SentRecord to do first -- totally sensible.  But
It can't comply with the above model because the .message foreign key will
create a column that enforces NOT NULL.

OK fine, I changed the above model to allow null on message, since it
basically does this sequence:

1. create sent messages, with no message pk
2. create messages
3. then it *should* fill in the sent messages .message pk... but instead it
blows up because because it generates stuff like this:

app_message_1.recipient.add( importer.locate_object(User, 'id', 1, ...

Which is a big no no because of the through record it's using wrong
manager.  It should be getting the sent records already created and setting
the .message pk on those instead of trying to add Users directly to the
message, as though it were a regular m2m.


I'm just wondering if anyone knows if this is a fixed issue and I'm just
'holding it wrong'... otherwise I'll be faced with some stark choices, fix
django-extensions to get my way... or do some ugly sed/awk to patch it up.

Thank you!

=D

-- 
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/CAGq7KhoAkw57YzmEZReouD7Fr9f0fX7mG-bhdGgSRu3Oc07xiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Gmail Django

2016-02-19 Thread Daniel Wilcox
You should generate a certificate to use TLS (even something self signed,
or try Let's Encrypt and get a free cert from there).  Other than that we
have the same settings and I've been sending mail successfully with almost
identical settings the past day or so.

I presume you are using an app-specific password.  Another difference I see
is that I removed the default from setting since it doesn't match the host
user (and I don't expect that google would deliver it).

Best of luck!

On Fri, Feb 19, 2016 at 12:17 PM,  wrote:

> my settings
>
> EMAIL_USE_TLS = True
> DEFAULT_FROM_EMAIL = 'webmaster@vaility'
> EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
> EMAIL_FILE_PATH = None
> EMAIL_HOST = 'smtp.gmail.com'
> EMAIL_HOST_PASSWORD = 'lv210493'
> EMAIL_HOST_USER = 'setivolkyl...@gmail.com'
> EMAIL_PORT = 587
> EMAIL_SUBJECT_PREFIX = '[Django] '
> EMAIL_TIMEOUT = None
> EMAIL_USE_TLS = True
> SERVER_EMAIL = 'root@vaility'  # email for errors
>
> Every time I had next error
>
> SMTPAuthenticationError: (534, b'5.7.14 <
> https://accounts.google.com/ContinueSignIn?sarp=1=1=AKgnsbsy1\n5.7.14
> Hm68kFAtFDZroMBYjdIl_EN2We7HAeUt2puFzfziG5SUr_1ZyN9UgsCfV_M_RKiMRBEYw9\n5.7.14
> F4k9yCuW8gTxTgcL5lV4ofXgDXumhhKkh7yc-BvkyqL1NBPZv_WXNPD7qQQUhUO8-KikpH\n5.7.14
> ct0vd7ZvgpfIF48HMJKlSiICSCHsmwaqU9Atwc5dx4RlcMJ7Bcn63ePgmwruSeBHh4rKOB\n5.7.14
> nGaIDTGZyrou7ao5k4lm5t6wxosA> Please log in via your web browser
> and\n5.7.14 then try again.\n5.7.14  Learn more at\n5.7.14
> https://support.google.com/mail/answer/78754 eb3sm1684842lbc.31 - gsmtp')
>
> I again sigin in my account, but not result
>
>
> --
> 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/d2feb1b0-56c0-41ee-9a61-75acf91f5b90%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGq7KhqUEhjqqnM5cNj1mCbTGXjLj5exJHNakwVnQdjAgaXrug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.