Re: Seems like a geodjango bug with multiple databases

2015-02-20 Thread Jani Tiainen
On Wed, 18 Feb 2015 06:45:15 -0800 (PST)
Luan Nguyen  wrote:

> I'm using geodjango and multiple databases, and experiencing a quite weird 
> situation, I guess it's a kind of bug but not absolutely sure since I'm 
> pretty new to Django.
> 
> Here is how to reproduce the problem:
> - Set up another database besides default:
> DATABASES = {
> 'default': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> ,
> 'NAME' : 'issue1',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> 'another': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> ,
> 'NAME' : 'issue2',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> }
> 
> And two models:
> from django.db import models as default_models
> from django.contrib.gis.db import models
> # Create your models here.
> class Hotel(models.Model):
> hotel_name = models.CharField(max_length=255)
> objects = models.GeoManager()
> 
> class Room(models.Model):
> room_num = models.IntegerField()
> hotel = models.ForeignKey(Hotel, null=True, blank=True)

You don't have GeoManager on Room model? It's required to be default (first) 
manager if you do queries that even relate to geo-enabled model.

https://docs.djangoproject.com/en/1.7/ref/contrib/gis/model-api/#geomanager

And there reads: "It should also be noted that GeoManager is required even if 
the model does not have a geographic field itself, e.g., in the case of a 
ForeignKey relation to a model with a geographic field."
 
> Add data into issue2 database (leave issue1 blank), then go into shell:
> >>>h = Hotel.objects.using('another').all()[0]
> >>> h.id
> 9
> >>>h.room_set.all()[0].id  #=> room id 
> 10 links to hotel id 9
> 10
> >>>r = Room.objects.using('another').get(pk=10)
> >>>r.hotel
> Traceback (most recent call last):
> File "", line 1, in 
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py
>  
> ",
>  
> line 572, in __get__
> rel_obj = qs.get()
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py
>  
> ",
>  
> line 357, in get
> self.model._meta.object_name)
> multi.models.DoesNotExist: Hotel matching query does not exist.
> 
> The thing is, if I create a hotel record on database issue1 with id of 9 
> then the last command works, so I guess it tried to look up in default 
> database. This doesn't have any problems if I use default manager for 
> Hotel, so I guess it's a bug?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/daa291e8-bf87-422a-a8fc-b23038e94268%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
Jani Tiainen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150220101236.1c721b6e%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


How to filter by Group_BY ?

2015-02-20 Thread SHINTO PETER
How to filter by Group_BY ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/260e065a-fcae-433c-a0fe-6df25a8718b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to filter by Group_BY ?

2015-02-20 Thread SHINTO PETER
How to filter by Group_BY ?

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


Re: Handling FormSet client side with javascript

2015-02-20 Thread aRkadeFR

Hello,

Yes {{ formset.media }} works. But the problem is
wider. How to include/manage the javascript around
the formset?

I want to add a media file (js) only on formset and not
inside a form contained in a formset.

Let me know if I'm not clear in my first message (it's
a bit long to read, I know =D).

Thanks

On 02/19/2015 07:28 PM, Collin Anderson wrote:

Hi,

Sorry for the late reply. Does simply using {{ formset.media }} work?

Collin

On Friday, February 13, 2015 at 11:02:31 AM UTC-5, aRkadeFR wrote:

Hello everyone,

I'm using FormSet in order to add multiple object at once on
a view. To have a more user friendly approach, I created a
'my.formset.js' file and I need to include a 'jquery.formset.js' lib
to add/remove row of the formset (client side) and edit the
formset management information.

My idea to resolve this problem was to include these two
javascript media file everytime I'm using a formset.

A bit like every media js file for widgets :)

So my first attempt was something like that:
```
class BaseFormSet(BaseInlineFormSet):
 class Media:
 js = ("my.formset.js", "jquery.formset.js", )
```

but this doesnt render these js files with formset.media.render_js().

My second attempt was:
```
formset.media.add_js( ["my.formset.js", "jquery.formset.js", ])
```

My last attempt:
```
form = formset.forms[0]

formset.forms[0].fields[form.fields.keys()[0]].media.add_js(["my.formset.js",

"jquery.formset.js", ])
```

Still not working cause the .media._js is regenerating the media js
files.

The only solution so far I have, provided by @tbaxter, is to
include all my js files in all my application, and initialize/use
the formset/widgets javascript only on certain condition.

I don't like the idea of including my js application wide. It's
gonna overload all my pages for nothing (my js files are
completely standalone) when there is no FormSet.

Can I have your tought on this probleme, and what solution
you have in mind?

Thank you,



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


Re: How to filter by Group_BY ?

2015-02-20 Thread James Schneider
Without more detail, a good place to start would be with the ORM
aggregation documentation:

https://docs.djangoproject.com/en/1.7/topics/db/aggregation/#filter-and-exclude

I would advise reading the whole page, though. Note that the
placement/order of filters are much more significant than with normal ORM
queries when using aggregation, but the section I linked to should explain
that.

-James

On Fri, Feb 20, 2015 at 1:08 AM, SHINTO PETER  wrote:

> How to filter by Group_BY ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3b251918-cc2c-4602-b810-a24485f05a78%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUW7MZ1xhnFXGjkAaHrO%2BeosnV_khgS%3Dq%3DCiUmu_KoHxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: extracting data from three tables

2015-02-20 Thread James Schneider
I would suggest reading this:

https://docs.djangoproject.com/en/1.7/topics/db/queries/#lookups-that-span-relationships

and see if that helps out. You can span relationships (in this case, using
FK's) using the double-underscore notation.

I would also check out using select_related() if you would like to keep the
number of queries to a minimum. The description of how to use
select_related() also includes an example that spans 3 models, which I
think is what you are looking for (although you didn't specify whether one
model contains the other two FK's, or if you are jumping through one model
via an FK to another model FK):

https://docs.djangoproject.com/en/1.7/ref/models/querysets/#select-related

-James


On Thu, Feb 19, 2015 at 9:44 PM, sum abiut  wrote:

> Hi,
> I have three models that i want to extract data from them. The models are
> join using foreign key. i am not sure how to do that in django. Can someone
> please point me to the right path.
>
> Cheers
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPCf-y7vVA995WHrStKebFOBLQXx9gnu%2B-c0TwaK70uFNA-ZqA%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXXZmQKp607PO-3jtBN6O%2B5YdOCF3FbTUk8ch5m%3DTDtoA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: html response to be loaded in a div

2015-02-20 Thread João Marques
According to Django documentation I can include a crsf token to prevent 
malicious acts, but it is not necessary right? Or am I getting this wrong? 
Because right now I wouldn't mind skipping the crsf token step for a little 
while I manage to get the rest of the essential things to work.

sexta-feira, 20 de Fevereiro de 2015 às 00:08:32 UTC, Vijay Khemlani 
escreveu:
>
> There's no "range" in django templates, you just use
>
> {% for elem in sols %}
>
> Regarding making the request using POST, are you sure you're not having a 
> proble with CSRF?
>
> https://docs.djangoproject.com/en/1.7/ref/contrib/csrf/
>
> It has a section for AJAX requests
>
>
>
> On Thu, Feb 19, 2015 at 7:44 PM, João Marques  > wrote:
>
>> Thank You guys for all the aswers. Your were crucial debugging this 
>> error. 
>>
>> By the way, on the GET request matter, I'm using a GET because I can't 
>> actually get POST to work I'll explain: As I execute the POST request, the 
>> url is loaded and everything runs fine except that the code on the view 
>> doesn't return nothing. Thats is the reason I have everything set uo with 
>> GET. Does anybody know if I have to enable something on my Django 
>> properties to get this to work?
>>
>> Cheers
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/76c1ef99-5082-4b26-a954-f8dde0b7262d%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bc394c9f-6614-457d-b091-b791a10c6eab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Design question: Is it really a good idea for models having “side effects”?

2015-02-20 Thread Gergely Polonkai
Hello,

I’m currently implementing a finite state machine in my application using 
Django FSM[1]. In the Usage section of the README the author said that 
“This function may contain side-effects, like updating caches, notifying 
users, etc.”

Opposing this statement, the Symfony PHP framework’s authors say that 
models should never have such side effects.

Thus, I was wondering what is the case with Django in this topic. Should I 
really do such things, like notifying users, in the model’s code?

Best,
Gergely


[1] https://github.com/kmmbvnr/django-fsm

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/69272d49-de97-40a0-9682-430f28f38663%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Admin Page

2015-02-20 Thread Tim Co
Hello,

We are trying to run a local development server for our django python app. 
We are able to connect to our localhost index and get the "It Worked!" 
Dango page. However when we try to connect to 127.0.0.1/admin/ we are 
getting an error that the server dropped the connection. Here is the log 
for the django project:

Exception happened during processing of request from ('130.191.204.231', 
62070)
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/SocketServer.py", line 593, in process_request_thread
self.finish_request(request, client_address)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
  File "/Library/Python/2.7/site-packages/Django-1.8.
dev20141212211410-py2.7.egg/django/core/servers/basehttp.py", line 101, in 
__init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/SocketServer.py", line 649, in __init__
self.handle()
  File "/Library/Python/2.7/site-packages/Django-1.8.
dev20141212211410-py2.7.egg/django/core/servers/basehttp.py", line 173, in 
handle
handler.run(self.server.get_app())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/wsgiref/handlers.py", line 92, in run
self.close()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/wsgiref/simple_server.py", line 33, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'


///
Our urls.py file

urls.py

from django.conf.urls import include, url
from django.contrib import admin

admin.autodiscover()

urlpatterns = [
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
]



///
settings.py


# Application definition

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'trainstar',
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
'django.contrib.messages.context_processors.messages'
)


