Re: Chatbot using Django Channels. Persist a python object in a scope?

2018-06-10 Thread Rithwik Cherian
Hi Andrew,

Great. That's good to know. :) 
I'll try it out right away.
Yeah, I read somewhere that it is available from Channels 2. I am using the 
latest version anyways. :)

Well, pardon my usage. I am not 100% sure about what exactly these terms 
(websocket, asgi etc) mean exactly (I'm very new to all this), so I may 
have made a few mistakes when talking about them.
As for what happens when connection is lost or reconnects, I'm planning to 
store the state in a session variable as well to be safe.

On Sunday, June 10, 2018 at 10:14:29 PM UTC+5:30, Andrew Godwin wrote:
>
> Hi!
>
> You can indeed have things persist for the entire scope - the Consumer (or 
> any other ASGI app) does exactly this, and so if you're in a consumer you 
> can just store things on "self". That'll be tied to a specific socket and 
> garbage-collected once it's done (on Channels 2 only - channels 1 didn't do 
> this!)
>
> Of course, I am assuming you're meaning "per websocket". If you want to 
> use another protocol - like the ASGI Telegram server I cooked up - those 
> scopes are per-user but sometimes get garbage collected after an idle 
> period with no communication. You should think about this even for 
> WebSocket; what happens if the user's socket reconnects? Does the state 
> machine reset? If not, you need to store state somewhere externally from 
> the socket handling code.
>
> Andrew
>
> Andrew
>
> On Sat, Jun 9, 2018 at 5:05 AM Rithwik Cherian  > wrote:
>
>> Hello all,
>>
>> Very excited to discover the Channels project. I think it could be 
>> exactly what I was looking for. I am going through the documentation and 
>> seeing how it works right now, but I would really appreciate if someone 
>> could tell me if it will help me do what I want.
>>
>> I am making a chatbot, which is state dependent. The dialogue delivery 
>> and state management is handled by a Finite State Machine built using the 
>> transitions (pytransitions ) 
>> library. So my chatbot is a python object, which transitions from one state 
>> to another based on the users input. So to run the chatbot (per user per 
>> session) I need something exactly like the scope provided by channels, 
>> something that lasts for more than one request. 
>>
>> My question is *if I can have a python object instantiated per scope and 
>> have it persist for the duration of the scope*, so that for each user I 
>> can have a different object keeping track of which state the user is in and 
>> returning responses based on the state?
>>
>> Any help would be appreciated, as I am very inexperienced on things 
>> related to web (websockets, WSGI, ASGI etc.).
>>
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/142cb856-17f7-4cf1-9f3b-87d80e0ca5f8%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/0a2dc931-cd92-43ab-a6ee-9536dd018f9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Chatbot using Django Channels. Persist a python object in a scope?

2018-06-10 Thread Rithwik Cherian
Hey Ryan. 
The problem is actually not specific to pytransitions. But anyways, I 
wanted to persist an object in memory and not have to retrieve it from the 
DB every time. Although I'm not sure which is better for scaling (please 
give suggestions if you know more). As for recovering state, I'm planning 
to store the state in a session variable as a fail safe.

On Sunday, June 10, 2018 at 7:07:23 AM UTC+5:30, Ryan Nowakowski wrote:
>
> I've never used pytransitions. Typically persistent state in Django is 
> stored in the model instead of objects in memory. This allows you to easily 
> scale and also recover state if your app process stops.
>
> On June 9, 2018 1:01:14 AM CDT, Rithwik Cherian  > wrote:
>>
>> Hello all,
>>
>> Very excited to discover the Channels project. I think it could be 
>> exactly what I was looking for. I am going through the documentation and 
>> seeing how it works right now, but I would really appreciate if someone 
>> could tell me if it will help me do what I want.
>>
>> I am making a chatbot, which is state dependent. The dialogue delivery 
>> and state management is handled by a Finite State Machine built using the 
>> transitions (pytransitions ) 
>> library. So my chatbot is a python object, which transitions from one state 
>> to another based on the users input. So to run the chatbot (per user per 
>> session) I need something exactly like the scope provided by channels, 
>> something that lasts for more than one request. 
>>
>> My question is *if I can have a python object instantiated per scope and 
>> have it persist for the duration of the scope*, so that for each user I 
>> can have a different object keeping track of which state the user is in and 
>> returning responses based on the state?
>>
>> Any help would be appreciated, as I am very inexperienced on things 
>> related to web (websockets, WSGI, ASGI etc.).
>>
>> 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/cc8f52ad-4874-4345-a8e4-905b63f42f39%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trouble adding users through admin site

