Add id to url after login user

2016-04-29 Thread Dariusz Mysior
I use FormView do login user, but I don't know how I should add his ID 
number to success url that when he will log in adres will be 
users/profile/id

urls.py

from users.views import RegisterView, LoginView, ProfileView

urlpatterns = [

url(r'^register/$', RegisterView.as_view(), name='register-view'),
url(r'^login/$', LoginView.as_view(), name='login-view'),
url(r'^profile/(?P\d+)/$', ProfileView.as_view(), 
name='profile-view'),



views.py

class LoginView(FormView):
template_name = 'login_form.html'
model = MysiteUser
form_class = AuthenticationForm
success_url = '/users/profile/'

-- 
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/215be504-9c65-4525-a523-d1d0f7f8c0d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add id to url after login user

2016-04-29 Thread Michal Petrucha
On Fri, Apr 29, 2016 at 12:36:30AM -0700, Dariusz Mysior wrote:
> I use FormView do login user, but I don't know how I should add his ID 
> number to success url that when he will log in adres will be 
> users/profile/id
> 
> urls.py
> 
> from users.views import RegisterView, LoginView, ProfileView
> 
> urlpatterns = [
> 
> url(r'^register/$', RegisterView.as_view(), name='register-view'),
> url(r'^login/$', LoginView.as_view(), name='login-view'),
> url(r'^profile/(?P\d+)/$', ProfileView.as_view(), 
> name='profile-view'),
> 
> 
> 
> views.py
> 
> class LoginView(FormView):
> template_name = 'login_form.html'
> model = MysiteUser
> form_class = AuthenticationForm
> success_url = '/users/profile/'

Have you considered using the built-in ``login`` view? [1] One of its
advantages is that it has built-in support for the ``next`` URL
argument, which makes it possible to redirect the user back to the
page they were trying to access before they were asked to log in,
instead of always redirecting them to the same fixed page after login.

Regarding the meat of your question, there are several options, but
personally, I'd set up an additional view with a URL pattern of
'^profile/$' that would just get the current logged-in user, and
return a redirect to the user's profile page.

Or even better, if you do not need users to be able to view other
users' profiles, you can just remove the user ID from your profile URL
pattern, and simply always display the current user's profile there.

Cheers,

Michal


[1] 
https://docs.djangoproject.com/en/1.9/topics/auth/default/#django.contrib.auth.views.login

-- 
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/20160429080314.GE435%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: Add id to url after login user

2016-04-29 Thread Dariusz Mysior
Hi I try learn Django, and I want do authenticated system in CBV. My nxt 
try is that I wright it like below but in url adrees instead of id number I 
have "None" :/

 success_url = '/users/profile/'+ str(MysiteUser.pk)


W dniu piątek, 29 kwietnia 2016 09:36:30 UTC+2 użytkownik Dariusz Mysior 
napisał:
>
> I use FormView do login user, but I don't know how I should add his ID 
> number to success url that when he will log in adres will be 
> users/profile/id
>
> urls.py
>
> from users.views import RegisterView, LoginView, ProfileView
>
> urlpatterns = [
>
> url(r'^register/$', RegisterView.as_view(), name='register-view'),
> url(r'^login/$', LoginView.as_view(), name='login-view'),
> url(r'^profile/(?P\d+)/$', ProfileView.as_view(), 
> name='profile-view'),
>
>
>
> views.py
>
> class LoginView(FormView):
> template_name = 'login_form.html'
> model = MysiteUser
> form_class = AuthenticationForm
> success_url = '/users/profile/'
>
>

-- 
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/023bf58a-8c66-48ec-8761-108498133db1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add id to url after login user

2016-04-29 Thread Michal Petrucha
On Fri, Apr 29, 2016 at 01:12:23AM -0700, Dariusz Mysior wrote:
> Hi I try learn Django, and I want do authenticated system in CBV. My nxt 
> try is that I wright it like below but in url adrees instead of id number I 
> have "None" :/
> 
>  success_url = '/users/profile/'+ str(MysiteUser.pk)

That won't work – the class definition of LoginView is evaluated
during import, not when processing a request, which means you cannot
use the “current user” object in the definition of a class attribute.

Is there any reason why you cannot use one of the two solutions I
described in my previous email? (Quoted below.)

On Fri, Apr 29, 2016 at 10:03:15AM +0200, Michal Petrucha wrote:
> personally, I'd set up an additional view with a URL pattern of
> '^profile/$' that would just get the current logged-in user, and
> return a redirect to the user's profile page.
> 
> Or even better, if you do not need users to be able to view other
> users' profiles, you can just remove the user ID from your profile URL
> pattern, and simply always display the current user's profile there.

Cheers,

Michal

-- 
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/20160429084354.GF435%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: Add id to url after login user

2016-04-29 Thread Dariusz Mysior
Hej ja po angielsku słabo piszę, chciałem się nauczyć Class Based View i na 
tym zrobić system rejestracji, masz pomysł jak to dalej zrobić? Chciałbym 
wyciagnąć pk i dodać do adresu succes_url...

W dniu piątek, 29 kwietnia 2016 09:36:30 UTC+2 użytkownik Dariusz Mysior 
napisał:
>
> I use FormView do login user, but I don't know how I should add his ID 
> number to success url that when he will log in adres will be 
> users/profile/id
>
> urls.py
>
> from users.views import RegisterView, LoginView, ProfileView
>
> urlpatterns = [
>
> url(r'^register/$', RegisterView.as_view(), name='register-view'),
> url(r'^login/$', LoginView.as_view(), name='login-view'),
> url(r'^profile/(?P\d+)/$', ProfileView.as_view(), 
> name='profile-view'),
>
>
>
> views.py
>
> class LoginView(FormView):
> template_name = 'login_form.html'
> model = MysiteUser
> form_class = AuthenticationForm
> success_url = '/users/profile/'
>
>

-- 
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/d87f880e-3b4e-4e96-816f-9c1e25481393%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add id to url after login user

2016-04-29 Thread Michal Petrucha
On Fri, Apr 29, 2016 at 07:18:28AM -0700, Dariusz Mysior wrote:
> Hej ja po angielsku słabo piszę, chciałem się nauczyć Class Based View i na 
> tym zrobić system rejestracji, masz pomysł jak to dalej zrobić? Chciałbym 
> wyciagnąć pk i dodać do adresu succes_url...

Heh, Michal, nie Michał. (-: O krajinu vedľa (Slovensko).

Anyway, while I can read Polish more or less OK, I'm clueless at
writing, so I'll try this in English again.

What I suggest is that you leave your view as it was, and create
another one just to redirect the user::

class LoginView(FormView):
template_name = 'login_form.html'
model = MysiteUser
form_class = AuthenticationForm
success_url = '/users/profile/'


class CurrentUserProfileView(RedirectView):
def get_redirect_url(self):
return reverse('profile-view', pk=self.request.user.pk)

And, of course, then you have to add it to urls.py::

from users.views import RegisterView, LoginView, ProfileView, 
CurrentUserProfileView

urlpatterns = [
url(r'^register/$', RegisterView.as_view(), name='register-view'),
url(r'^login/$', LoginView.as_view(), name='login-view'),
url(r'^profile/$', CurrentUserProfileView.as_view(), 
name='current-profile-view'),
url(r'^profile/(?P\d+)/$', ProfileView.as_view(), 
name='profile-view'),
]

Michal

-- 
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/20160429143730.GH435%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Is it good idea to transition from MS Access to a webapp? And if so, is Django a good tool to do it?

2016-04-29 Thread Patrik Mjartan
Hi,

I work for a very small company that I developed an application for, all 
using MS Access (it has back-end MS Access db - although this is planned to 
change to some more robust RDBMS, and a front-end app built in MS Access). 
Currently this app is used to calculate the exact wages of some employees 
(sorry, English is not my native language so I don't know how that type of 
wage is called here, but basically we look at how many products they 
produced and calculate it based on that. It's not a hourly wage). However, 
this summer I would like to expand it to do some order management too (ie. 
each order has specific products that need to be produced... each of those 
can be produced by our employees and so it's directly linked to the wages).

However, it is very hard to manage everything using MS Access. Basically 
each time I make any change to FE or BE, I have to re-distribute the FE to 
all of the front-users. This is not a HUGE problem, the big problem, 
however, is within the MS Access itself, that is, it's very hard to manage 
all the forms as they are listed as simple names (ie. you cannot sub-group 
them efficiently to make a tree-view). Overall I cannot see myself working 
with MS Access in 5 years time as I can already see the scalability 
problems after a few months of working with it.

What I thought of, however, is making a website that is only for local use, 
but is it possible to have the same functionality as a regular front-end 
app? Is this good idea to begin with? I had a brief look at Django (I'm 
VERY new to web-dev, but I'm a fast learner I like to think) and I really 
like it so far. But is it possible to have the same level of functionality 
MS Access offers? That is, for example a sub-form on a form that gives more 
details about the current record selected in the main form? Ie. main form 
consists of overview of 10 recent orders and the lower portion of the main 
form is a subform that displays some detailed info about a selected order.

How does it stand from security-perspective if the app is changed from 
local to public? Obviously even on local I'd imagine I'd put a login 
requirement there, similar to how the admin page has it, but how safe is it 
regardless if put to public? Are there pre-determined measures that if 
taken, it will be 100% secure? As you'd imagine I wouldn't be very happy if 
someone deleted all of our inventory records because they could bypass the 
logging system.

Is there any good literature I can read up on doing some similar 
exercises/examples? For instance: orders/inventory management web app?

Thanks a lot 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fdee3fe0-6f3e-4d5b-862c-3a875b04035b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Sorry about this post

2016-04-29 Thread Gary Roach
I'm sorry that I am tying up everything with this message but am having 
problems with one of my mailing list accounts and need to trouble shoot.

None of my posts are showing up.

If anyone sees this just add something simple and return it to me.

I really appreciate your help.

Gary R

--
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/5723984F.1090506%40verizon.net.
For more options, visit https://groups.google.com/d/optout.


Re: Sorry about this post

2016-04-29 Thread m1chael
.

On Fri, Apr 29, 2016 at 1:22 PM, Gary Roach 
wrote:

> I'm sorry that I am tying up everything with this message but am having
> problems with one of my mailing list accounts and need to trouble shoot.
> None of my posts are showing up.
>
> If anyone sees this just add something simple and return it to me.
>
> I really appreciate your help.
>
> Gary R
>
> --
> 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/5723984F.1090506%40verizon.net
> .
> 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/CAAuoY6NC8Bw-EJgy%3DCcKLEyuAz-_wWSA5OX%2Ba2eKsAOyx2T0Vg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it good idea to transition from MS Access to a webapp? And if so, is Django a good tool to do it?

2016-04-29 Thread Fred Stluka

  
  
Patrik,

Yes, Django can be used for that.  

The "ORM" features and the "templates" and "views" of Django 
make it very easy to do a "CRUD" app for a users to create/
retrieve/update/delete data in any RDBMS.  

There are some built-in security features like logins, protection 
against "CSRF" attacks, etc.  

Django "formsets" make it easy to show multiple rows with a 
details panel for the row currently selected.

With a web app, you won't have to re-distribute the front 
end.  Just push a new version to the server.

Django's templates and views both support "inheritance", 
which should solve your problem of managing multiple 
related forms.  And, there are many Open Source custom 
widgets for Django and for _javascript_ that will give you all
the sub-grouping and tree-views that you need.

Django scales very well to large amounts of data, large 
numbers of screens, and large numbers of users.  There 
are many performance tuning options, including "caching"
of templates, and of fully-constructed pages, and of DB 
data.  Also, lots of other "middleware" for security, 
performance, logging, and other "aspects" of the software.

Yes, you can run a Django server locally, behind a "firewall",
or can expose it to the world, securing various parts as 
needed.

To make it as secure as possible, I'd put in on a Linux server
that is protected by tools like Logwatch, Fail2ban, and 
Tripwire.  See:
- http://bristle.com/Tips/Unix.htm#unix_security
And be sure to redirect all page requests from HTTP to 
HTTPS.

I do all of this and more, including processing financial 
transactions and supporting "multitenancy", restricting 
access by thousands of different users, each to his own data, 
plus "attribute based access control" for cases where data is
shared, at the Web site I'm currently working on:
- http://HelpHOPELive.org

Sorry for all the terms and acronyms, but if you're considering 
writing such an app, you'll need to be aware of them and they're 
all pretty easy to Google.  Feel free to reply with more questions. 


Also, you'll quickly get a feel for Django's power if you go 
through the on-line tutorial at:
- https://docs.djangoproject.com/en/dev/intro/

Enjoy!
--Fred

  
  Fred Stluka -- mailto:f...@bristle.com --
  http://bristle.com/~fred/
  
  Bristle Software, Inc -- http://bristle.com -- Glad to be of
  service!
  
  Open Source: Without walls and fences, we need no Windows or
  Gates.
  

On 4/29/16 12:57 PM, Patrik Mjartan
  wrote:


  Hi,


I work for a very small company that I developed an
  application for, all using MS Access (it has back-end MS
  Access db - although this is planned to change to some more
  robust RDBMS, and a front-end app built in MS Access).
  Currently this app is used to calculate the exact wages of
  some employees (sorry, English is not my native language so I
  don't know how that type of wage is called here, but basically
  we look at how many products they produced and calculate it
  based on that. It's not a hourly wage). However, this summer I
  would like to expand it to do some order management too (ie.
  each order has specific products that need to be produced...
  each of those can be produced by our employees and so it's
  directly linked to the wages).


However, it is very hard to manage everything using MS
  Access. Basically each time I make any change to FE or BE, I
  have to re-distribute the FE to all of the front-users. This
  is not a HUGE problem, the big problem, however, is within the
  MS Access itself, that is, it's very hard to manage all the
  forms as they are listed as simple names (ie. you cannot
  sub-group them efficiently to make a tree-view). Overall I
  cannot see myself working with MS Access in 5 years time as I
  can already see the scalability problems after a few months of
  working with it.


What I thought of, however, is making a website that is
  only for local use, but is it possible to have the same
  functionality as a regular front-end app? Is this good idea to
  begin with? I had a brief look at Django (I'm VERY new to
  web-dev, but I'm a fast learner I like to think) and I really
  like it so far. But is it possible to have the same level of
  functionality MS Access offers? That is, for example a
  sub-form on a form that gives more details about the current
  record selected in the main form? Ie. main form consists of

Re: Add id to url after login user

2016-04-29 Thread Dariusz Mysior
Sory I thought that You are from Poland like I :)

Hmm I try Your code but there is comment 

name 'request' is not defined


W dniu piątek, 29 kwietnia 2016 09:36:30 UTC+2 użytkownik Dariusz Mysior 
napisał:
>
> I use FormView do login user, but I don't know how I should add his ID 
> number to success url that when he will log in adres will be 
> users/profile/id
>
> urls.py
>
> from users.views import RegisterView, LoginView, ProfileView
>
> urlpatterns = [
>
> url(r'^register/$', RegisterView.as_view(), name='register-view'),
> url(r'^login/$', LoginView.as_view(), name='login-view'),
> url(r'^profile/(?P\d+)/$', ProfileView.as_view(), 
> name='profile-view'),
>
>
>
> views.py
>
> class LoginView(FormView):
> template_name = 'login_form.html'
> model = MysiteUser
> form_class = AuthenticationForm
> success_url = '/users/profile/'
>
>

-- 
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/af4e5a35-3704-4052-aa7d-3beffa16fd09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Display image instead of text in related-widget-wrapper of FK picker in admin interface.

2016-04-29 Thread Patrik Mjartan
How would one go about changing this:




into something where instead of 1, 2 there are pictures that correspond to 
those objects. The class itself is very simple:



Note that I use the picture already in the table view of this item 
(ie. admin/someapp/item/).

Can I somehow make the widget above also display the same image?

Thanks!

-- 
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/9032f08e-801a-464b-9bcf-b26ac42f6be1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New to Django (stuck at the end of the tutorial)

2016-04-29 Thread Mie Rex
I just did another try with a different version of Django which is same 
version of Django used in the book I am reading.
It turns out where the project(mysite) saved has no effect on it.  I think 
it's how Django suppose to behave.
Perhaps you are not working with the same version of Django as the 
tutorial??

The sense of achievement is great once the view function starts to working 
and progress are being made.
I hope you could figure out your problem soon.
Cheers~

Mie Rex於 2016年4月27日星期三 UTC-7下午7時02分56秒寫道:
>
> I had a smiliar problem with another Django tutorial.
>>
>
> I was running Django with Anaconda environment and I took the advice from 
> "Two Scoop Django" to have all projects stored in one directory and all the 
> environment in another.  Therefore the project "mysite" was initialized and 
> put in a folder, which was parallel to the environment folder.
> I fixed all the problem by initializing the project inside the environment 
> used for Django.
>
> Took me 3 days to figure out what was the problem.
> Hope you could figure out how to fix that soon.
> Cheers
>

-- 
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/f0794dab-736d-43a3-8b93-2ac69178e7bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.