ROOT_URLCONF = 'mysite.urls'

WSGI_APPLICATION = 'mysite.wsgi.application'


Please advise. I've exhausted Google/stackoverflow for possible fixes to of 
no avail. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/029488ab-06de-4f38-a61c-f5924b615a2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Real time and Django - approaches

2015-02-20 Thread Aaron Reabow
Hi.

I wanted to see what the Django community thought about realtime circa 2015.

My impression (and I could be very wrong) is that if you want real time, 
you should build your own stack up from scratch.  There are frameworks - 
like swampdragon/socketio - that promise to do the hard yards for you, but 
ultimately are either based on older versions of the underlying tech, or 
too green to be in production.

So which stack to build?  There is the gevent route which looks promising 
as it keeps it all in the python family.  (Stack would be something like - 
django/redis/gevent/gunicorn)

>From what I have read, gevent becomes opaque and throws up hard to 
understand errors.  Without a strong community behind this, debugging is 
either for the advanced, or extremely dedicated.

Another stack option is to use Node.  I quite like this, despite the 
challenges.  The stack would be django/apache +redis/socetio/node/celery. 
 I think the hardest part would be managing oauth2 between the two servers. 
 On the upside, django can do all the regular web stuff, with node handling 
realtime components.

So I have just stated my own views from what I could glean from blog posts. 
 I was interested if people had alternate understandings.

What I am building definitely does need pubsub at the least, and to be as 
near to realtime as possible would be an advantage.

many thanks,

Aaron


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


Transcode video using celery and ffmpeg in django

2015-02-20 Thread Robin Lery
I would like to transcode user uploaded videos using celery. I think first
I should upload the video, and spawn a celery task for transcoding.

Maybe something like this in the tasks.py:

subprocess.call('ffmpeg -i path/.../original path/.../output')
>

Just completed First steps with celery
,
so confused how to do so in the `views.py` and `tasks.py`. Also is it a
good solution? I would really appreciate your help and advice. Thank you.

models.py:

class Video(models.Model):
> user = models.ForeignKey(User)
> title = models.CharField(max_length=100)
> original = models.FileField(upload_to=get_upload_file_name)
> mp4_480 = models.FileField(upload_to=get_upload_file_name)
> mp4_720 = models.FileField(upload_to=get_upload_file_name)
> privacy = models.CharField(max_length=1,choices=PRIVACY,
> default='F')
> pub_date = models.DateTimeField(auto_now_add=True, auto_now=False)
>

my incomplete views.py:


@login_required
> def upload_video(request):
> if request.method == 'POST':
> form = VideoForm(request.POST, request.FILES)
> if form.is_valid():
> if form.cleaned_data:
> user = request.user
> #
> #
> # No IDEA WHAT TO DO NEXT
> #
> #
> return HttpResponseRedirect('/')
>
> else:
> form = VideoForm()
> return render(request, 'upload_video.html', {
> 'form':form
> })
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B4-nGoz%3D_qCx%2BbSnOfNFLYiufqUUES3S3T9y4GXoZiaBV9tyw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Transcode video using celery and ffmpeg in django

2015-02-20 Thread Vijay Khemlani
I would do something like this

video = Video()
video.original = form.cleaned_data['video']  # Assuming the form field is
"video"
video.user = user
video.title = form.cleaned_data['title']  # Assuming the form field is
"title"
video.save()  # You might need to make the mp4_480 and mp4_720
fields "nullable" on the model
yourapp.tasks.transcode_video.delay(video)   # Assuming the task is the
"transcode_video" function.

return HttpResponseRedirect('/')

Then


On Fri, Feb 20, 2015 at 10:04 AM, Robin Lery  wrote:

> I would like to transcode user uploaded videos using celery. I think first
> I should upload the video, and spawn a celery task for transcoding.
>
> Maybe something like this in the tasks.py:
>
> subprocess.call('ffmpeg -i path/.../original path/.../output')
>>
>
> Just completed First steps with celery
> ,
> so confused how to do so in the `views.py` and `tasks.py`. Also is it a
> good solution? I would really appreciate your help and advice. Thank you.
>
> models.py:
>
> class Video(models.Model):
>> user = models.ForeignKey(User)
>> title = models.CharField(max_length=100)
>> original = models.FileField(upload_to=get_upload_file_name)
>> mp4_480 = models.FileField(upload_to=get_upload_file_name)
>> mp4_720 = models.FileField(upload_to=get_upload_file_name)
>> privacy = models.CharField(max_length=1,choices=PRIVACY,
>> default='F')
>> pub_date = models.DateTimeField(auto_now_add=True, auto_now=False)
>>
>
> my incomplete views.py:
>
>
> @login_required
>> def upload_video(request):
>> if request.method == 'POST':
>> form = VideoForm(request.POST, request.FILES)
>> if form.is_valid():
>> if form.cleaned_data:
>> user = request.user
>> #
>> #
>> # No IDEA WHAT TO DO NEXT
>> #
>> #
>> return HttpResponseRedirect('/')
>>
>> else:
>> form = VideoForm()
>> return render(request, 'upload_video.html', {
>> 'form':form
>> })
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2B4-nGoz%3D_qCx%2BbSnOfNFLYiufqUUES3S3T9y4GXoZiaBV9tyw%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2ZBh7AX3h-vkY9qShnzWzfiRPZ-%2B%2B5KPJF06o7cZ-o4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Transcode video using celery and ffmpeg in django

2015-02-20 Thread Vijay Khemlani
Then in your task function you can get the file from the video model
instance, trascode it, and store it in the corresponding fields of the
object (mp4_480, mp4_720)

On Fri, Feb 20, 2015 at 10:18 AM, Vijay Khemlani  wrote:

> I would do something like this
>
> video = Video()
> video.original = form.cleaned_data['video']  # Assuming the form field is
> "video"
> video.user = user
> video.title = form.cleaned_data['title']  # Assuming the form field is
> "title"
> video.save()  # You might need to make the mp4_480 and mp4_720
> fields "nullable" on the model
> yourapp.tasks.transcode_video.delay(video)   # Assuming the task is the
> "transcode_video" function.
>
> return HttpResponseRedirect('/')
>
> Then
>
>
> On Fri, Feb 20, 2015 at 10:04 AM, Robin Lery  wrote:
>
>> I would like to transcode user uploaded videos using celery. I think
>> first I should upload the video, and spawn a celery task for transcoding.
>>
>> Maybe something like this in the tasks.py:
>>
>> subprocess.call('ffmpeg -i path/.../original path/.../output')
>>>
>>
>> Just completed First steps with celery
>> ,
>> so confused how to do so in the `views.py` and `tasks.py`. Also is it a
>> good solution? I would really appreciate your help and advice. Thank you.
>>
>> models.py:
>>
>> class Video(models.Model):
>>> user = models.ForeignKey(User)
>>> title = models.CharField(max_length=100)
>>> original = models.FileField(upload_to=get_upload_file_name)
>>> mp4_480 = models.FileField(upload_to=get_upload_file_name)
>>> mp4_720 = models.FileField(upload_to=get_upload_file_name)
>>> privacy = models.CharField(max_length=1,choices=PRIVACY,
>>> default='F')
>>> pub_date = models.DateTimeField(auto_now_add=True,
>>> auto_now=False)
>>>
>>
>> my incomplete views.py:
>>
>>
>> @login_required
>>> def upload_video(request):
>>> if request.method == 'POST':
>>> form = VideoForm(request.POST, request.FILES)
>>> if form.is_valid():
>>> if form.cleaned_data:
>>> user = request.user
>>> #
>>> #
>>> # No IDEA WHAT TO DO NEXT
>>> #
>>> #
>>> return HttpResponseRedirect('/')
>>>
>>> else:
>>> form = VideoForm()
>>> return render(request, 'upload_video.html', {
>>> 'form':form
>>> })
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CA%2B4-nGoz%3D_qCx%2BbSnOfNFLYiufqUUES3S3T9y4GXoZiaBV9tyw%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei0fjxCurSdVufpqj5hpzCGadMq_tQky_POGoXm%2B6GtSfA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: html response to be loaded in a div

2015-02-20 Thread Vijay Khemlani
Is is required by default.

I would recommend including the csrf token in your ajax request. If you
still want to prevent the CSRF verification in your view then you can use
the "csrf_exempt" decorator