2018-06-10 Thread Dylan Moreland
Ah, perfect! I was inheriting from django.contrib.admin.ModelAdmin instead of 
django.contrib.auth.admin.UserAdmin. That worked. Thanks so much!

Dylan Moreland
Industrial Engineering Student
California Polytechnic State University, San Luis Obispo

> On Jun 9, 2018, at 17:30, Daniel Germano Travieso  
> wrote:
> 
> Hello Dylan
> 
> You will never see a user password as a raw text on django (only maybe if you 
> intercept the request the user creation form sent to the django view that 
> handles the creation)
> 
> User passwords are stored as their appropriate hash, and you can just use the 
> add user admin page to add a new user to your project (setting first it's 
> username and password and then the other settings).
> 
> Also, if you are using a custom User model that inherits AbstractUser, you 
> need to set it's UserAdmin (from django.contrib.auth.admin) via the admin.py 
> 
> You also need the setting AUTH_USER_MODEL to point to your custom User and do 
> this before creating or running any migrations or migrating
> 
> Check out the official docs [0] on the matter to learn more!
> 
> Also on an important note:
> User passwords are not displayed in the admin (nor stored in the database), 
> but the password storage details are displayed. Included in the display of 
> this information is a link to a password change form that allows admins to 
> change user passwords [1]
> 
> 
> [0] 
> https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project
>  
> 
> [1] https://djangobook.com/managing-users-admin/ 
> 
> 
> 
> 
> On Sat, Jun 9, 2018, 18:38 Dylan Moreland  > wrote:
> Hello!
> 
> I've created a Django app for my company to track employee infractions 
> (missed punch, late to a shift, etc.), but I'm at a roadblock in terms of 
> adding users. Currently, the only way I can add users is through the command 
> line. I'd much rather be able to add users through the django.contrib.admin 
> site. However, I've found that if I input a password there, it treats is as 
> the value to enter into the database (post hashing/salting/etc.) rather than 
> raw text. This obviously does not work.
> 
> I'm using an AbstractUser model called Employee to represent users instead of 
> the default User model. This is just so I have the option of customizing my 
> model down the road if need be without having to deal with broken ForeignKey 
> relationships.
> 
> If this were on the frontend, I would write a view that would take the raw 
> password and send it through set_password(), and that would be the end of it. 
> But I'm not sure how to do that with the admin site.
> 
> Models.py:
> from django.db import models
> from django.contrib.auth.models import AbstractUser
> 
> # Create your models here.
> class Employee(AbstractUser):
>  def __str__(self):
>  return self.first_name
> 
> class InfractionType(models.Model):
>  description = models.CharField(max_length=30)
> 
>  def __str__(self):
>  return self.description
> 
> 
> class Infraction(models.Model):
>  timestamp = models.DateTimeField()
>  employee = models.ForeignKey(Employee, on_delete=models.CASCADE)
>  type = models.ForeignKey(InfractionType, on_delete=models.CASCADE)
>  has_comment = models.BooleanField(default=False)
>  description = models.CharField(max_length=200)
> 
>  def __str__(self):
>  return str(self.employee) + ": " + self.description
> 
> 
> Admin.py:
> from django.contrib import admin
> 
> # Register your models here.
> from .models import Employee, InfractionType, Infraction
> 
> class InfractionInline(admin.TabularInline):
>  model = Infraction
>  extra = 0
> 
> class EmployeeAdmin(admin.ModelAdmin):
>  fieldsets = [
>  ('Authentication and Metadata', {'fields': ['username', 'first_name', 
> 'last_name', 'email', 'groups', 'is_staff', 'is_active'], 'classes': 
> ['collapse']}),
> 
>  ]
>  inlines = [InfractionInline]
> 
>  # Prevent users from getting deleted (should be made inactive instead)
>  def has_delete_permission(self, request, obj=None):
>  return False
> 
> admin.site.register(Employee, EmployeeAdmin)
> admin.site.register(InfractionType)
> 
> What I see on the admin site:
> 
>  
> 
>  
> 
>  
> 
> 
> 
> Thanks for your help!
> 
> -- 
> You received this message because you are subscribed to the Google 

