Re: I have problem in when submitting song_form

2017-01-31 Thread Александр Христюхин (roboslone)
Hi, it's your model, you probably have "album" field, that is required and not 
filled by a view.

> On 31 Jan 2017, at 14:35, sridhar chary  wrote:
> 
> I don't no where i made mistake
> 
> DETAIL.HTML
> 
> 
> {% extends 'music/base.html'%}
> {% block title %}Album detail{%endblock%}
> {% block body %}
> 
> 
>   
>   
>   
>   
>
>   
>   {% if album.album_logo %}
>src="{{album.album_logo.url}}">
>   {% else %}
>   no images to display
>   {% endif %}
>   
>   
>   
> {{album.album_title}}{{album.genre}}
>   {{album.artist}}   
> 
>   {{album.genre}}
>   
> 
> 
> 
>
>   
>   
>href="#">View All
>href="{% url 'music:song-add' album.id %}">Add new Song
>   
>   
>   
>   All Songs
>   
>   
> 
> 
> Title
> Audio File
> Favorite
> Actions
> 
>   
>   
>   {% for song in 
> album.song_set.all%}
>   
>   
> 
>   {{song.song_title}}
>   
>   
>
>   
>   
> 
> 
>  Play
> 
> 
> 
>   
>
>   
>  class="glyphicon glyphicon-star">
> 
> 
> 
> {% csrf_token %}
>  value="" />
> 
>  Delete
> 
>   
> 
>  
>   {% endfor%}
>   
>   
>   
>   
>   
>   
>   
>   
>   
> 
> 
> {% endblock %}
> 
> URLS.py 
> 
> 
> from django.conf.urls import include, url
> from music import views
> 
> app_name = 'music'
> 
> urlpatterns = [
>#this music url
>url(r'^$', views.IndexView.as_view(), name='index'),
>#registration form
>url(r'^register/$', views.UserFormView.as_view(), name='register'),
>#this music/detail(album_id)
>url(r'^(?P[0-9]+)/$', views.DetailView.as_view(), name='detail'),
>url(r'album/add/$',views.AlbumCreate.as_view(), name='album-add'),
>#this music/id/is_favorite
>#url(r'^(?P[0-9]+)/favorite/$', views.favorite, name='favorite'),
># music/album/2
>url(r'^album/(?P[0-9]+)/$',views.AlbumUpdate.as_view(), 
> name='album-update'),
>#music/album/2
>url(r'^album/(?P[0-9]+)/delete/$',views.AlbumDelete.as_view(), 
> name='album-delete'),
>#music/album/song/
>url(r'^song/add/(?P[0-9]+)/$', views.SongCreate.as_view(), 
> name="song-add"),
>

Re: creating models but its not showing in db

2017-01-31 Thread Александр Христюхин (roboslone)
Did you run makemigrations first and then migrate?
Also, do you have any instances of your model?

> On 31 Jan 2017, at 19:08, Kazi Atik  wrote:
> 
> Hi i am creating  a table in my model but its not showing in my sqlite.db 
> files i also run migrate command and makemigration
> Here is my code
> 
> 
> 
> 
>  
> from
>  django.db import models
> from django.contrib.auth.models import User
> 
> class Others (models.Model):
> education = models.TextField()
> aim = models.TextField()
> award = models.TextField()
> 
> please help me out this
> 
> 
> 
> -- 
> 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/24b80b57-45bc-41ac-ad12-935340139ead%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/A5B972EF-9CBF-4082-865B-5C195D6DA0CF%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing a custome Django Log Formatter.

2017-01-23 Thread Александр Христюхин (roboslone)
Hi, yes, it's absolutely possible. Refer to Django docs about logging 
(https://docs.djangoproject.com/en/1.10/topics/logging/ 
) and logging docs 
(https://docs.python.org/3/library/logging.config.html#logging-config-dictschema
 
).

What you're looking for is logging formatters and filters. Here's an example:


LOGGING = {
'formatters': {
'detailed': {
'format': '%(asctime)s %(module)s %(levelname)-8s- %(some_id)s 
%(message)s',
...
},
},
'handlers': {
'default': {
'formatter': 'detailed',
'filters': ['some_id_filter'],
...
},
...
},
'filters': {
'some_id_filter': {
'()': 'package.module.SomeIdFilter',
},
},
...
}


> On 23 Jan 2017, at 12:51, Arun S  wrote:
> 
> Hi all,
> 
> I have a small issue with writing a Custom Log Formatter.
> 
> By default: log_format = '%(asctime)s %(module)s %(levelname)-8s- %(message)s'
> 
> This is the Log formatter being used. 
> But only in a few cases or rather in a few modules, i would like to include 
> for ex: "some_id" as a seperator in the Logs. 
> Intended : log_format = '%(asctime)s %(module)s %(levelname)-8s- %(some_id)s 
> %(message)s'
> 
> But this always raises a Key Error and i would not want to change each and 
> every existing log and manually add the new log.
> 
> Is there a way to write this Custom Log format.???
> 
> I did try this:
> log_format = '%(asctime)s %(module)s %(levelname)-8s- %(some_id)s 
> %(message)s' %{'some_id': id}
> 
> This gives a Key Error " asctime "
> 
> And During Logging setup, i setup the Logging :
> 
> formatter = logging.Formatter(data.get('logging.log_format', None))
> file_handler.setFormatter(formatter)
> 
> 
> 
> 
> -- 
> 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/3275bad0-405b-4bbf-afe7-d0eeb1feb77f%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/67752380-BA71-4FCC-A8B7-234E494824BB%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing a custome Django Log Formatter.

2017-01-23 Thread Александр Христюхин (roboslone)
Filter applies to handlers, as you can see from my example. So what you need is 
a custom handler for loggers that require that some_id of yours.

> On 23 Jan 2017, at 13:04, Arun S  wrote:
> 
> Hi,
> 
> Thanks, I did this. But this applies to all the Modules in the Project.
> 
> Basically my issue is when Django is running with Celery and there are more 
> no of workers, the Logs needs to be diffrentiatied and also not for all the 
> Modules of the project.
> So in order to apply for a particular module and handle it in the Code, 
> 
> 
> Can the Filter be applied individally and part of the Code when the Logger is 
> being setup for a module.???
> 
> Thanks & Cheers
> Arun
> 
> 
> On Monday, January 23, 2017 at 3:29:25 PM UTC+5:30, Александр Христюхин wrote:
> Hi, yes, it's absolutely possible. Refer to Django docs about logging 
> (https://docs.djangoproject.com/en/1.10/topics/logging/ 
> ) and logging docs 
> (https://docs.python.org/3/library/logging.config.html#logging-config-dictschema
>  
> ).
> 
> What you're looking for is logging formatters and filters. Here's an example:
> 
> 
> LOGGING = {
> 'formatters': {
> 'detailed': {
> 'format': '%(asctime)s %(module)s %(levelname)-8s- %(some_id)s 
> %(message)s',
> ...
> },
> },
> 'handlers': {
> 'default': {
> 'formatter': 'detailed',
> 'filters': ['some_id_filter'],
> ...
> },
> ...
> },
> 'filters': {
> 'some_id_filter': {
> '()': 'package.module.SomeIdFilter',
> },
> },
> ...
> }
> 
> 
>> On 23 Jan 2017, at 12:51, Arun S gmail.com > 
>> wrote:
>> 
>> Hi all,
>> 
>> I have a small issue with writing a Custom Log Formatter.
>> 
>> By default: log_format = '%(asctime)s %(module)s %(levelname)-8s- 
>> %(message)s'
>> 
>> This is the Log formatter being used. 
>> But only in a few cases or rather in a few modules, i would like to include 
>> for ex: "some_id" as a seperator in the Logs. 
>> Intended : log_format = '%(asctime)s %(module)s %(levelname)-8s- %(some_id)s 
>> %(message)s'
>> 
>> But this always raises a Key Error and i would not want to change each and 
>> every existing log and manually add the new log.
>> 
>> Is there a way to write this Custom Log format.???
>> 
>> I did try this:
>> log_format = '%(asctime)s %(module)s %(levelname)-8s- %(some_id)s 
>> %(message)s' %{'some_id': id}
>> 
>> This gives a Key Error " asctime "
>> 
>> And During Logging setup, i setup the Logging :
>> 
>> formatter = logging.Formatter(data.get('logging.log_format', None))
>> file_handler.setFormatter(formatter)
>> 
>> 
>> 
>> 
>> -- 
>> 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/3275bad0-405b-4bbf-afe7-d0eeb1feb77f%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/7e5ce87f-5749-48da-96cb-e410dc669cd9%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 

Re: Extract Date-From and Date-To in DateRangeField django

2017-02-17 Thread Александр Христюхин (roboslone)
Hi, do you mean to store some kind of duration? There's DurationField for that. 
And you could store datetime.timedelta there. To get timedelta between two 
datetime.datetime objects, you could subtract ine from another:


from django.utils import timezone as tz

now = tz.now()
day_ago = tz.now() - tz.timedelta(days=1)
duration = now - day_ago  # duration can be stored in DurationField

> On 17 Feb 2017, at 04:31, RON MICHAEL  wrote:
> 
> Hi! In my database I have a DateRangeField. What I want to do is get the 
> date-from and the date-to and store them in a separate variable like example:
> 
> date_from =DateRangeField(date_from)
> date_to =DateRangeField(date_to)
> 
> 
> of course that code won't work. My data is like this:
> 
> 'date_range': DateRange(datetime.date(2017, 2, 17), datetime.date(2017, 2, 
> 18), '[)')
> 
> 
> 
> How do I get those dates?
> 
> Btw, I've tried indexing this, and it doesn't work. I've tried iterating it, 
> but it also doesn't work. 
> 
> 
> 
> -- 
> 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/848d9e95-4701-4984-bfee-64526621084e%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/14695B35-164D-480B-824F-DCBA8B9369AF%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Handle uncaught exceptions?

2017-02-28 Thread Александр Христюхин (roboslone)
Hi, what you need is a middleware with process_exception method. Be sure that 
it's the last one in MIDDLEWARE setting.
https://docs.djangoproject.com/en/1.10/topics/http/middleware/#process-exception
 



> On 28 Feb 2017, at 08:57, Chillar Anand  wrote:
> 
> In staging server, for staff users, I am trying to show actual exception even 
> if DEBUG is False.
> 
> I am using this wsgi file 
>  for 
> it. However, handle_uncaught_exception method is not getting called?
> 
> Any help on how to fix this?
> 
> -- 
> 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/fddd8515-bf54-4e73-94e4-e0f9afe42188%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/7D869CB5-A625-4FB8-AEE2-4FE96B7074E5%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Group Permissions programmatically

2017-07-31 Thread Александр Христюхин (roboslone)
Hi,

Why don't you use the same approach that is generally used with users? I mean 
you connect a signal to your User/Group model, that changes permission for 
created objects, like so:

@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_user_permissions(instance=None, created=None, **kwargs) -> None:
if created:
instance.user_permissions.add(...)  # add actual Permission objects here

> On 31 Jul 2017, at 10:23, Frank Semaganga  wrote:
> 
> Hi!
> 
> I am having a challenge . My aim is to be able to assign some group 
> permissions when the group is created. In admin.py I have a custom GroupAdmin 
> class  on which I have the function save customized but the challenge is 
> everything else get saved and reflected on admin page including user 
> permissions(if i set permissions to the user direct) but the group 
> permissions seems to be saved but when I go to admin page they are not 
> assigned.
> 
> Can you share you experience !
> 
> 
> permits = Permission.objects.filter(content_type__app_label='myapp')
> 
> Saved but not updated on Admin page
> obj.permissions=permits
> obj.save()
> 
> 
> #Works Perfect and changes seen on admin page
> user = User.objects.create_user('username12', '', 'password')
> user.groups.add(obj)
> user.user_permissions=perms
> user.is_staff=True
> user.save()
> 
> 
> obj is an object of Group.
> 
> 
> Regards
> 
> -- 
> 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/f862d504-99fa-4a1f-a6ea-523ba4cca67a%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/D062C2C9-125E-4DB0-85F6-E818CE6EB8F0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Python OSError No such file or directory but file exists

2017-08-02 Thread Александр Христюхин (roboslone)
Hi,

Are you sure s3file contains absolute path? I can't see where s3upload is being 
called.

Also, you might wanna use os.remove instead of calling subprocess.
You also might wanna check out PEP-8 and Sphinx for your docstrings.

> On 2 Aug 2017, at 02:28, Ronaldo Bahia  wrote:
> 
> Hi everyone, can you help me?
> Thanks in advance
> 
> Thread: 
> https://stackoverflow.com/questions/45449102/django-python-oserror-no-such-file-or-directory-but-file-exists
> 
> Code:
> 
> 
> 
> down vote
>  <>favorite
>  
> 
>   
> I'm converting doc and docx files to pdf in the server using unoconv with 
> LibreOffice. And I need to upload to S3 the converted file.
> 
> I can convert with success the files and I can see them in the server.
> 
> But when I try to upload the pdf, I get the error. What am I missing?
> 
> Thanks in advance
> 
> This works just fine:
> 
> import subprocess
> from boto.s3.connection import S3Connection, Bucket, Key
> 
> def doc_to_pdf(user):
> '''
> Convert doc or docx to PDF.
> 
> parameter user: is a request.user
> 
> Usage:
> doc_to_pdf(self.request.user):
> '''
> 
> user_cv = CandidateCV.objects.get(user=user)
> user_cv_file = str(user_cv.resume).split('/')[-1] # tem que ser PDF
> user_cv_filetype = user_cv_file.split('.')[-1]
> 
> if not user_cv_filetype in settings.PDF_FILE_TYPE:
> # Se não for PDF
> file_in = user_cv.resume.url
> file_name = file_in.split('/')[-1]
> # download
> urllib.request.urlretrieve(file_in, file_name)
> file_out = user_cv_file.split('.')[0] + '.pdf'
> 
> # converte para PDF
> env = os.environ.copy()
> env['HOME'] = '/tmp'
> subprocess.Popen(["unoconv","-f", "pdf", "%s" % (file_in)], env = env)
> 
> # Define a path para salvar o documento na S3
> resume_path = 'resumes/%s/' % str(date.today())
> 
> # key é o nome do arquivo na S3
> key = '%s%s' % (resume_path, file_out)
> 
> # deleta o arquivo localmente
> subprocess.call("rm -f %s" % user_cv_file, shell=True)
> 
> # Salva o novo formato no banco
> user_cv.resume = key
> user_cv.save()
> This is the code in which I get the error in line: 
> k_out.set_contents_from_filename(s3file)
> 
> def s3upload(s3file):
> 
> # Conecta na AWS S3
> conn = S3Connection(settings.AWS_ACCESS_KEY_ID, 
> settings.AWS_SECRET_ACCESS_KEY)
> bucket_out = Bucket(conn, settings.AWS_STORAGE_BUCKET_NAME)
> k_out = Key(bucket=bucket_out, name=s3file)
> 
> # Define a path para salvar o documento na S3
> resume_path = 'resumes/%s/' % str(date.today())
> 
> # key é o nome do arquivo na S3
> key = '%s%s' % (resume_path, s3file)
> k_out.key = key
> 
> # Salva na AWS S3
> k_out.set_contents_from_filename(s3file)
> k_out.make_public()
> 
> # deleta o arquivo localmente
> subprocess.call("rm -f %s" % s3file, shell=True)
> 
> 
> -- 
> 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/7cecdcdb-7fcf-4f4a-858a-30801fa9cf9b%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/6BC03BEF-B4AD-49AB-8A2A-6EDDAD0DB13F%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tutorial help Blank Front page

2017-08-11 Thread Александр Христюхин (roboslone)
Hi,

You should open "http://127.0.0.1:8000/polls/ " 
instead of "http://127.0.0.1:8000/ ".
Take a look at the error Django gives you, all registered URLs are listed there.

> On 11 Aug 2017, at 20:56, Kareem Hart  wrote:
> 
> I am currently doing the tutorial and I'm writing views.
> 
> I wrote my index.html file and updated the view to use a loader and add the 
> extra code that they provided. It tells me next to load 127.0.0.1:8000/polls 
> and I should see a bulleted list containing the "whats up" question but my 
> page is blank. 
> 
> Also when I point my browser towards the http://127.0.0.1:8000/, it gives me 
> the following error.
> 
> Page not found (404)
> Request Method:   GET
> Request URL:  http://127.0.0.1:8000/
> Using the URLconf defined in mysite.urls, Django tried these URL patterns, in 
> this order:
> 
> ^polls/
> ^admin/
> The empty path didn't match any of these.
> 
> 
> 
> So I checked the code for mysite.urls.
> 
> 
> 
> from django.conf.urls import url, include
> 
> from django.contrib import admin
> 
> 
> 
> urlpatterns = [
> 
> url(r'^polls/', include('polls.urls')),
> 
> url(r'^admin/', admin.site.urls),
> 
> ]
> 
> 
> I ran the following command and got no issues.
> $python manage.py check 
> 
> 
> 
> 
> -- 
> 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/c7383a02-dd7f-407d-9ea0-297e8ca85c4b%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/BCAC4AAF-47EF-4D24-A25D-2B3013DA68F4%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to handle nested backward lookups in a template for a generic detail view?

2017-08-09 Thread Александр Христюхин (roboslone)
You still can reference the data:


class Foo(models.Model):
pass

class Bar(models.Model):
foo = models.ForeignKey(Foo, related_name='bars')

f = Foo()
b1 = Bar(foo=f)
b2 = Bar(foo=f)

f.bars.all()  # 


> On 9 Aug 2017, at 18:19, Thomas Hughes <ezero.technol...@gmail.com> wrote:
> 
> Thank you for your reply.
> 
> I understand your third point.  In this application though I have a many 
> images to a single detail structure.
> 
> For your first point "use `related_name` in your model fields to get pretty 
> backref names (so you don't have to use image_set everywhere)", how do I do 
> that and maintain the ability to reference the data via the two-fold nested 
> loop I need in my HTML template?
> 
> Thanks,
> 
> Tom
> 
> On Wednesday, August 9, 2017 at 9:10:33 AM UTC-4, Александр Христюхин wrote:
> Whoops, looks like all dots are in place, my mistake. First and last points 
> are still valid, though.
> 
>> On 9 Aug 2017, at 16:08, Александр Христюхин (roboslone) <robo...@gmail.com 
>> > wrote:
>> 
>> Hi,
>> 
>> First of all, you can use `related_name` in your model fields to get pretty 
>> backref names (so you don't have to use image_set everywhere).
>> 
>> Second, you're missing dots in your template (`for detail in 
>> project.projectdetail_set.all`).
>> 
>> And finally, your model is called ProjectDetailImage and it has a field, 
>> that is named `image`. So you won't be able to get rid of `image.image.url`. 
>> However, you can move your image to ProjectDetail model (add field `image = 
>> models.ImageField(...)`) and use it like so:
>> 
>> {% for detail in project.projectdetail_set.all %}
>> 
>> {% endfor %}
>> 
>>> On 9 Aug 2017, at 15:33, Thomas Hughes <ezero.te...@gmail.com 
>>> > wrote:
>>> 
>>> Just FYI - the issue was with using 'image.url' rather than 
>>> 'image.image.url' in code labeled with 'do something with image' in the 
>>> HTML template above.
>>> 
>>> On Monday, August 7, 2017 at 3:52:15 PM UTC-4, Thomas Hughes wrote:
>>> I have a generic detail view serving content for 'project' to an HTML 
>>> template with the following code: 
>>> 
>>> {% for detail in project.projectdetail_set.all %}
>>> {% for image in detail.projectdetailimage_set.all %}
>>> do something with image
>>> {% endfor %}
>>> {% endfor %}
>>> and my models look like:
>>> 
>>> class Project(models.Model):
>>> name = models.CharField(max_length=1000)
>>> start_date = models.DateField()
>>> abstract = models.TextField()
>>> abstract_image = models.ImageField(storage=PROJECT_STORAGE)
>>> 
>>> def __str__(self):
>>> return self.name <http://self.name/>
>>> 
>>> class ProjectDetail(models.Model):
>>> project = models.ForeignKey(Project, on_delete=models.CASCADE)
>>> name = models.CharField(max_length=1000)
>>> text = models.TextField()
>>> 
>>> def __str__(self):
>>> return self.name <http://self.name/>
>>> 
>>> class ProjectDetailImage(models.Model):
>>> detail = models.ForeignKey(ProjectDetail, on_delete=models.CASCADE)
>>> image = models.ImageField(storage=PROJECT_STORAGE)
>>> It looks like generic detail view only arranges for backward lookup on the 
>>> 'project' via .projectdetail_set.all but not on the 'detail' as the HTML 
>>> for .projectdetailimage_set.all just never shows up in the HTML source. I 
>>> am wondering then what is the proper way to handle nested ForeignKeys like 
>>> this, basically like a Book > Section > Chapter structure where a Book has 
>>> several Sections and a Section has several Chapters and Chapters are only 
>>> associated with Sections and Sections are only associated with Books.
>>> 
>>> 
>>> -- 
>>> 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 
>>> <https://groups.google.com/group/django-users>.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/aca8ff0e-cf46-407d-9a58-36feb7d7627

Re: Django, permission error saving on disk, why?

2017-07-04 Thread Александр Христюхин (roboslone)
Looks like Linux permission issue. Are you sure user that runs Django is 
allowed to write anything to given directory?

> On 4 Jul 2017, at 14:37, Antonis Christofides  
> wrote:
> 
> Is it possible to show full traceback and error message?
> Antonis Christofides
> http://djangodeployment.com 
> On 2017-07-04 14:33, miguel vfx wrote:
>> Hello,I'm getting a Permissions Error [Errno 13] Permission Denied when a 
>> workbook on disk using openpyxl:
>> wb.save(path)
>> No file is uploaded. It's a request then the file is generated and delivered 
>> (downloaded), and that part works fine. What I'm trying to do is save a copy 
>> of that file on disk.
>> 
>> 
>> So far I have rw to both group and others. Same error.
>> 
>> 
>> Has anyone tried this before? Is this a Django issue or Linux/Permission? 
>> Thank you for the help.
>> 
>> -- 
>> 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/1d973104-6c3f-4b67-865a-389ab58f39a8%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/72cbeb2d-cc8b-7bdd-7423-79dd698e6f8c%40djangodeployment.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/70E25BBC-9264-4B17-B7B1-6AB489000BB6%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to handle nested backward lookups in a template for a generic detail view?

2017-08-09 Thread Александр Христюхин (roboslone)
Whoops, looks like all dots are in place, my mistake. First and last points are 
still valid, though.

> On 9 Aug 2017, at 16:08, Александр Христюхин (roboslone) 
> <robosl...@gmail.com> wrote:
> 
> Hi,
> 
> First of all, you can use `related_name` in your model fields to get pretty 
> backref names (so you don't have to use image_set everywhere).
> 
> Second, you're missing dots in your template (`for detail in 
> project.projectdetail_set.all`).
> 
> And finally, your model is called ProjectDetailImage and it has a field, that 
> is named `image`. So you won't be able to get rid of `image.image.url`. 
> However, you can move your image to ProjectDetail model (add field `image = 
> models.ImageField(...)`) and use it like so:
> 
> {% for detail in project.projectdetail_set.all %}
> 
> {% endfor %}
> 
>> On 9 Aug 2017, at 15:33, Thomas Hughes <ezero.technol...@gmail.com 
>> <mailto:ezero.technol...@gmail.com>> wrote:
>> 
>> Just FYI - the issue was with using 'image.url' rather than 
>> 'image.image.url' in code labeled with 'do something with image' in the HTML 
>> template above.
>> 
>> On Monday, August 7, 2017 at 3:52:15 PM UTC-4, Thomas Hughes wrote:
>> I have a generic detail view serving content for 'project' to an HTML 
>> template with the following code: 
>> 
>> {% for detail in project.projectdetail_set.all %}
>> {% for image in detail.projectdetailimage_set.all %}
>> do something with image
>> {% endfor %}
>> {% endfor %}
>> and my models look like:
>> 
>> class Project(models.Model):
>> name = models.CharField(max_length=1000)
>> start_date = models.DateField()
>> abstract = models.TextField()
>> abstract_image = models.ImageField(storage=PROJECT_STORAGE)
>> 
>> def __str__(self):
>> return self.name <http://self.name/>
>> 
>> class ProjectDetail(models.Model):
>> project = models.ForeignKey(Project, on_delete=models.CASCADE)
>> name = models.CharField(max_length=1000)
>> text = models.TextField()
>> 
>> def __str__(self):
>> return self.name <http://self.name/>
>> 
>> class ProjectDetailImage(models.Model):
>> detail = models.ForeignKey(ProjectDetail, on_delete=models.CASCADE)
>> image = models.ImageField(storage=PROJECT_STORAGE)
>> It looks like generic detail view only arranges for backward lookup on the 
>> 'project' via .projectdetail_set.all but not on the 'detail' as the HTML for 
>> .projectdetailimage_set.all just never shows up in the HTML source. I am 
>> wondering then what is the proper way to handle nested ForeignKeys like 
>> this, basically like a Book > Section > Chapter structure where a Book has 
>> several Sections and a Section has several Chapters and Chapters are only 
>> associated with Sections and Sections are only associated with Books.
>> 
>> 
>> -- 
>> 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 
>> <mailto:django-users+unsubscr...@googlegroups.com>.
>> To post to this group, send email to django-users@googlegroups.com 
>> <mailto:django-users@googlegroups.com>.
>> Visit this group at https://groups.google.com/group/django-users 
>> <https://groups.google.com/group/django-users>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/aca8ff0e-cf46-407d-9a58-36feb7d76276%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/aca8ff0e-cf46-407d-9a58-36feb7d76276%40googlegroups.com?utm_medium=email_source=footer>.
>> For more options, visit https://groups.google.com/d/optout 
>> <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/E9E21E4C-B503-4005-86DA-8FFA5629A85F%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to handle nested backward lookups in a template for a generic detail view?

2017-08-09 Thread Александр Христюхин (roboslone)
Hi,

First of all, you can use `related_name` in your model fields to get pretty 
backref names (so you don't have to use image_set everywhere).

Second, you're missing dots in your template (`for detail in 
project.projectdetail_set.all`).

And finally, your model is called ProjectDetailImage and it has a field, that 
is named `image`. So you won't be able to get rid of `image.image.url`. 
However, you can move your image to ProjectDetail model (add field `image = 
models.ImageField(...)`) and use it like so:

{% for detail in project.projectdetail_set.all %}

{% endfor %}

> On 9 Aug 2017, at 15:33, Thomas Hughes  wrote:
> 
> Just FYI - the issue was with using 'image.url' rather than 'image.image.url' 
> in code labeled with 'do something with image' in the HTML template above.
> 
> On Monday, August 7, 2017 at 3:52:15 PM UTC-4, Thomas Hughes wrote:
> I have a generic detail view serving content for 'project' to an HTML 
> template with the following code: 
> 
> {% for detail in project.projectdetail_set.all %}
> {% for image in detail.projectdetailimage_set.all %}
> do something with image
> {% endfor %}
> {% endfor %}
> and my models look like:
> 
> class Project(models.Model):
> name = models.CharField(max_length=1000)
> start_date = models.DateField()
> abstract = models.TextField()
> abstract_image = models.ImageField(storage=PROJECT_STORAGE)
> 
> def __str__(self):
> return self.name 
> 
> class ProjectDetail(models.Model):
> project = models.ForeignKey(Project, on_delete=models.CASCADE)
> name = models.CharField(max_length=1000)
> text = models.TextField()
> 
> def __str__(self):
> return self.name 
> 
> class ProjectDetailImage(models.Model):
> detail = models.ForeignKey(ProjectDetail, on_delete=models.CASCADE)
> image = models.ImageField(storage=PROJECT_STORAGE)
> It looks like generic detail view only arranges for backward lookup on the 
> 'project' via .projectdetail_set.all but not on the 'detail' as the HTML for 
> .projectdetailimage_set.all just never shows up in the HTML source. I am 
> wondering then what is the proper way to handle nested ForeignKeys like this, 
> basically like a Book > Section > Chapter structure where a Book has several 
> Sections and a Section has several Chapters and Chapters are only associated 
> with Sections and Sections are only associated with Books.
> 
> 
> -- 
> 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/aca8ff0e-cf46-407d-9a58-36feb7d76276%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/71ADE1A0-A0A8-435E-8104-9B89931BAA19%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Python OSError No such file or directory but file exists

2017-08-07 Thread Александр Христюхин (roboslone)
Well, yeah, you're using local path basically. And you should NEVER use 
.split('/')[-1] to determine file basename, take a look at os.path module 
instead.

But that's not the point. You should try to use absolute path, I believe it 
would do the trick.

> On 4 Aug 2017, at 17:49, Ronaldo Bahia <rona...@jobconvo.com> wrote:
> 
> the method is called in a def post() within a class view:
> 
> user_cv = CandidateCV.objects.get(user=request.user)
> user_cv_file = str(user_cv.resume).split('/')[-1]
> s3upload(user_cv_file)
> 
> The file is converted from doc to pdf in server project folder, where 
> manage.py is.
> So probably there is no absolute path.
> 
> How can I solve it?
> 
> Thanks
> Ronaldo Bahia
> +55 11 3280 6971
> +55 11 963 622 581
> 
> Materiais gratuitos para o RH:
> - ROI - Melhorando Indicadores no RH 
> <http://blog.jobconvo.com/post/110644747055/o-impacto-das-entrevistas-virtuais-no-recrutamento?from=email>
> - Manual do Recrutador Moderno 
> <http://blog.jobconvo.com/post/108666785355/manual-do-recrutador-moderno?from=email>
> 2017-08-03 1:36 GMT-03:00 "Александр Христюхин (roboslone)" 
> <robosl...@gmail.com <mailto:robosl...@gmail.com>>:
> Hi,
> 
> Are you sure s3file contains absolute path? I can't see where s3upload is 
> being called.
> 
> Also, you might wanna use os.remove instead of calling subprocess.
> You also might wanna check out PEP-8 and Sphinx for your docstrings.
> 
>> On 2 Aug 2017, at 02:28, Ronaldo Bahia <rona...@jobconvo.com 
>> <mailto:rona...@jobconvo.com>> wrote:
>> 
>> Hi everyone, can you help me?
>> Thanks in advance
>> 
>> Thread: 
>> https://stackoverflow.com/questions/45449102/django-python-oserror-no-such-file-or-directory-but-file-exists
>>  
>> <https://stackoverflow.com/questions/45449102/django-python-oserror-no-such-file-or-directory-but-file-exists>
>> 
>> Code:
>> 
>> 
>> 
>> down vote
>>  <>favorite
>>  
>> <https://stackoverflow.com/questions/45449102/django-python-oserror-no-such-file-or-directory-but-file-exists#>
>>  
>> I'm converting doc and docx files to pdf in the server using unoconv with 
>> LibreOffice. And I need to upload to S3 the converted file.
>> 
>> I can convert with success the files and I can see them in the server.
>> 
>> But when I try to upload the pdf, I get the error. What am I missing?
>> 
>> Thanks in advance
>> 
>> This works just fine:
>> 
>> import subprocess
>> from boto.s3.connection import S3Connection, Bucket, Key
>> 
>> def doc_to_pdf(user):
>> '''
>> Convert doc or docx to PDF.
>> 
>> parameter user: is a request.user
>> 
>> Usage:
>> doc_to_pdf(self.request.user):
>> '''
>> 
>> user_cv = CandidateCV.objects.get(user=user)
>> user_cv_file = str(user_cv.resume).split('/')[-1] # tem que ser PDF
>> user_cv_filetype = user_cv_file.split('.')[-1]
>> 
>> if not user_cv_filetype in settings.PDF_FILE_TYPE:
>> # Se não for PDF
>> file_in = user_cv.resume.url
>> file_name = file_in.split('/')[-1]
>> # download
>> urllib.request.urlretrieve(file_in, file_name)
>> file_out = user_cv_file.split('.')[0] + '.pdf'
>> 
>> # converte para PDF
>> env = os.environ.copy()
>> env['HOME'] = '/tmp'
>> subprocess.Popen(["unoconv","-f", "pdf", "%s" % (file_in)], env = 
>> env)
>> 
>> # Define a path para salvar o documento na S3
>> resume_path = 'resumes/%s/' % str(date.today())
>> 
>> # key é o nome do arquivo na S3
>> key = '%s%s' % (resume_path, file_out)
>> 
>> # deleta o arquivo localmente
>> subprocess.call("rm -f %s" % user_cv_file, shell=True)
>> 
>> # Salva o novo formato no banco
>> user_cv.resume = key
>> user_cv.save()
>> This is the code in which I get the error in line: 
>> k_out.set_contents_from_filename(s3file)
>> 
>> def s3upload(s3file):
>> 
>> # Conecta na AWS S3
>> conn = S3Connection(settings.AWS_ACCESS_KEY_ID, 
>> settings.AWS_SECRET_ACCESS_KEY)
>> bucket_out = Bucket(conn, settings.AWS_STORAGE_BUCKET_NAME)
>> k_out = Key(bucket=bucket_out, name=s3file)
>> 
>> # Define a path para salvar o documento na S3
>> resume_path = 'resumes/%s/' % str(date.today())
>&g

Re: Model with mix of timezone aware and naive datetimes?

2017-06-22 Thread Александр Христюхин (roboslone)
Why don't you store all your time as tz-aware and let views decide how to 
display them?

> On 22 Jun 2017, at 05:49, Chris Beck  wrote:
> 
> I a model that requires both timezone aware and naive datetimes. To be 
> specific, I am modelling a travel segment where the standard for departure 
> and arrival is to always use current local time, regardless of tz/dst/ as 
> well as an approved_on field that should have a tz.
> 
> Is there anyway to declare the desired timezone support for the datetime 
> field in the model? I'm trying to avoid "RuntimeWarning: DateTimeField 
> XXX.timestamp received a naive datetime" warning spam in my output.
> 
> 
> 
> -- 
> 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/a24aa1dd-95a1-47ba-93fc-01841b982083%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/E0260CC8-081C-41CD-A809-CB50656CAC34%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: testing in django

2017-05-23 Thread Александр Христюхин (roboslone)
Perhaps fixtures is what you want: https://code.djangoproject.com/wiki/Fixtures 


> On 23 May 2017, at 10:07, Akash Tomar  wrote:
> 
> class SignUpTest(TestCase):
>   def test_createAccount(self):
>   my_data = {'username': 'akash.tomar107', 'password': 
> 'akashtomar',"email":"akash.tomar...@gmail.com", 
> "confirm_password":"akashtomar", "type_of_user":"1", "first_name":"akash", 
> "last_name":"tomar"}
>   response = self.client.post('/signup/', json.dumps(my_data), 
> content_type='application/json')
>   self.assertIs(json.loads(response.content)["success"], True)
> 
> class LoginTest(TestCase):
>   def test_login(self):
>   my_data = {'username': 'akash.tomar107', 'password': 
> 'akashtomar'}
>   response = self.client.post('/login/', json.dumps(my_data), 
> content_type='application/json')
>   # import pdb; pdb.set_trace()
>   self.assertIs(json.loads(response.content)["login"], True)
> 
> 
> I want to be able to use the data created while running SignUpTest in the 
> LoginTest. How do I achieve that? Please help.
> 
> -- 
> 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/a3625070-4f46-4c68-b912-888b91e42c82%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/938F7C2B-E0BE-4F4B-93DD-81C8652BD7AF%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Install Django

2017-06-07 Thread Александр Христюхин (roboslone)
It has nothing to do with pytz. The issue is that you're trying to install 
packages into system's python. You shouldn't do it ever.
Use virtualenv instead: https://virtualenv.pypa.io/en/stable/ 


> On 7 Jun 2017, at 10:34, sadri ashari  wrote:
> 
>  
> please
>  help me, i cant install django, if i install it always stack in collecting 
> pytz package..  what's wrong ?
> 
> -- 
> 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/2b685e42-f5dd-442e-ac81-09b358f5a9dc%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/C3CF7F6B-468D-4BC8-B70F-CA394887F5E5%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: I use requests to submit form,how to bate Django's csrfmiddlewaretoken

2017-06-15 Thread Александр Христюхин (roboslone)
CSRF token value is passed in Django's response headers.
And anyway, you're no supposed to post data like that. Do you do that in tests?

> On 15 Jun 2017, at 16:20, liyutong19961...@gmail.com wrote:
> 
> I uis this code to submit form
> ```python
> import requests
> 
> url = 'http://127.0.0.1:8000/contact/'
> d = {'subject':'你好','email':'','message':'thank u'}
> r = requests.post(url,data = d)
> print(r.text)
> ```
> 
> but i don't has csrfmiddlewaretoken's values
> I try to use requests.get to get csrfmiddlewaretoken's values then post,it 
> also wrong,what should i do?
> 
> -- 
> 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/b2a43a6f-cbe1-4347-be28-5f298093dae8%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/11F572EF-E25A-481E-9B93-1AA512E4B1D6%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: I use requests to submit form,how to bate Django's csrfmiddlewaretoken

2017-06-15 Thread Александр Христюхин (roboslone)
https://docs.djangoproject.com/en/1.11/ref/csrf/#ajax 


> On 15 Jun 2017, at 17:20, 李余通  wrote:
> 
> Sorry,the message of Django CSRF and X-CSRFToken i can find is less.
> Can you give me an example to use requests or urllib2 and set "X-CSRFToken" 
> header to post form?
> Thank you very much!
> 
> 在 2017年6月15日星期四 UTC+8下午9:37:25,Александр Христюхин写道:
> You could set "X-CSRFToken" header, that would be enough. Why do you post 
> data manually though?
> 
>> On 15 Jun 2017, at 16:33, 李余通  wrote:
>> 
>> Ture,my way is wrong,should i send cookies?
>> 
>> 在 2017年6月15日星期四 UTC+8下午9:29:17,Александр Христюхин写道:
>> CSRF token value is passed in Django's response headers.
>> And anyway, you're no supposed to post data like that. Do you do that in 
>> tests?
>> 
>>> On 15 Jun 2017, at 16:20, liyutong...@gmail.com <> wrote:
>>> 
>>> I uis this code to submit form
>>> ```python
>>> import requests
>>> 
>>> url = 'http://127.0.0.1:8000/contact/ '
>>> d = {'subject':'你好','email':'','message':'thank u'}
>>> r = requests.post(url,data = d)
>>> print(r.text)
>>> ```
>>> 
>>> but i don't has csrfmiddlewaretoken's values
>>> I try to use requests.get to get csrfmiddlewaretoken's values then post,it 
>>> also wrong,what should i do?
>>> 
>>> -- 
>>> 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/b2a43a6f-cbe1-4347-be28-5f298093dae8%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...@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/e4931b53-1006-457b-b48f-3e16917cc908%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/0fbf3f28-7af7-49e2-aee0-a961cabf1865%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/DC576B22-5996-4225-8E29-52601DDC5C95%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: I use requests to submit form,how to bate Django's csrfmiddlewaretoken

2017-06-15 Thread Александр Христюхин (roboslone)
You could set "X-CSRFToken" header, that would be enough. Why do you post data 
manually though?

> On 15 Jun 2017, at 16:33, 李余通  wrote:
> 
> Ture,my way is wrong,should i send cookies?
> 
> 在 2017年6月15日星期四 UTC+8下午9:29:17,Александр Христюхин写道:
> CSRF token value is passed in Django's response headers.
> And anyway, you're no supposed to post data like that. Do you do that in 
> tests?
> 
>> On 15 Jun 2017, at 16:20, liyutong...@gmail.com  wrote:
>> 
>> I uis this code to submit form
>> ```python
>> import requests
>> 
>> url = 'http://127.0.0.1:8000/contact/ '
>> d = {'subject':'你好','email':'','message':'thank u'}
>> r = requests.post(url,data = d)
>> print(r.text)
>> ```
>> 
>> but i don't has csrfmiddlewaretoken's values
>> I try to use requests.get to get csrfmiddlewaretoken's values then post,it 
>> also wrong,what should i do?
>> 
>> -- 
>> 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/b2a43a6f-cbe1-4347-be28-5f298093dae8%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/e4931b53-1006-457b-b48f-3e16917cc908%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/6D024762-6FEC-4A2C-962D-FD2A8BAE3BDA%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: cors headers in django

2017-09-20 Thread Александр Христюхин (roboslone)
Hi, take a look at this package: https://github.com/ottoyiu/django-cors-headers 

README is pretty thorough.

> On 20 Sep 2017, at 12:51, Rakhee Menon  wrote:
> 
> Hello,
> Please can anyone tell how to add CORS headers in  Django and where should I 
> add it??
> 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 https://groups.google.com/group/django-users 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/da6c7389-89d2-4426-92e2-0acea471281a%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/7030F12B-52D8-479C-BA22-3EED2071BC03%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: setup.py for Django project?

2017-09-08 Thread Александр Христюхин (roboslone)
`manage.py` is ABSOLUTELY NOT a `setup.py`. It doesn't really matter how you 
think.

`setup.py` is used for package managing while `manage.py` manages Django.

> On 8 Sep 2017, at 09:17, callsamle...@gmail.com wrote:
> 
> hi,
> yes, django has `setup.py`, that's `manage.py`,LOL
> 
> depend on how you think. 
> if you code is like `tools`, that use `setup.py`
> like your code is a `calculator`.
> if not, that's many way to setup, like Fabric, Ansible,etc.
> think this two word, `functional` and  `system/project`
> 
> for python, see PEP-400
> 
> "Projects" are software components that are made available for integration. 
> Projects include Python libraries, frameworks, scripts, plugins, 
> applications, collections of data or other resources, and various 
> combinations thereof. Public Python projects are typically registered on the 
> Python Package Index .
> 
> 
> 
> 
> On Thursday, September 7, 2017 at 4:29:13 AM UTC+8, Scot Hacker wrote:
> I am accustomed to seeing pip-installable dependencies of a Django project 
> each have their own `setup.py`. I am not accustomed to seeing a Django 
> project *itself* have its own `setup.py`, but I am now working with a project 
> that does just that. The setup does not move the Django project itself to 
> `site-packages`, but does add the whole project to the Python path.
> 
> This approach is not documented or recommended by Django itself, and I can't 
> find many references to it on the web. The stated advantages are that it lets 
> you use `manage.py` from any dir (not just the top-level) and that it 
> simplifies the writing of fab commands. I am wary of it because it (slightly) 
> complicates setup, is unusual, confusing to new developers, etc. 
> 
> Does anyone have experience with this approach? In 10 years of Django 
> development, I've never encountered this on a project, and it feels a bit... 
> strange to me. But would love to hear from anyone who has had positive or 
> negative experiences doing this. 
> 
> Thanks for any feedback,
> Scot
> 
> 
> -- 
> 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/940b4795-dfd5-44c6-8766-72f2e2471a35%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/6884AC13-6E91-441F-837C-1508AEA9B422%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Retrieving objects created in trasaction

2017-09-11 Thread Александр Христюхин (roboslone)
Thanks to everyone and sorry for the delay, I've missed your responses.

I've tried to use transaction.on_commit, it didn't work for me. For some 
strange reason Django thought the code wasn't running in a transaction.

I'm using Django 1.10 and PostgreSQL 9.6. Bar uses standard manager and yes, I 
can fetch objects after transaction has finished.

I ended up with local storage for newly created objects. So I query database 
for existing objects I've added to relation and if original pk_set is bigger I 
also query that local storage. That fixed the problem for me, but it's not 
exactly a good solution.

> On 24 Aug 2017, at 18:47, Daniel Hepper  wrote:
> 
> I cannot reproduce this behavior with Django 1.11 and PostgreSQL 9.6. What 
> database are you using?
> 
> Does your Bar model maybe use non-standard Manager? Can you actually fetch to 
> objects after the transaction has finished?
> 
> 
> On Wednesday, August 16, 2017 at 8:29:09 PM UTC+2, Александр Христюхин wrote:
> Hi, 
> 
> I have some function (fetcher) that runs in transaction (it has to) and it 
> creates a bunch if new objects that are written to database after transaction 
> is commited. Those objects are added to a many-to-many relation. And on that 
> relation change a signal is fired and handled by my signal handler, that 
> collects objects from relation and writes them into some cache. 
> 
> The problem is that during signal handling newly created objects do have PKs, 
> but are not in database yet. So signal_handler in code below always gets 
> empty queryset. 
> 
> 
> def fetcher(): 
> with transaction.atomic(): 
> foo = Foo.objects.create(...) 
> foo.bars.add( 
> Bar.objects.create(...), 
> Bar.objects.create(...), 
> Bar.objects.create(...), 
> ... 
> ) 
> 
> @receiver(m2m_changed, sender=Foo.bars.through) 
> def signal_handler(pk_set=None, **kwargs): 
> # signal_handler is being called inside of a transaction block 
> Bar.objects.filter(pk__in=pk_set)  # <-- returns empty QuerySet! 
> 
> 
> Is there a way to delay signal handling until transaction is committed or to 
> get newly created objects by PKs? 
> 
> 
> -- 
> 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/e9c89d82-e92b-4de0-bf6a-52f4e505d6fc%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/FE630650-F7DA-4183-97E7-774004D30162%40gmail.com.
For more options, visit https://groups.google.com/d/optout.