https://docs.djangoproject.com/en/1.7/ref/contrib/csrf/#utilities

On Fri, Feb 20, 2015 at 9:05 AM, João Marques 
wrote:

> According to Django documentation I can include a crsf token to prevent
> malicious acts, but it is not necessary right? Or am I getting this wrong?
> Because right now I wouldn't mind skipping the crsf token step for a little
> while I manage to get the rest of the essential things to work.
>
> sexta-feira, 20 de Fevereiro de 2015 às 00:08:32 UTC, Vijay Khemlani
> escreveu:
>>
>> There's no "range" in django templates, you just use
>>
>> {% for elem in sols %}
>>
>> Regarding making the request using POST, are you sure you're not having a
>> proble with CSRF?
>>
>> https://docs.djangoproject.com/en/1.7/ref/contrib/csrf/
>>
>> It has a section for AJAX requests
>>
>>
>>
>> On Thu, Feb 19, 2015 at 7:44 PM, João Marques 
>> wrote:
>>
>>> Thank You guys for all the aswers. Your were crucial debugging this
>>> error.
>>>
>>> By the way, on the GET request matter, I'm using a GET because I can't
>>> actually get POST to work I'll explain: As I execute the POST request, the
>>> url is loaded and everything runs fine except that the code on the view
>>> doesn't return nothing. Thats is the reason I have everything set uo with
>>> GET. Does anybody know if I have to enable something on my Django
>>> properties to get this to work?
>>>
>>> Cheers
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/76c1ef99-5082-4b26-a954-f8dde0b7262d%
>>> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/bc394c9f-6614-457d-b091-b791a10c6eab%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei1ScoHtevoWyVBBxTaFqkUwrigo37FaLtTQM7xOAQTcxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Design question: Is it really a good idea for models having “side effects”?

2015-02-20 Thread Vijay Khemlani
I'm not sure if there's an official stance on that, but I believe that
since Django is a "MVT" framework, that kind of logic does not seem to be
appropiate neither for templates nor views, so models seem like the logical
choice.

That way you can also make sure that the side-effect that you want to be
called (cache update when changing a model, for example) are always
executed when calling the model's method.

On Fri, Feb 20, 2015 at 5:23 AM, Gergely Polonkai 
wrote:

> Hello,
>
> I’m currently implementing a finite state machine in my application using
> Django FSM[1]. In the Usage section of the README the author said that
> “This function may contain side-effects, like updating caches, notifying
> users, etc.”
>
> Opposing this statement, the Symfony PHP framework’s authors say that
> models should never have such side effects.
>
> Thus, I was wondering what is the case with Django in this topic. Should I
> really do such things, like notifying users, in the model’s code?
>
> Best,
> Gergely
>
>
> [1] https://github.com/kmmbvnr/django-fsm
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/69272d49-de97-40a0-9682-430f28f38663%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei0q2-i2JQpe9zTS90PxCt%2BRY7%2BVRQLFRZPg21Muy581zA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


django

2015-02-20 Thread ravikiran
how to dump mysql database table  in our django project

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


Re: Transcode video using celery and ffmpeg in django

2015-02-20 Thread Robin Lery
So mp4_480 and mp4_720 should be blank=True and null=True. And then pass
the video instance object to the delay() ???