Re: Interfaz administrativa, login con SSH

2018-06-10 Thread carlos
Hola, tambien te recomiendo que leas esto
Hi, i also recommend you read this

https://hackernoon.com/5-ways-to-make-django-admin-safer-eb7753698ac8


On Sun, Jun 10, 2018 at 8:02 PM Frank Mascarell <
frank_mascar...@gandiweb.com> wrote:

> Vijay, thanks for the help, but the authentication of two factors seems
> quite uncomfortable, considering that an administrator can enter every day,
> several times a day, having to depend on a mobile device for each login.
>
> I have to rethink the problem, perhaps by directly accessing postgres,
> through
> SSH with a GUI for the client-user that includes a CRUD interface,
> although I do not have
> knowledge of the software available for this. I have to investigate what
> other ways I can
> identify myself to a postgress database with SSH.
>
> Greetings.
>
> --
> 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/05cc0a47-79e8-4088-b54f-15d9d098c514%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
att.
Carlos Rocha

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


Odd problem with Incorrect padding error in Oauth2 flow using Django >=2.0

2018-06-10 Thread Malcolm MacKinnon

Using python 3.55 and django 1.10 in my Oauth2 flow (with 
django_openid_auth in my installed apps),
my code executes without any errors. But in a python 3.55 and django >=2.0 
environment, I get the following error:

Error at /openid/login/

Incorrect padding


I've spent two days searching for what's causing this and haven't found 
anything. There is some discussion here:
https://github.com/WeblateOrg/weblate/issues/1799
and here:
https://bugs.python.org/issue33770

But, I haven't found a solution. Does anyone know the reason why this is 
happening or have a solution?


Here's my traceback:
Internal Server Error: /openid/login/
Traceback (most recent call last):
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/django/core/handlers/exception.py",
 
line 35, in inner
response = get_response(request)
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/django/core/handlers/base.py",
 
line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/django/core/handlers/base.py",
 
line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/malcolm/qb6/qb5/django_openid_auth/views.py", line 191, in 
login_begin
openid_request = consumer.begin(openid_url)
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/openid/consumer/consumer.py",
 
line 359, in begin
return self.beginWithoutDiscovery(service, anonymous)
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/openid/consumer/consumer.py",
 
line 382, in beginWithoutDiscovery
auth_req = self.consumer.begin(service)
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/openid/consumer/consumer.py",
 
line 610, in begin
assoc = self._getAssociation(service_endpoint)
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/openid/consumer/consumer.py",
 
line 1178, in _getAssociation
assoc = self.store.getAssociation(endpoint.server_url)
  File "/home/malcolm/qb6/qb5/django_openid_auth/store.py", line 80, in 
getAssociation
base64.decodestring(assoc.secret.encode('utf-8')),
  File "/home/malcolm/anaconda3/envs/qb6/lib/python3.5/base64.py", line 
562, in decodestring
return decodebytes(s)
  File "/home/malcolm/anaconda3/envs/qb6/lib/python3.5/base64.py", line 
554, in decodebytes
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
ERROR:django.request:Internal Server Error: /openid/login/
Traceback (most recent call last):
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/django/core/handlers/exception.py",
 
line 35, in inner
response = get_response(request)
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/django/core/handlers/base.py",
 
line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/django/core/handlers/base.py",
 
line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/malcolm/qb6/qb5/django_openid_auth/views.py", line 191, in 
login_begin
openid_request = consumer.begin(openid_url)
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/openid/consumer/consumer.py",
 
line 359, in begin
return self.beginWithoutDiscovery(service, anonymous)
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/openid/consumer/consumer.py",
 
line 382, in beginWithoutDiscovery
auth_req = self.consumer.begin(service)
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/openid/consumer/consumer.py",
 
line 610, in begin
assoc = self._getAssociation(service_endpoint)
  File 
"/home/malcolm/anaconda3/envs/qb6/lib/python3.5/site-packages/openid/consumer/consumer.py",
 
line 1178, in _getAssociation
assoc = self.store.getAssociation(endpoint.server_url)
  File "/home/malcolm/qb6/qb5/django_openid_auth/store.py", line 80, in 
getAssociation
base64.decodestring(assoc.secret.encode('utf-8')),
  File "/home/malcolm/anaconda3/envs/qb6/lib/python3.5/base64.py", line 