And also, could you please show me how to write the tasks.py, so that I can
use ffmpeg code (subprocess.call('ffmpeg -i path/.../original
path/.../mp4_720') to transcode.

Thank you.

On Fri, Feb 20, 2015 at 6:49 PM, Vijay Khemlani  wrote:

> Then in your task function you can get the file from the video model
> instance, trascode it, and store it in the corresponding fields of the
> object (mp4_480, mp4_720)
>
> On Fri, Feb 20, 2015 at 10:18 AM, Vijay Khemlani 
> wrote:
>
>> I would do something like this
>>
>> video = Video()
>> video.original = form.cleaned_data['video']  # Assuming the form field is
>> "video"
>> video.user = user
>> video.title = form.cleaned_data['title']  # Assuming the form field is
>> "title"
>> video.save()  # You might need to make the mp4_480 and
>> mp4_720 fields "nullable" on the model
>> yourapp.tasks.transcode_video.delay(video)   # Assuming the task is the
>> "transcode_video" function.
>>
>> return HttpResponseRedirect('/')
>>
>> Then
>>
>>
>> On Fri, Feb 20, 2015 at 10:04 AM, Robin Lery  wrote:
>>
>>> I would like to transcode user uploaded videos using celery. I think
>>> first I should upload the video, and spawn a celery task for transcoding.
>>>
>>> Maybe something like this in the tasks.py:
>>>
>>> subprocess.call('ffmpeg -i path/.../original path/.../output')

>>>
>>> Just completed First steps with celery
>>> ,
>>> so confused how to do so in the `views.py` and `tasks.py`. Also is it a
>>> good solution? I would really appreciate your help and advice. Thank you.
>>>
>>> models.py:
>>>
>>> class Video(models.Model):
 user = models.ForeignKey(User)
 title = models.CharField(max_length=100)
 original = models.FileField(upload_to=get_upload_file_name)
 mp4_480 = models.FileField(upload_to=get_upload_file_name)
 mp4_720 = models.FileField(upload_to=get_upload_file_name)
 privacy = models.CharField(max_length=1,choices=PRIVACY,
 default='F')
 pub_date = models.DateTimeField(auto_now_add=True,
 auto_now=False)

>>>
>>> my incomplete views.py:
>>>
>>>
>>> @login_required
 def upload_video(request):
 if request.method == 'POST':
 form = VideoForm(request.POST, request.FILES)
 if form.is_valid():
 if form.cleaned_data:
 user = request.user
 #
 #
 # No IDEA WHAT TO DO NEXT
 #
 #
 return HttpResponseRedirect('/')

 else:
 form = VideoForm()
 return render(request, 'upload_video.html', {
 'form':form
 })

>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CA%2B4-nGoz%3D_qCx%2BbSnOfNFLYiufqUUES3S3T9y4GXoZiaBV9tyw%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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALn3ei0fjxCurSdVufpqj5hpzCGadMq_tQky_POGoXm%2B6GtSfA%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 http://groups.google.com/group/django-users.
To view this discussion

Re: django

2015-02-20 Thread François Schiettecatte
Two options:


https://docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-dumpdata

http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html

François

> On Feb 20, 2015, at 8:49 AM, raviki...@inndata.in wrote:
> 
> how to dump mysql database table  in our django project
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/bdbbfd6c-a0f6-4465-a972-62a95abea19c%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0D26673A-0433-4674-BACD-89D1F8B9927D%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can migrated apps depend on unmigrated apps?

2015-02-20 Thread Carsten Fuchs

Hi Collin,

thank you very much for your reply!

Am 19.02.2015 um 19:35 schrieb Collin Anderson:

If you haven't yet, you could try generating migrations for the
unmigrated app, and reference them using MIGRATION_MODULES.


I've tried this, and my real problem is that I have problems with this 
step, i.e. applying the initial migrations to the unmigrated app: Please 
see  
for details. Any help about this would very much be appreciated!


Many thanks and best regards,
Carsten

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


Re: Migrating to initial migration: "ORA-00955: name is already used by an existing object"

2015-02-20 Thread Carsten Fuchs

Hi all,

another update:

My developer system's local Oracle database content was created from 
importing a dump of a production database. On Monday night I'll have a 
chance to safely try to create and apply the initial migrations on the 
production database, rather than my dev system. Maybe some subtle issues 
from the export-import cycle are responsible for the ORA-00955 on my 
developer machine, and so I'll just give it a try.


Also, I suspect that if not for the ORA-00955 error, the initial 
migrations for this app would turn out to be "FAKE" applied -- just as 
was the case with other previously unmigrated apps that I successfully 
added initial migrations to after the upgrade to Django 1.7.


However, I don't quite dare yet running

./manage.py migrate --fake

explicitly, mostly because I'm not sure how to undo or recover if there 
are subsequent problems, or if there is a way to re-try, etc.


(On the other hand, if this worked and there were errors only much 
later, they would probably occur after individual, small changes, thus 
much smaller migration files, and thus (I recon) much easier to pin down 
as from the big stack trace about the ORA-00955...)


Any help or hint would still be very much appreciated.

Best regards,
Carsten

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


Re: Real time and Django - approaches

2015-02-20 Thread Carlos Aguilar
I build something related with realtime using gevent-socketio more than 1
year ago and works really well.

Best Regards

On Fri, Feb 20, 2015 at 6:37 AM, Aaron Reabow  wrote:

> Hi.
>
> I wanted to see what the Django community thought about realtime circa
> 2015.
>
> My impression (and I could be very wrong) is that if you want real time,
> you should build your own stack up from scratch.  There are frameworks -
> like swampdragon/socketio - that promise to do the hard yards for you, but
> ultimately are either based on older versions of the underlying tech, or
> too green to be in production.
>
> So which stack to build?  There is the gevent route which looks promising
> as it keeps it all in the python family.  (Stack would be something like -
> django/redis/gevent/gunicorn)
>
> From what I have read, gevent becomes opaque and throws up hard to
> understand errors.  Without a strong community behind this, debugging is
> either for the advanced, or extremely dedicated.
>
> Another stack option is to use Node.  I quite like this, despite the
> challenges.  The stack would be django/apache +redis/socetio/node/celery.
> I think the hardest part would be managing oauth2 between the two servers.
> On the upside, django can do all the regular web stuff, with node handling
> realtime components.
>
> So I have just stated my own views from what I could glean from blog
> posts.  I was interested if people had alternate understandings.
>
> What I am building definitely does need pubsub at the least, and to be as
> near to realtime as possible would be an advantage.
>
> many thanks,
>
> Aaron
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a5923d8e-54a4-46ab-8df0-fdbb25ad076b%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Carlos Aguilar
Consultor Hardware y Software
DWD&Solutions
http://www.dwdandsolutions.com
http://www.houseofsysadmin.com
Cel: +50378735118
USA: (301) 337-8541

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN-g%3Dg%3DP2_k8aK7raPRUHf%2B8JKaahp%2B9kAyF1NKdc%2B1tax8g4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Transcode video using celery and ffmpeg in django

2015-02-20 Thread Vijay Khemlani
The task is just a function, you finished the tutorial, it's the same thing

@app.task
def trascode(video):
subprocess.call('ffmpeg -i path/.../original path/.../mp4_720') #
Change the path to the one given by video.original
video.mp4_480 = # Something
video.mp4_720 = # Something else
video.save()

On Fri, Feb 20, 2015 at 11:18 AM, Robin Lery  wrote:

> So mp4_480 and mp4_720 should be blank=True and null=True. And then pass
> the video instance object to the delay() ???
>
> And also, could you please show me how to write the tasks.py, so that I
> can use ffmpeg code (subprocess.call('ffmpeg -i path/.../original
> path/.../mp4_720') to transcode.
>
> Thank you.
>
> On Fri, Feb 20, 2015 at 6:49 PM, Vijay Khemlani 
> wrote:
>
>> Then in your task function you can get the file from the video model
>> instance, trascode it, and store it in the corresponding fields of the
>> object (mp4_480, mp4_720)
>>
>> On Fri, Feb 20, 2015 at 10:18 AM, Vijay Khemlani 
>> wrote:
>>
>>> I would do something like this
>>>
>>> video = Video()
>>> video.original = form.cleaned_data['video']  # Assuming the form field
>>> is "video"
>>> video.user = user
>>> video.title = form.cleaned_data['title']  # Assuming the form field is
>>> "title"
>>> video.save()  # You might need to make the mp4_480 and
>>> mp4_720 fields "nullable" on the model
>>> yourapp.tasks.transcode_video.delay(video)   # Assuming the task is the
>>> "transcode_video" function.
>>>
>>> return HttpResponseRedirect('/')
>>>
>>> Then
>>>
>>>
>>> On Fri, Feb 20, 2015 at 10:04 AM, Robin Lery 
>>> wrote:
>>>
 I would like to transcode user uploaded videos using celery. I think
 first I should upload the video, and spawn a celery task for transcoding.

 Maybe something like this in the tasks.py:

 subprocess.call('ffmpeg -i path/.../original path/.../output')
>

 Just completed First steps with celery
 ,
 so confused how to do so in the `views.py` and `tasks.py`. Also is it a
 good solution? I would really appreciate your help and advice. Thank you.

 models.py:

 class Video(models.Model):
> user = models.ForeignKey(User)
> title = models.CharField(max_length=100)
> original = models.FileField(upload_to=get_upload_file_name)
> mp4_480 = models.FileField(upload_to=get_upload_file_name)
> mp4_720 = models.FileField(upload_to=get_upload_file_name)
> privacy = models.CharField(max_length=1,choices=PRIVACY,
> default='F')
> pub_date = models.DateTimeField(auto_now_add=True,
> auto_now=False)
>

 my incomplete views.py:


 @login_required
> def upload_video(request):
> if request.method == 'POST':
> form = VideoForm(request.POST, request.FILES)
> if form.is_valid():
> if form.cleaned_data:
> user = request.user
> #
> #
> # No IDEA WHAT TO DO NEXT
> #
> #
> return HttpResponseRedirect('/')
>
> else:
> form = VideoForm()
> return render(request, 'upload_video.html', {
> 'form':form
> })
>
  --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users+unsubscr...@googlegroups.com.
 To post to this group, send email to django-users@googlegroups.com.
 Visit this group at http://groups.google.com/group/django-users.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CA%2B4-nGoz%3D_qCx%2BbSnOfNFLYiufqUUES3S3T9y4GXoZiaBV9tyw%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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CALn3ei0fjxCurSdVufpqj5hpzCGadMq_tQky_POGoXm%2B6GtSfA%40mail.gmail.com
>> 

Deploying Django, nginx , gunicorn, postgresql

2015-02-20 Thread Tony Kyriakidis
Hello, 

It's been a week now since the day i started trying to deploy a test blog 
application on digital ocean.
I tried everthing and if you go to the IP: http://188.166.62.146 you get a 
Welcome to Nginx page.
when i go to http://188.166.62.146:8001 i get a (400 Bad Request) error.

Here on Stack overflow i posted every detail. Please take a look at it.

http://stackoverflow.com/questions/28629112/502-bad-gateway-django-nginx-gunicorn-postgresql-virtualenv?noredirect=1#comment45560477_28629112


Thank in advance.

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


Re: html response to be loaded in a div

2015-02-20 Thread James Schneider
In most cases, including the CSRF token in AJAX requests is trivial, and
processing the token is handled automatically by Django. I would recommend
spending a few minutes to implement the CSRF protection in your code of you
plan to ever move to production. It is easy enough and pays good dividends
later.

-James
On Feb 20, 2015 5:23 AM, "Vijay Khemlani"  wrote:

> Is is required by default.
>
> I would recommend including the csrf token in your ajax request. If you
> still want to prevent the CSRF verification in your view then you can use
> the "csrf_exempt" decorator
>
> https://docs.djangoproject.com/en/1.7/ref/contrib/csrf/#utilities
>
> On Fri, Feb 20, 2015 at 9:05 AM, João Marques 
> wrote:
>
>> According to Django documentation I can include a crsf token to prevent
>> malicious acts, but it is not necessary right? Or am I getting this wrong?
>> Because right now I wouldn't mind skipping the crsf token step for a little
>> while I manage to get the rest of the essential things to work.
>>
>> sexta-feira, 20 de Fevereiro de 2015 às 00:08:32 UTC, Vijay Khemlani
>> escreveu:
>>>
>>> There's no "range" in django templates, you just use
>>>
>>> {% for elem in sols %}
>>>
>>> Regarding making the request using POST, are you sure you're not having
>>> a proble with CSRF?
>>>
>>> https://docs.djangoproject.com/en/1.7/ref/contrib/csrf/
>>>
>>> It has a section for AJAX requests
>>>
>>>
>>>
>>> On Thu, Feb 19, 2015 at 7:44 PM, João Marques 
>>> wrote:
>>>
 Thank You guys for all the aswers. Your were crucial debugging this
 error.

 By the way, on the GET request matter, I'm using a GET because I can't
 actually get POST to work I'll explain: As I execute the POST request, the
 url is loaded and everything runs fine except that the code on the view
 doesn't return nothing. Thats is the reason I have everything set uo with
 GET. Does anybody know if I have to enable something on my Django
 properties to get this to work?

 Cheers

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users...@googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.
 Visit this group at http://groups.google.com/group/django-users.
 To view this discussion on the web visit https://groups.google.com/d/
 msgid/django-users/76c1ef99-5082-4b26-a954-f8dde0b7262d%
 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/bc394c9f-6614-457d-b091-b791a10c6eab%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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALn3ei1ScoHtevoWyVBBxTaFqkUwrigo37FaLtTQM7xOAQTcxQ%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXeCNeVMoA9Mu-JnBjx18zSs6ULQT06y-vfMPyqN-G2fA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


OperationalError: ORA-03114: not connected to ORACLE.

2015-02-20 Thread alexandrosstylianou88
Hi, 

I migrated my project to a new infrastructure but i kept the same versions 
Apache 2.2 + mod_wsgi + python 2.6.1 + Django 1.2.1  

I am trying to run my project and i am getting the below exception that 
seems to be from Django and i need help pin pointing the exact cause, 
because i think that the actual exception is never caught and returned to 
the log and all i am getting is the OperationalError: ORA-03114: not 
connected to ORACLE. I checked the Oracle DB and i can connect to it. 

[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] mod_wsgi 
(pid=27565): Exception occurred processing WSGI script 
'/opt/wgt_proxy/wgtproxyProj/wgtproxy/apache/django.wsgi'.
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] Traceback (most 
recent call last):
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File 
"/opt/wgt_proxy/wgtproxyProj/wgtproxy/apache/django.wsgi", line 50, in 
__call__
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] return 
self.__application(environ, _start_response)
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File 
"/opt/webtier/python_64/lib/python2.6/site-packages/django/core/handlers/wsgi.py",
 
line 248, in __call__
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] 
signals.request_finished.send(sender=self.__class__)
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File 
"/opt/webtier/python_64/lib/python2.6/site-packages/django/dispatch/dispatcher.py",
 
line 162, in send
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] response = 
receiver(signal=self, sender=sender, **named)
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File 
"/opt/webtier/python_64/lib/python2.6/site-packages/django/db/__init__.py", 
line 82, in close_connection
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] conn.close()
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File 
"/opt/webtier/python_64/lib/python2.6/site-packages/django/db/backends/__init__.py",
 
line 70, in close
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] 
self.connection.close()
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] OperationalError: 
ORA-03114: not connected to ORACLE
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] 
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] Request Failed for 
: /wgtproxy/admin/, Resp Code : [500]

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/88d2de85-f330-4c35-9818-9c19addcc1cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


OperationalError: ORA-03114: not connected to ORACLE

2015-02-20 Thread alexandrosstylianou88
Hi, 

I have migrated my project to a new installation of Apache + mod_wsgi 3.2.1 
+ python 2.6.1 + Django 1.2.1, i kept the same versions just to be sure 
that i do not have any problems with my project. 

I am trying to run the project and i am getting this Oracle exception... 

The DB is fine because i can connect to it using the Oracle Client 
installed on the machine the Apache + mod_wsgi 3.2.1 + python 2.6.1 + 
Django 1.2.1 is installed.


[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] mod_wsgi 
(pid=27565): Exception occurred processing WSGI script 
'/opt/wgt_proxy/wgtproxyProj/wgtproxy/apache/django.wsgi'.
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] Traceback (most 
recent call last):
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File 
"/opt/wgt_proxy/wgtproxyProj/wgtproxy/apache/django.wsgi", line 50, in 
__call__
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] return 
self.__application(environ, _start_response)
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File 
"/opt/webtier/python_64/lib/python2.6/site-packages/django/core/handlers/wsgi.py",
 
line 248, in __call__
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] 
signals.request_finished.send(sender=self.__class__)
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File 
"/opt/webtier/python_64/lib/python2.6/site-packages/django/dispatch/dispatcher.py",
 
line 162, in send
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] response = 
receiver(signal=self, sender=sender, **named)
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File 
"/opt/webtier/python_64/lib/python2.6/site-packages/django/db/__init__.py", 
line 82, in close_connection
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] conn.close()
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File 
"/opt/webtier/python_64/lib/python2.6/site-packages/django/db/backends/__init__.py",
 
line 70, in close
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] 
self.connection.close()
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] OperationalError: 
ORA-03114: not connected to ORACLE
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] 
[Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] Request Failed for 
: /wgtproxy/admin/, Resp Code : [500]



I need help debugging this it seems that the problem is coming from Django, 
but i think the actual issue is hidden probably some exception that is not 
returned to the logs and the only thing i get is "OperationalError: 
ORA-03114: not connected to ORACLE"

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


Django 1.7 migrate for postgres fails: Charfield to ForeignKey

2015-02-20 Thread Martin Kapfhammer
First I created a CharField:
 ('currency', models.CharField(max_length=30)),

In a later migration I changed it to a foreign key field:

field=models.ForeignKey(to='web.Currency'),

It worked on a local MySql instance, but not on Postgres on Heroku:
django.db.utils.ProgrammingError: column "currency_id" cannot be cast 
automatically to type integer
HINT:  Specify a USING expression to perform the conversion.

If I do the following manually, I can continue:

alter table web_financialdata drop column currency;
alter table web_financialdata add column currency integer;

Should I add this via RunSQL between the migrations. If so, how? Or is 
there a better way?

Thanks,
Martin





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


Re: OperationalError: ORA-03114: not connected to ORACLE.

2015-02-20 Thread Andreas Kuhne
2015-02-20 17:18 GMT+01:00 :

> Hi,
>
> I migrated my project to a new infrastructure but i kept the same versions
> Apache 2.2 + mod_wsgi + python 2.6.1 + Django 1.2.1
>
> I am trying to run my project and i am getting the below exception that
> seems to be from Django and i need help pin pointing the exact cause,
> because i think that the actual exception is never caught and returned to
> the log and all i am getting is the OperationalError: ORA-03114: not
> connected to ORACLE. I checked the Oracle DB and i can connect to it.
>
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] mod_wsgi
> (pid=27565): Exception occurred processing WSGI script
> '/opt/wgt_proxy/wgtproxyProj/wgtproxy/apache/django.wsgi'.
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] Traceback (most
> recent call last):
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File
> "/opt/wgt_proxy/wgtproxyProj/wgtproxy/apache/django.wsgi", line 50, in
> __call__
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] return
> self.__application(environ, _start_response)
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File
> "/opt/webtier/python_64/lib/python2.6/site-packages/django/core/handlers/wsgi.py",
> line 248, in __call__
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]
> signals.request_finished.send(sender=self.__class__)
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File
> "/opt/webtier/python_64/lib/python2.6/site-packages/django/dispatch/dispatcher.py",
> line 162, in send
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] response =
> receiver(signal=self, sender=sender, **named)
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File
> "/opt/webtier/python_64/lib/python2.6/site-packages/django/db/__init__.py",
> line 82, in close_connection
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] conn.close()
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]   File
> "/opt/webtier/python_64/lib/python2.6/site-packages/django/db/backends/__init__.py",
> line 70, in close
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]
> self.connection.close()
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] OperationalError:
> ORA-03114: not connected to ORACLE
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx]
> [Fri Feb 20 17:40:51 2015] [error] [client xx.xx.xx.xx] Request Failed for
> : /wgtproxy/admin/, Resp Code : [500]
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/88d2de85-f330-4c35-9818-9c19addcc1cf%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

What happens if you try to do "python manage.py dbshell"? Are you able to
connect to the database then?

Regards,

Andréas

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


Re: Django 1.7 migrate for postgres fails: Charfield to ForeignKey

2015-02-20 Thread George Silva
The deal here is that the model Currency has an ID, which is well, integer.

Your data that is already on that column, is char (original field). If you
are not in production, I would recommend dropping the field (comment the
code), make migrations and apply. that will remove the currency column.
Then add the new column, make migrations and apply.

On Fri, Feb 20, 2015 at 2:30 PM, Martin Kapfhammer <
mart.kapfham...@gmail.com> wrote:

> First I created a CharField:
>  ('currency', models.CharField(max_length=30)),
>
> In a later migration I changed it to a foreign key field:
>
> field=models.ForeignKey(to='web.Currency'),
>
> It worked on a local MySql instance, but not on Postgres on Heroku:
> django.db.utils.ProgrammingError: column "currency_id" cannot be cast
> automatically to type integer
> HINT:  Specify a USING expression to perform the conversion.
>
> If I do the following manually, I can continue:
>
> alter table web_financialdata drop column currency;
> alter table web_financialdata add column currency integer;
>
> Should I add this via RunSQL between the migrations. If so, how? Or is
> there a better way?
>
> Thanks,
> Martin
>
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/bdde39c8-a81a-4228-bb68-cbebb675d729%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
George R. C. Silva
SIGMA Consultoria

http://www.consultoriasigma.com.br/

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


Re: How to host django application in redhat using virtual environment?

2015-02-20 Thread Collin Anderson
Hi,

Here's a tutorial.

https://devops.profitbricks.com/tutorials/deploy-django-with-virtualenv-on-centos-7/

Collin

On Thursday, February 19, 2015 at 8:29:47 AM UTC-5, SHINTO PETER wrote:
>
> How to host django application in redhat using virtual environment?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ec55fd10-4962-4ca1-9305-2127e470511f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: matplotlib pyplot stop working

2015-02-20 Thread Collin Anderson
Hi,

The freezing could be a memory 
leak. 
http://stackoverflow.com/questions/7125710/matplotlib-errors-result-in-a-memory-leak-how-can-i-free-up-that-memory

Could the image be cached by the browser, does shift+F5 refresh it? The 
easiest way to fix it would be to use a different url/filename every time 
you generate an new image.

Collin

On Thursday, February 19, 2015 at 4:26:16 PM UTC-5, dk wrote:
>
> I am using matplotlib.pyplot to generate a plot image, put it in a temp 
> folder, 
> and then use that to populate a webpage.
>
> the problem is:
> 1) always display the same image,  I all ready deleted the image before 
> creating the new one, 
> I also set pyplot .close()  to close all my figures.
>
> 2) some times everything freeze and stop working.
>
> my suspicions is since django is constantly running keeps the figure in 
> the memory some how.   have any one got issues like this?
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d4f25a28-67f3-445e-8b46-f01b026842a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: JSON Response

2015-02-20 Thread Collin Anderson
Hi,

It sounds like you click "submit" and then get a page showing the raw json? 
That sounds like it could be a bug in your code. Either the event handler 
is not connected, or there's an error. You could try checking "Preserve 
Log" in the developer console.

Collin