562, in decodestring
return decodebytes(s)
  File "/home/malcolm/anaconda3/envs/qb6/lib/python3.5/base64.py", line 
554, in decodebytes
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
[11/Jun/2018 01:44:19] "GET 
/openid/login/?next=/quick/authCodeHandler%3Fstate%3Da2tbp1iauv66p9o8pnndhjfmy6fc8njotrgkppbx%26code%3DL011528681818rdMG5DmLYzdLfwvyaRcHY02PaWYoxkoxEP2w4%26realmId%3D123145812832527
 
HTTP/1.1" 500 150348


-- 
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 

Re: Interfaz administrativa, login con SSH

2018-06-10 Thread Frank Mascarell
Vijay, thanks for the help, but the authentication of two factors seems 
quite uncomfortable, considering that an administrator can enter every day, 
several times a day, having to depend on a mobile device for each login.

I have to rethink the problem, perhaps by directly accessing postgres, 
through
SSH with a GUI for the client-user that includes a CRUD interface, although 
I do not have
knowledge of the software available for this. I have to investigate what 
other ways I can
identify myself to a postgress database with SSH.

Greetings.

-- 
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/05cc0a47-79e8-4088-b54f-15d9d098c514%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Interfaz administrativa, login con SSH

2018-06-10 Thread Vijay Khemlani
En general SSH sirve para hacer conexiones remotas por terminal (bueno,
puedes hacer una sesión X a través de SSH pero no creo que sea lo que
necesites)

La forma más común de aumentar la seguridad del login es por two factor
authorization, básicamente mandar una validación a tu celular o algun otro
dispositivo que valide que seas tú el que está iniciando sesión.

Personalmente nunca lo he hecho, pero hay paquetes de Django que lo
implementan

http://django-two-factor-auth.readthedocs.io/en/stable/

Aunque requieren cierto nivel de configuración

El proyecto que linkeas no parece servir para hacer login con llaves SSH,
solo las almacena

Saludos

On Sun, Jun 10, 2018 at 8:49 PM Frank Mascarell <
frank_mascar...@gandiweb.com> wrote:

> Hi, sorry for the mistakes, I'm using google-translator :)
>
> I hired a VPS on Digital Ocean, installed Django-Postgres and everything
> works
>
> correctly. Now I want to increase the security of Django's administrative
> interface,
> I want site administrators to login using SSH, eliminating authentication
> by password. It would be something similar to when I connect to the server
> with PuTTY via SSH.
>
> There is little documentation of SSH-Django, but I found an interesting
> package called
> simplesshkey , which can
> relate SSH keys to a user, saving them in the database
> of Django. I do not know if with this package I can achieve my goal, but I
> do not think so.
>
> Is there any way to do this?
> Can I reconsider another way of connecting as an administrator to the
> database, less
>
> safe ? I would not like to have a remote open port in postgres, I would
> prefer it to be
>
> Managed through Django.
>
> --
> 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/9b1bb164-73af-4c92-9ed9-d7371c6bfa92%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/CALn3ei0C20rLDPyKJXWNCksFS_-uoov_AyQJrdTGQ95ABF3sJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Passing Django Template Vars to JS

2018-06-10 Thread Vijay Khemlani
I'm not sure why your code does not work (maybe there is a "race condition"
between the JS click handlers), but that global variable is a bad idea in
general.

You can add the comment ID as an attribute to your button, like



and in your event handler obtain the comment id

$("#like_comment_button").click(function (event) {
   var comment_id = event.target.getAttribute('data-comment-id')
   // Call AJAX
})

That way you don't need the global variable or the other click handler

Finally, it's a bad idea to have multiple elements with the same ID (all
comments will have a button with ID "like_comment_button") so it's better
to add it as a class rather than an id.

Regards





On Sun, Jun 10, 2018 at 11:19 AM Simon Connah 
wrote:

> I know that the standard way to do this is to create a script tag with
> a global JS variable in your Django template before you import your
> other JS files but that won't work for my current situation.
>
> I have an article detail view which is a single model instance. But I
> also have a list of comment objects that have a Foreign Key to the
> article (because that is the article that is being commented on).
>
> I need to pass the comment_id to the JS files that I am loading. If
> you want to see the code I am using then you can see it here:
>
>
> https://gitlab.com/glamorous-systems/seductive/blob/master/blog/templates/blog/article_detail.html
>
> I thought I'd use an onclick event on the Like / Dislike button to
> call a JS function which then passes that value to this JS file:
>
>
> https://gitlab.com/glamorous-systems/seductive/blob/master/blog/static/js/pass_comment_id.js
>
> and then I'd just call the return_comment_id() function from my other
> JS files to get the comment_id of the specific comment the user
> clicked the Like / Dislike button for. I think the problem is that my
> jQuery AJAX selectors are also looking for a click event, so they
> happen in a strange order, but I'm not sure.
>
> I'm totally lost on what I should be doing here. Any help would be
> very much appreciated :).
>
> --
> 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/CADNsu1OksTqc2crvX%3DK%3D_Kf_Xz1fCfABTRV-q48htRUikiAtXA%40mail.gmail.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/CALn3ei0ZneJzKAbSyN958_1RCaS7kjQY6VszQb8a%3D-Mxgod-GQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Interfaz administrativa, login con SSH

2018-06-10 Thread Frank Mascarell
Hola, lo siento por los errores, estoy usando google-traductor :)

Contraté un VPS en Digital Ocean, instalé Django-Postgres y todo funciona

correctamente. Ahora quiero aumentar la seguridad de la interfaz 
administrativa de Django,
Quiero que los administradores del sitio inicien sesión usando SSH, 
eliminando la autenticación
por contraseña Sería algo similar a cuando me conecto al servidor con PuTTY 
a través de SSH.

Hay poca documentación de SSH-Django, pero encontré un paquete interesante 
llamado
simplesshkey , que puede 
relacionar las claves SSH con un usuario, guardándolas en la base de datos
de Django. No sé si con este paquete puedo lograr mi objetivo, pero no lo 
creo.

¿Hay alguna manera de hacer esto?
¿Puedo reconsiderar otra forma de conectarme como administrador a la base 
de datos, menos

seguro ? No me gustaría tener un puerto abierto remoto en Postgres, 
preferiría que fuera

Administrado a través de Django.

Saludos.

-- 
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/e9c3552b-e751-45c5-92b2-380b40a00cd9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Interfaz administrativa, login con SSH

2018-06-10 Thread Frank Mascarell
Hi, sorry for the mistakes, I'm using google-translator :)

I hired a VPS on Digital Ocean, installed Django-Postgres and everything 
works

correctly. Now I want to increase the security of Django's administrative 
interface,
I want site administrators to login using SSH, eliminating authentication
by password. It would be something similar to when I connect to the server 
with PuTTY via SSH.

There is little documentation of SSH-Django, but I found an interesting 
package called
simplesshkey , which can 
relate SSH keys to a user, saving them in the database
of Django. I do not know if with this package I can achieve my goal, but I 
do not think so.

Is there any way to do this?
Can I reconsider another way of connecting as an administrator to the 
database, less

safe ? I would not like to have a remote open port in postgres, I would 
prefer it to be

Managed through Django.

-- 
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/9b1bb164-73af-4c92-9ed9-d7371c6bfa92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Anthony Anonde
the example.com is am example django give for Site. Which means there is a 
way for you to manage more than one site at a time, basically using the 
site_id.
To you Questions, i don't understand why you want to hard code your uri 
routing like that when you can easily use the app_name and name convention 
which is more dynamic then hard coding it like that: 
for example at the model Transaction urls.py 
app_name = "trans"
url(r'(?P-/d+)$', views.func, name='account_trans'),

def get_absolute_url(self):
return reverse("trans:account_trans",  kwargs={"pk":self.pk})


and you will be just fine hope this help



On Sunday, June 10, 2018 at 12:30:51 PM UTC+1, Joakim Hove wrote:
>
> Hello,
>
> I have a model `Transaction` which can be viewed at the url: 
> /transaction/view/$ID/ - if I just enter that url in the browser, or in 
> template everything works. But when I have the following get_abolute_url() 
> method:
>
> def get_absolute_url(self):
>  return "/transaction/view/{}/".format( self.id )
>
> things do not work from the Admin. When I click on the "View on Site" link 
> i am redirected to "http://example.com/transaction/view/23635/; and I get 
> an error message about failed XML parsing. I have no clue where the "
> example.com" address comes from - that string is not in my codebase. If I 
> hardcode the get_absolute_url to:
>
> def get_absolute_url(self):
>  return "http://127.0.0.1:8000/transaction/view{}/".format(self.id)
>
> That works in development, but needless to say that is not a very good 
> approach.
>
> I am on Django 1.10
>
>
> Regard Joakim
>
>
>