On Thursday, February 19, 2015 at 5:06:59 PM UTC-5, elcaiaimar wrote:
>
> I mean in a correct form. My code doesn't work. It seems like the JS code 
> doesn't receive the jsonresponse.
> I get a page with {"status":"True","product_id":p.id} But this should be 
> read for the JS code, and if it's True show an alert saying Remove it!
>
> Is there anything wrong in my code? 
>
> El jueves, 19 de febrero de 2015, 21:49:59 (UTC+1), Vijay Khemlani 
> escribió:
>>
>> What do you mean with "in a good way"? Does your code work?
>>
>> On Thu, Feb 19, 2015 at 4:14 PM, elcaiaimar  wrote:
>>
>>> Hello,
>>>
>>> I was wondering how I can send a response JSON in a good way, because I 
>>> have the next code:
>>>
>>> if "product_id" in request.POST:
>>> try:
>>> id_producto = request.POST['product_id']
>>> p = Pozo.objects.get(pk=id_producto)
>>> mensaje = {"status":"True","product_id":p.id}
>>> p.delete() # Elinamos objeto de la base de datos
>>> return JsonResponse(mensaje)
>>> except:
>>> mensaje = {"status":"False"}
>>> return JsonResponse(mensaje)
>>>
>>> And my JS function doesn't work with this code:
>>>
>>>var options = {
>>> success:function(response)
>>> {
>>> if(response.status=="True"){
>>> alert("Eliminado!");
>>> var idProd = response.product_id;
>>> var elementos= $(nombre_tabla+' >tbody >tr').length;
>>> if(elementos==1){
>>> location.reload();
>>> }else{
>>> $('#tr'+idProd).remove();
>>> $(nombre_ventana_modal).modal('hide');
>>> }
>>> }else{
>>> alert("Hubo un error al eliminar!");
>>> $(nombre_ventana_modal).modal('hide');
>>> };
>>> }
>>> };
>>> $(nombre_formulario_modal).ajaxForm(options);
>>> });
>>>
>>> And I don't know what I can do. Does anyone have any idea?
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/2cfc6283-ee2f-4280-b086-2dc1595855c8%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6d1cd6bc-25ce-4c05-907b-312a17feda1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: JSON Response

2015-02-20 Thread Daniel Roseman
What it sounds like actually is that the OP is not preventing the default 
action of the form, so the page is being submitted normally and displaying the 
response.
-- 
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ecfbfebd-71f6-472b-adf5-3d684d7f48f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: html response to be loaded in a div

2015-02-20 Thread João Marques
Oh I see. Meanwhile I'm trying to implement the token but I cant get this 
to work, I copied the code from Django's docs and now Im getting a 
javascript error syaing that the function sameOrigin is not defined.




*Code*function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i=0; ihttp://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a9eb7352-d042-4170-b21f-62ccc6c5e209%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.7 migrate for postgres fails: Charfield to ForeignKey

2015-02-20 Thread Martin Kapfhammer
Yep, I can drop the column and create a new one as integer.
The only problem I have is that creating the field as a char was in 
migration number 0020, changing it to a foreign key was in migration number 
0028 and now I have already 0036 migrations. Therefore I have to "hang in" 
the dropping and adding code between 0020 and 0028. How can I do this? I 
can write the migration files by hand, but what is the logic to hang it in 
e.g. before 0028 with already a 0027 existing.

What's best practice here?

Am Freitag, 20. Februar 2015 18:16:48 UTC+1 schrieb george:
>
> The deal here is that the model Currency has an ID, which is well, integer.
>
> Your data that is already on that column, is char (original field). If you 
> are not in production, I would recommend dropping the field (comment the 
> code), make migrations and apply. that will remove the currency column. 
> Then add the new column, make migrations and apply.
>
> On Fri, Feb 20, 2015 at 2:30 PM, Martin Kapfhammer  > wrote:
>
>> First I created a CharField:
>>  ('currency', models.CharField(max_length=30)),
>>
>> In a later migration I changed it to a foreign key field:
>>
>> field=models.ForeignKey(to='web.Currency'),
>>
>> It worked on a local MySql instance, but not on Postgres on Heroku:
>> django.db.utils.ProgrammingError: column "currency_id" cannot be cast 
>> automatically to type integer
>> HINT:  Specify a USING expression to perform the conversion.
>>
>> If I do the following manually, I can continue:
>>
>> alter table web_financialdata drop column currency;
>> alter table web_financialdata add column currency integer;
>>
>> Should I add this via RunSQL between the migrations. If so, how? Or is 
>> there a better way?
>>
>> Thanks,
>> Martin
>>
>>
>>
>>
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/bdde39c8-a81a-4228-bb68-cbebb675d729%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> George R. C. Silva
> SIGMA Consultoria
> 
> http://www.consultoriasigma.com.br/
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2fd346ed-51e4-4ff1-9358-3f2e43fd7cb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: JSON Response

2015-02-20 Thread elcaiaimar
Please, have a look at this tutorial: 
https://www.youtube.com/watch?v=Pxn5L1qJTAw
Sorry, It's in spanish, but it's what I'm doing. I've tried to put the same 
code but it doesn't work because he uses an older version of django.
If you don't want to see all the video, you can see the minute 12:16.
He clicks on the remove button and then, an alert appears!
My django version is 1.7

I hope this helps!

And Thank you for your answers!

El jueves, 19 de febrero de 2015, 20:14:32 (UTC+1), elcaiaimar escribió:
>
> Hello,
>
> I was wondering how I can send a response JSON in a good way, because I 
> have the next code:
>
> if "product_id" in request.POST:
> try:
> id_producto = request.POST['product_id']
> p = Pozo.objects.get(pk=id_producto)
> mensaje = {"status":"True","product_id":p.id}
> p.delete() # Elinamos objeto de la base de datos
> return JsonResponse(mensaje)
> except:
> mensaje = {"status":"False"}
> return JsonResponse(mensaje)
>
> And my JS function doesn't work with this code:
>
>var options = {
> success:function(response)
> {
> if(response.status=="True"){
> alert("Eliminado!");
> var idProd = response.product_id;
> var elementos= $(nombre_tabla+' >tbody >tr').length;
> if(elementos==1){
> location.reload();
> }else{
> $('#tr'+idProd).remove();
> $(nombre_ventana_modal).modal('hide');
> }
> }else{
> alert("Hubo un error al eliminar!");
> $(nombre_ventana_modal).modal('hide');
> };
> }
> };
> $(nombre_formulario_modal).ajaxForm(options);
> });
>
> And I don't know what I can do. Does anyone have any idea?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7598022d-83b0-4c49-b8e1-a86b169fd336%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to filter results using forms in Django/Python (best approach) ?

2015-02-20 Thread Ronaldo Bahia


I'm kind of new in python/django and I'd like to know: What's the best 
approach to filter results in Django using forms in a view?

I need to filter candidates by haircolor, according to the model 
CandidateLook and by status, according to CandidateToJob model.

Thanks in advance.

Here is my code:
http://stackoverflow.com/questions/28637326/how-to-filter-results-using-forms-in-django-best-approach

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bf338512-fa18-4d97-a3e7-02588577e1a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Create a new object for the newly registered user

2015-02-20 Thread tiklitaba123
I am very new to django, so please bear with me. What I want is whenever a 
new user is registered I would like to create an `About` for that user. How 
will I do that? Please help me. Thank you.

views:

def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST or None)
if form.is_valid():
form.save()
return HttpResponseRedirect('/')
else:
return render(request, 'register.html', {'form':form})
else:
form = UserCreationForm()
return render(request, 'register.html', {'form':form})

model:

class About(models.Model):
user = models.OneToOneField(User)
gender = models.CharField(max_length=1, choices=GENDER)
dob = models.DateField(null=True, blank=True)
place = models.CharField(max_lenght=100)

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


Re: Sqlite3 to Postgres Migration?

2015-02-20 Thread talex
Thanks for your helpful comments.

Andrew, thanks for your migration article at http://afrg.co/updj17/a2 .  It 
is slightly daunting for me at this point, but I may need to come back to 
it later. Your book looks interesting.

Mike, thanks for the dump/load load suggestion.

For the moment, I think the easiest thing for me is to follow Thomas, and 
just start over with Postgres, but let me explain more about what I am 
doing and ask two more questions.

I am leading a project to create a web application for uploading certain 
scientific data into a database.  No one in the group has experience with 
web development.  We decided on Django, and I wrote a prototype using 
sqlite3.  Sqlite3 will not be used going forward.  Instead either Postgres 
or MySql will be used.  Personally I am in favor of Postgres, but I have 
been telling the group, perhaps incorrectly, that Django is "database 
agnostic" and that we can easily change databases at any time in the future 
should we need to do so.  So let me ask two more questions:

In the life of a Django application, is it simple and easy to change the 
database flavor (say from Postgres to MySql), even after significant data 
has accumulated in the model's database?  

Does the answer change if we are willing to forgo the use of the 
version-control-like capabilities represented by Django's 
makemirations/migrate tools?

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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/458baa37-5387-4784-97c2-c7cbb50fc480%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.7 migrate for postgres fails: Charfield to ForeignKey

2015-02-20 Thread George Silva
check merge migrations. some migrations the framework will combine whenever
possible.
Em 20/02/2015 17:15, "Martin Kapfhammer" 
escreveu:

> Yep, I can drop the column and create a new one as integer.
> The only problem I have is that creating the field as a char was in
> migration number 0020, changing it to a foreign key was in migration number
> 0028 and now I have already 0036 migrations. Therefore I have to "hang in"
> the dropping and adding code between 0020 and 0028. How can I do this? I
> can write the migration files by hand, but what is the logic to hang it in
> e.g. before 0028 with already a 0027 existing.
>
> What's best practice here?
>
> Am Freitag, 20. Februar 2015 18:16:48 UTC+1 schrieb george:
>>
>> The deal here is that the model Currency has an ID, which is well,
>> integer.
>>
>> Your data that is already on that column, is char (original field). If
>> you are not in production, I would recommend dropping the field (comment
>> the code), make migrations and apply. that will remove the currency column.
>> Then add the new column, make migrations and apply.
>>
>> On Fri, Feb 20, 2015 at 2:30 PM, Martin Kapfhammer 
>> wrote:
>>
>>> First I created a CharField:
>>>  ('currency', models.CharField(max_length=30)),
>>>
>>> In a later migration I changed it to a foreign key field:
>>>
>>> field=models.ForeignKey(to='web.Currency'),
>>>
>>> It worked on a local MySql instance, but not on Postgres on Heroku:
>>> django.db.utils.ProgrammingError: column "currency_id" cannot be cast
>>> automatically to type integer
>>> HINT:  Specify a USING expression to perform the conversion.
>>>
>>> If I do the following manually, I can continue:
>>>
>>> alter table web_financialdata drop column currency;
>>> alter table web_financialdata add column currency integer;
>>>
>>> Should I add this via RunSQL between the migrations. If so, how? Or is
>>> there a better way?
>>>
>>> Thanks,
>>> Martin
>>>
>>>
>>>
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/bdde39c8-a81a-4228-bb68-cbebb675d729%
>>> 40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> George R. C. Silva
>> SIGMA Consultoria
>> 
>> http://www.consultoriasigma.com.br/
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2fd346ed-51e4-4ff1-9358-3f2e43fd7cb9%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGyPVTtgR7N9inPrLP_5Y0sLwuDU8Yiyj9yeyBc%2BgOZBn59bOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: matplotlib pyplot stop working

2015-02-20 Thread dk
yep  I get the same issue the guy is commenting, were it happen when I run 
it more than once,  I will try to do the multiprocess that he mention and I 
will see what happen.

On Friday, February 20, 2015 at 11:22:32 AM UTC-6, Collin Anderson wrote:
>
> Hi,
>
> The freezing could be a memory leak. 
> http://stackoverflow.com/questions/7125710/matplotlib-errors-result-in-a-memory-leak-how-can-i-free-up-that-memory
>
> Could the image be cached by the browser, does shift+F5 refresh it? The 
> easiest way to fix it would be to use a different url/filename every time 
> you generate an new image.
>
> Collin
>
> On Thursday, February 19, 2015 at 4:26:16 PM UTC-5, dk wrote:
>>
>> I am using matplotlib.pyplot to generate a plot image, put it in a temp 
>> folder, 
>> and then use that to populate a webpage.
>>
>> the problem is:
>> 1) always display the same image,  I all ready deleted the image before 
>> creating the new one, 
>> I also set pyplot .close()  to close all my figures.
>>
>> 2) some times everything freeze and stop working.
>>
>> my suspicions is since django is constantly running keeps the figure in 
>> the memory some how.   have any one got issues like this?
>> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cb183ead-a8b2-4f08-8f83-188c4e0f0cdc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Sqlite3 to Postgres Migration?

2015-02-20 Thread Andrew Farrell
One approach may be to use django-import-export
 to add to the
admin interface the capability to export your data to CSV (or JSON or
Excel) and likewise to import it.
Then, simply run two instances of your app: one on top of postgres, one on
top of sqlite. Export from one and import into the other.

Modifying the admin interface is probably not the fastest route to victory,
but if your application is centered around uploading and downloading data,
then you might decide that adding an "export to CSV" button is already
useful.

On Fri, Feb 20, 2015 at 4:55 PM, talex  wrote:

> Thanks for your helpful comments.
>
> Andrew, thanks for your migration article at http://afrg.co/updj17/a2 .
> It is slightly daunting for me at this point, but I may need to come back
> to it later. Your book looks interesting.
>
> Mike, thanks for the dump/load load suggestion.
>
> For the moment, I think the easiest thing for me is to follow Thomas, and
> just start over with Postgres, but let me explain more about what I am
> doing and ask two more questions.
>
> I am leading a project to create a web application for uploading certain
> scientific data into a database.  No one in the group has experience with
> web development.  We decided on Django, and I wrote a prototype using
> sqlite3.  Sqlite3 will not be used going forward.  Instead either Postgres
> or MySql will be used.  Personally I am in favor of Postgres, but I have
> been telling the group, perhaps incorrectly, that Django is "database
> agnostic" and that we can easily change databases at any time in the future
> should we need to do so.  So let me ask two more questions:
>
> In the life of a Django application, is it simple and easy to change the
> database flavor (say from Postgres to MySql), even after significant data
> has accumulated in the model's database?
>
> Does the answer change if we are willing to forgo the use of the
> version-control-like capabilities represented by Django's
> makemirations/migrate tools?
>
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/458baa37-5387-4784-97c2-c7cbb50fc480%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2By5TLY7v65oBPbsjW17ByqW4%3DGJTE359zo%3DqsGdEZKsEHm_uQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: JSON Response

2015-02-20 Thread elcaiaimar
I solved it! Sorry, at last I had a bad called to jquery library in my 
base.html. I had to check all my project
Thank you for your answers, you have helped me a lot!

El viernes, 20 de febrero de 2015, 21:01:46 (UTC+1), elcaiaimar escribió:
>
> Please, have a look at this tutorial: 
> https://www.youtube.com/watch?v=Pxn5L1qJTAw
> Sorry, It's in spanish, but it's what I'm doing. I've tried to put the 
> same code but it doesn't work because he uses an older version of django.
> If you don't want to see all the video, you can see the minute 12:16.
> He clicks on the remove button and then, an alert appears!
> My django version is 1.7
>
> I hope this helps!
>
> And Thank you for your answers!
>
> El jueves, 19 de febrero de 2015, 20:14:32 (UTC+1), elcaiaimar escribió:
>>
>> Hello,
>>
>> I was wondering how I can send a response JSON in a good way, because I 
>> have the next code:
>>
>> if "product_id" in request.POST:
>> try:
>> id_producto = request.POST['product_id']
>> p = Pozo.objects.get(pk=id_producto)
>> mensaje = {"status":"True","product_id":p.id}
>> p.delete() # Elinamos objeto de la base de datos
>> return JsonResponse(mensaje)
>> except:
>> mensaje = {"status":"False"}
>> return JsonResponse(mensaje)
>>
>> And my JS function doesn't work with this code:
>>
>>var options = {
>> success:function(response)
>> {
>> if(response.status=="True"){
>> alert("Eliminado!");
>> var idProd = response.product_id;
>> var elementos= $(nombre_tabla+' >tbody >tr').length;
>> if(elementos==1){
>> location.reload();
>> }else{
>> $('#tr'+idProd).remove();
>> $(nombre_ventana_modal).modal('hide');
>> }
>> }else{
>> alert("Hubo un error al eliminar!");
>> $(nombre_ventana_modal).modal('hide');
>> };
>> }
>> };
>> $(nombre_formulario_modal).ajaxForm(options);
>> });
>>
>> And I don't know what I can do. Does anyone have any idea?
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1cad0560-be64-45f5-9091-f2c2f07e07c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Design question: Is it really a good idea for models having “side effects”?

2015-02-20 Thread Russell Keith-Magee
On Fri, Feb 20, 2015 at 4:23 PM, Gergely Polonkai 
wrote:

> Hello,
>
> I’m currently implementing a finite state machine in my application using
> Django FSM[1]. In the Usage section of the README the author said that
> “This function may contain side-effects, like updating caches, notifying
> users, etc.”
>
> Opposing this statement, the Symfony PHP framework’s authors say that
> models should never have such side effects.
>
> Thus, I was wondering what is the case with Django in this topic. Should I
> really do such things, like notifying users, in the model’s code?
>

Separation of concerns isn't a Django thing or a Symfony thing - it's a
good software engineering thing.

I can't speak for the creators of Django FSM, but if I was to try an
interpret that statement, I'd say what they were trying to say is "this is
a place from which you can trigger other side effects", not "this is the
best place to put side effect logic".

It's a bit difficult to discuss without a concrete example, but I'd suggest
that the internal logic of your FSM isn't the best place to put complex
logic that touches external services (unless, of course, your FSM is
directly tied to managing that service). However, it *would* be appropriate
for your FSM to take the trigger of a state change, and use that as a
trigger for other system changes.