-- 
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/5678b297-2693-4ae8-b249-08e42713ebf7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Joakim Hove
Thank you;

that was indeed it!

On Sunday, June 10, 2018 at 11:03:54 PM UTC+2, Melvyn Sopacua wrote:
>
> On zondag 10 juni 2018 22:54:10 CEST Joakim Hove wrote: 
> > > > It is the default hostname for django.contrib.sites 
> > > 
> > > <
> https://github.com/django/django/blob/master/django/contrib/sites/managem 
> > > ent.py#L28> with SITE_ID = 1. 
> > 
> > OK - so that might be a smoking gun that I have not configured the 
> "sites" 
> > model correctly? I have so far not really related to the "sites" 
> > functionality at all. 
>
> It's enabled by default. And from the admin you can edit that hostname and 
> add 
> more sites. 
> Because Django supports multiple sites with a single admin, it generates 
> fully 
> qualified URLs for the "view on site" functionality, if 
> django.contrib.sites is 
> in INSTALLED_APPS. 
>
> -- 
> Melvyn Sopacua 
>

-- 
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/af654af4-ff87-45bd-9da4-038cbefc09cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Melvyn Sopacua
On zondag 10 juni 2018 22:54:10 CEST Joakim Hove wrote:
> > > It is the default hostname for django.contrib.sites
> > 
> >  > ent.py#L28> with SITE_ID = 1.
> 
> OK - so that might be a smoking gun that I have not configured the "sites"
> model correctly? I have so far not really related to the "sites"
> functionality at all.

It's enabled by default. And from the admin you can edit that hostname and add 
more sites.
Because Django supports multiple sites with a single admin, it generates fully 
qualified URLs for the "view on site" functionality, if django.contrib.sites is 
in INSTALLED_APPS.

-- 
Melvyn Sopacua

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


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Joakim Hove

>
>   
>
> > It is the default hostname for django.contrib.sites 
> 
>  
> with SITE_ID = 1.
>
>
OK - so that might be a smoking gun that I have not configured the "sites" 
model correctly? I have so far not really related to the "sites" 
functionality at all. 

-- 
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/dee9819f-fb1d-4a2f-9449-89ec0b3a8370%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Melvyn Sopacua
On zondag 10 juni 2018 13:30:51 CEST Joakim Hove wrote:

> things do not work from the Admin. When I click on the "View on Site" link
> i am redirected to "http://example.com/transaction/view/23635/; and I get
> an error message about failed XML parsing. I have no clue where the
> "example.com" address comes from - that string is not in my codebase.

It is the default hostname for django.contrib.sites[1] with SITE_ID = 1.
-- 
Melvyn Sopacua


[1] https://github.com/django/django/blob/master/django/contrib/sites/
management.py#L28

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


Re: Chatbot using Django Channels. Persist a python object in a scope?

2018-06-10 Thread Andrew Godwin
Hi!

You can indeed have things persist for the entire scope - the Consumer (or
any other ASGI app) does exactly this, and so if you're in a consumer you
can just store things on "self". That'll be tied to a specific socket and
garbage-collected once it's done (on Channels 2 only - channels 1 didn't do
this!)

Of course, I am assuming you're meaning "per websocket". If you want to use
another protocol - like the ASGI Telegram server I cooked up - those scopes
are per-user but sometimes get garbage collected after an idle period with
no communication. You should think about this even for WebSocket; what
happens if the user's socket reconnects? Does the state machine reset? If
not, you need to store state somewhere externally from the socket handling
code.

Andrew

Andrew

On Sat, Jun 9, 2018 at 5:05 AM Rithwik Cherian  wrote:

> Hello all,
>
> Very excited to discover the Channels project. I think it could be exactly
> what I was looking for. I am going through the documentation and seeing how
> it works right now, but I would really appreciate if someone could tell me
> if it will help me do what I want.
>
> I am making a chatbot, which is state dependent. The dialogue delivery and
> state management is handled by a Finite State Machine built using the
> transitions (pytransitions )
> library. So my chatbot is a python object, which transitions from one state
> to another based on the users input. So to run the chatbot (per user per
> session) I need something exactly like the scope provided by channels,
> something that lasts for more than one request.
>
> My question is *if I can have a python object instantiated per scope and
> have it persist for the duration of the scope*, so that for each user I
> can have a different object keeping track of which state the user is in and
> returning responses based on the state?
>
> Any help would be appreciated, as I am very inexperienced on things
> related to web (websockets, WSGI, ASGI etc.).
>
> 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/142cb856-17f7-4cf1-9f3b-87d80e0ca5f8%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/CAFwN1uq3emdzMgkqncBumhgday%3DjnLZPqeORhc28YfwZu5Fe%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Passing Django Template Vars to JS

2018-06-10 Thread Simon Connah
I know that the standard way to do this is to create a script tag with
a global JS variable in your Django template before you import your
other JS files but that won't work for my current situation.

I have an article detail view which is a single model instance. But I
also have a list of comment objects that have a Foreign Key to the
article (because that is the article that is being commented on).

I need to pass the comment_id to the JS files that I am loading. If
you want to see the code I am using then you can see it here:

https://gitlab.com/glamorous-systems/seductive/blob/master/blog/templates/blog/article_detail.html

I thought I'd use an onclick event on the Like / Dislike button to
call a JS function which then passes that value to this JS file:

https://gitlab.com/glamorous-systems/seductive/blob/master/blog/static/js/pass_comment_id.js

and then I'd just call the return_comment_id() function from my other
JS files to get the comment_id of the specific comment the user
clicked the Like / Dislike button for. I think the problem is that my
jQuery AJAX selectors are also looking for a click event, so they
happen in a strange order, but I'm not sure.

I'm totally lost on what I should be doing here. Any help would be
very much appreciated :).

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


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Joakim Hove
Thank  you for answering;

but I do not agree fully with your answer:

1. It is the @permalink decorator which is removed from Django 2.x - not
the get_abolute_url() method.
2. I agree using the reverse in the get_absolute_url() is nicer, and I have
also tried that - but the ersults were the same ... ;-(
3. Yes - I should upgrade

On Sun, Jun 10, 2018 at 2:19 PM Gerald Brown  wrote:

>  In version 2 of Django that function has been removed.
>
> For v 1.10 here is a link that might help:
> https://docs.djangoproject.com/en/1.10/ref/models/instances/#get-absolute-url
>
> Here is another link that might be of help:
> https://stackoverflow.com/questions/13503645/what-is-permalink-and-get-absolute-url-in-django?utm_medium=organic_source=google_rich_qa_campaign=google_rich_qa
>
> Hope this helps.
>
> BTW the first link says V1.10 is obsolete and is no longer supported!!!
>
> --
> 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/1c0b4b32-7154-4dd4-b437-92d0bba6c70e%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/CALKD1M8HqPs9rijWh63bAThh-o-6EsLNYFWLGQBm4%2BXjqkbB2g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Gerald Brown
 In version 2 of Django that function has been removed.

For v 1.10 here is a link that might help: 
https://docs.djangoproject.com/en/1.10/ref/models/instances/#get-absolute-url

Here is another link that might be of help: 
https://stackoverflow.com/questions/13503645/what-is-permalink-and-get-absolute-url-in-django?utm_medium=organic_source=google_rich_qa_campaign=google_rich_qa

Hope this helps.

BTW the first link says V1.10 is obsolete and is no longer supported!!!

-- 
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/1c0b4b32-7154-4dd4-b437-92d0bba6c70e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problem with get_absolute_url() in admin

2018-06-10 Thread Joakim Hove
Hello,

I have a model `Transaction` which can be viewed at the url: 
/transaction/view/$ID/ - if I just enter that url in the browser, or in 
template everything works. But when I have the following get_abolute_url() 
method:

def get_absolute_url(self):
 return "/transaction/view/{}/".format( self.id )

things do not work from the Admin. When I click on the "View on Site" link 
i am redirected to "http://example.com/transaction/view/23635/; and I get 
an error message about failed XML parsing. I have no clue where the 
"example.com" address comes from - that string is not in my codebase. If I 
hardcode the get_absolute_url to:

def get_absolute_url(self):
 return "http://127.0.0.1:8000/transaction/view{}/".format(self.id)

That works in development, but needless to say that is not a very good 
approach.

I am on Django 1.10


Regard Joakim


-- 
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/c6e8b55d-56b5-40f4-8505-76f1447c1542%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.