Put another way -  look at the process for testing your FSM. Will you be
able to test your FSM without a fully functional cache, notification
system, etc? If you're not able to configure your FSM in such a way that a
mock of your notification service can be passed in as a configuration
parameter, then you've probably coupled your FSM and your side effect logic
too closely. However, if you *can* drop in a testing mock as a
configuration item, you've captured the *type* of side effect that you
expect to occur, without tying it to a specific implementation.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq849VE%3DJw7DjhTs%3DpRejWtb0q%3Dtab5YeVjbSDQHj%2BkvzuYA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: html response to be loaded in a div

2015-02-20 Thread Vijay Khemlani
If you're using jQuery 1.5.1 or above you can do this instead

// using jQuery
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue =
decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

var csrftoken = getCookie('csrftoken');

function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}

$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});

On Fri, Feb 20, 2015 at 4:13 PM, João Marques 
wrote:

> Oh I see. Meanwhile I'm trying to implement the token but I cant get this
> to work, I copied the code from Django's docs and now Im getting a
> javascript error syaing that the function sameOrigin is not defined.
>
>
>
>
> *Code*function getCookie(name) {
> var cookieValue = null;
> if (document.cookie && document.cookie != '') {
> var cookies = document.cookie.split(';');
> for (var i=0; i var cookie = jQuery.trim(cookies[i]);
> // Does this cookie string begin with the name we want?
> if (cookie.substring(0, name.length+1) == (name + '=')) {
> cookieValue =
> decodeURIComponent(cookie.substring(name.length + 1));
> break;
> }
> }
> }
> return cookieValue;
> }
>
>
> function csrfSafeMethod(method) {
> // these HTTP methods do not require CSRF protection
> return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
> }
> function sameOrigin(url) {
> // test that a given url is a same-origin URL
> // url could be relative or scheme relative or absolute
> var host = document.location.host; // host + port
> var protocol = document.location.protocol;
> var sr_origin = '//' + host;
> var origin = protocol + sr_origin;
> // Allow absolute or scheme relative URLs to same origin
> return (url == origin || url.slice(0, origin.length + 1) == origin
> + '/') ||
> (url == sr_origin || url.slice(0, sr_origin.length + 1) ==
> sr_origin + '/') ||
> // or any other URL that isn't scheme relative or absolute i.e
> relative.
> !(/^(\/\/|http:|https:).*/.test(url));
> }
> $.ajaxSetup({
> beforeSend: function(xhr, settings) {
> if (!csrfSafeMethod(settings.type) &&
> sameOrigin(settings.url)) {
> // Send the token to same-origin, relative URLs only.
> // Send the token only if the method warrants CSRF
> protection
> // Using the CSRFToken value acquired earlier
> xhr.setRequestHeader("X-CSRFToken", csrftoken);
> }
> }
> });
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a9eb7352-d042-4170-b21f-62ccc6c5e209%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3vnG2HHc8CZXcx1svdg%2BC8LPu%2BKJJG89ebRvvOx7p%3D4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to filter results using forms in Django/Python (best approach) ?

2015-02-20 Thread Vijay Khemlani
It's not clear what's the purpose of the view you are showing. ¿Is it
supposed to display a form with "haircolor" and "status" fields and filter
the results it displays based on that?

In that case you can declare a form:

from django import forms

class ScreeningForm(forms.Form):
haircolor = forms.ChoiceField(choices=CandidateLook.HAIRCOLOR_CHOICES)
status = forms.ChoiceField(choices=CandidateToJob.STATUS_CHOICES)

then you can use it in your view, for example to display it:

class Screening(generic.DetailView):
model = Job
template_name = 'dashboard/screening.html'

def get_context_data(self, **kwargs):
context = super(Screening, self).get_context_data(**kwargs)
context['form'] = ScreeningForm()
return context

HTML:


{{ form.as_p }}



(the code above just creates, displays and submits the form, it does not
filter your results yet)

On Fri, Feb 20, 2015 at 5:10 PM, Ronaldo Bahia  wrote:

> I'm kind of new in python/django and I'd like to know: What's the best
> approach to filter results in Django using forms in a view?
>
> I need to filter candidates by haircolor, according to the model
> CandidateLook and by status, according to CandidateToJob model.
>
> Thanks in advance.
>
> Here is my code:
>
> http://stackoverflow.com/questions/28637326/how-to-filter-results-using-forms-in-django-best-approach
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/bf338512-fa18-4d97-a3e7-02588577e1a3%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2Zx9s1eD6hrNG%2BQqVrK6L3Ur0Hgfxp2h_uUpbLVAA9cA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Create a new object for the newly registered user

2015-02-20 Thread Vijay Khemlani
You can use a post_save signal for the User Model

https://docs.djangoproject.com/en/1.7/ref/signals/#post-save

from django.db.models.signals import post_save
from django.contrib.auth.models import User

def create_about(sender, **kwargs):
user = kwargs['instance']
if kwargs['created']:
about = About()
about.user = user
about.save()

post_save.connect(create_about, sender=User)


On Fri, Feb 20, 2015 at 4:58 PM,  wrote:

> I am very new to django, so please bear with me. What I want is whenever a
> new user is registered I would like to create an `About` for that user. How
> will I do that? Please help me. Thank you.
>
> views:
>
> def register(request):
> if request.method == 'POST':
> form = UserCreationForm(request.POST or None)
> if form.is_valid():
> form.save()
> return HttpResponseRedirect('/')
> else:
> return render(request, 'register.html', {'form':form})
> else:
> form = UserCreationForm()
> return render(request, 'register.html', {'form':form})
>
> model:
>
> class About(models.Model):
> user = models.OneToOneField(User)
> gender = models.CharField(max_length=1, choices=GENDER)
> dob = models.DateField(null=True, blank=True)
> place = models.CharField(max_lenght=100)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a9958449-22b8-437d-bdd0-8a25372a99fe%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3jaPf1Ua1kvfsEvVDs9KoWxfpzgJru6YyDigWKL5BJXA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Problem whit Stripe payment setup (stripeToken)

2015-02-20 Thread Petar Pilipovic
Hello there I am making an e_commerc django app, and I am trying to setup 
stripe as a payment. 
I have done all the tutorial setup from stripe.com site and when I use 
stripe test credit card I only get :

I do not see mine stripeToken. 
I have tried to google it on the web and they have told me that I did not 
setup it properly, I have tried to see where I am mistaking but can not see 
it.
Can someone help me overcome this.
This is mine views.py where mine stripe is defined , 
mine checkout.html  where stripe form, and the rest of 
the jQuery/javascripte are defined for genereting stripeToken, and mine 
base.html .
Tank you.

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


Re: Sqlite3 to Postgres Migration?

2015-02-20 Thread Mike Dewhirst

On 21/02/2015 9:55 AM, talex wrote:

Thanks for your helpful comments.

Andrew, thanks for your migration article at http://afrg.co/updj17/a2 .
  It is slightly daunting for me at this point, but I may need to come
back to it later. Your book looks interesting.

Mike, thanks for the dump/load load suggestion.

For the moment, I think the easiest thing for me is to follow Thomas,
and just start over with Postgres, but let me explain more about what I
am doing and ask two more questions.

I am leading a project to create a web application for uploading certain
scientific data into a database.  No one in the group has experience
with web development.  We decided on Django, and I wrote a prototype
using sqlite3.  Sqlite3 will not be used going forward.   Instead either
Postgres or MySql will be used.  Personally I am in favor of Postgres,


Good call. IMO.


but I have been telling the group, perhaps incorrectly, that Django is
"database agnostic"


Correctly. https://docs.djangoproject.com/en/1.7/ref/databases/

and that we can easily change databases at any time

in the future should we need to do so.  So let me ask two more questions:

In the life of a Django application, is it simple and easy to change the
database flavor (say from Postgres to MySql), even after significant
data has accumulated in the model's database?


Probably easy but depends on your data. You need to do a comparison of 
data types supported to see if your task is covered by both. But even if 
not, you should be able to work around it with sleight of hand. This is 
independent of Django.




Does the answer change if we are willing to forgo the use of the
version-control-like capabilities represented by Django's
makemirations/migrate tools?


Not sure I understand the question. Switching from one database to 
another is not migrating in the sense that word is used in Django.


You probably wouldn't even need to use migrations anyway unless your 
models change. And you wouldn't want to conflate a model change with a 
database switch.


You would use PG Admin for "dumbing down" Postgres data types so it will 
become dump/loadable into Mysql.


Your real alternatives in switching databases are to do it with a 
shutdown or do it live. Django can handle multiple databases 
simultaneously so your options are legion!


I think the only valid reason for switching databases is if the one you 
chose is not doing the job.


Maybe your team is familiar with Mysql. If so, go with that. It is 
usually better for a leader to ask the team to do the research then 
choose the stack so that they have buy-in.


Cheers

Mike



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 http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/458baa37-5387-4784-97c2-c7cbb50fc480%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54E8309C.4020405%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.