AJAX - Class Based View or Function Based View?

2013-08-29 Thread Sarthak Dev
I'm working on an app which uses a lot of AJAX requests. Having previously 
used FBVs for handling ajax and returning JSON, how efficient will it be to 
use a CBV for the same? I read the django docs and found 
mixins
 for 
it, but haven't figured out if using them and CBVs will help in any way.

Anyone?   

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


else: invalid syntax

2013-08-29 Thread Nagarajan Dharmar Sitha
if (os.stat('udacityLastFileNumberForL.txt').st_size == 0):
MaxNumberFile = open("udacityLastFileNumberForL.txt", "w")
self.udacityFileVersionNumberL = 1
MaxNumberFile.write("DATA_VERSION_CONSTANT_M: %s" % 
self.udacityFileVersionNumberL)
MaxNumberFile.close()
else:
MaxNumberFile = open('udacityLastFileNumberForL.txt', "r")
for LastFileNumber in MaxNumberFile.readlines():


it show error:

else:
   ^
SyntaxError: invalid syntax

Kindly help me for debug this

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: else: invalid syntax

2013-08-29 Thread Tom Lockhart

On 2013-08-29, at 5:33 AM, Nagarajan Dharmar Sitha 
 wrote:

> if (os.stat('udacityLastFileNumberForL.txt').st_size == 0):
> MaxNumberFile = open("udacityLastFileNumberForL.txt", "w")
> self.udacityFileVersionNumberL = 1
> MaxNumberFile.write("DATA_VERSION_CONSTANT_M: %s" % 
> self.udacityFileVersionNumberL)
> MaxNumberFile.close()
> else:
> MaxNumberFile = open('udacityLastFileNumberForL.txt', "r")
> for LastFileNumber in MaxNumberFile.readlines():
> 
> 
> it show error:
> 
> else:
>^
> SyntaxError: invalid syntax
> 
> Kindly help me for debug this

It looks like your indenting might be off. The "else" must line up exactly with 
the "if".

hth

- Tom

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: else: invalid syntax

2013-08-29 Thread Nagarajan Dharmar Sitha
Thank you Tom
Raja



-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: AJAX - Class Based View or Function Based View?

2013-08-29 Thread Jonathan Baker
I feel like FBV vs CBV is partially a matter of taste. If your app is
AJAX-heavy though, why not use one of the proper API frameworks like
http://django-rest-framework.org/ or
http://django-tastypie.readthedocs.org/en/latest/ ?


On Thu, Aug 29, 2013 at 12:51 AM, Sarthak Dev wrote:

> I'm working on an app which uses a lot of AJAX requests. Having previously
> used FBVs for handling ajax and returning JSON, how efficient will it be to
> use a CBV for the same? I read the django docs and found 
> mixins
>  for
> it, but haven't figured out if using them and CBVs will help in any way.
>
> Anyone?
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Jonathan D. Baker
Developer
http://jonathandbaker.com

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Javascript encoding and python decoding and vice versa

2013-08-29 Thread Tom Evans
On Wed, Aug 28, 2013 at 7:53 PM, Samantha Atkins  wrote:
> We all know about SSL so stop the lectures please.  Sometimes you simply
> want to reasonably encrypt on client and decrypt on server and for one
> reason or another SSL is not an option.

SSL is always an option, you are just not choosing it. Using JS crypto
is fine, assuming you do all the appropriate things that SSL does in
order to transmit a secure session key to the client. If you don't do
that, you might as well use ROT-13 encryption.

On Wed, Aug 28, 2013 at 7:51 PM, Samantha Atkins  wrote:
> So if I use sjcl.encrypt at browser then how do I do the equivalent of
> sjcl.decrypt in python at server side.  That is what the original question
> was asking as I read it.

Since there is no such thing as 'sjcl.encrypt', there is no answer to
this. If wanted to use CryptoJS's AES encryption however, you could do
something like this on the client (as taken from the linked docs...):

http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js";>

var encrypted = CryptoJS.AES.encrypt("JS crypto is daft", "Secret
Passphrase");


And then, the purpose of using STANDARD crypto comes clear, you use
the py-crypto library to decode

from Crypto.Cipher import AES
import binascii

key = 'Secret Passphrase'
ciphertext = binascii.unhexlify(encrypted_string)

decobj = AES.new(key, AES.MODE_ECB)
plaintext = decobj.decrypt(ciphertext)

I've not tested any of this, CryptoJS might not use ECB by default.

All of this, of course, does not take in to account my first warning
about key exchange. Without effective key exchange, your "secret"
passphrase is passed over the internet in the clear, meaning anyone
who wants to defeat your encryption needs only monitor that and your
encrypted data, and effectively your content is not encrypted at all.

Just use SSL. I'm sorry if you feel that advice is unhelpful, it
really isn't. See this answer for fuller explanations:

http://stackoverflow.com/questions/9833527/client-side-encryption-over-http-with-diffie-hellman-key-exchange-and-aes

Cheers

Tom

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: need a help in ListView 1) how to debug the rendered request and response

2013-08-29 Thread Tom Evans
On Wed, Aug 28, 2013 at 7:08 PM, bab mis  wrote:
> Here is my code
>
> models.py
> ===
> class member(models.Model):
> first_name = models.CharField(max_length=30)
> last_name = models.CharField(max_length=30)
> dob   = models.DateField()
>
> def get_fields(self):
> return(self.__dict__.keys()[0:len(self.__dict__.keys())-2])
>
>
> views.py
> ==
> class ListContactView(ListView):
>
> template_name = 'member_list.html'
> model=member
> member_list = member.objects.all()
> memberobj   = member()
> def listcontacttab(self):
> import tablib
> head=memberobj.get_fields()
> d=tablib.Dataset()
> d.headers=head
> for obj in member_list:
> values=[]
> for mem in head:
> values.append(obj.__dict__[mem].__str__())
> d.append(values)
>
>
> return render_to_response(template_name,{'member_list':d})

Note, the template variable is called 'member_list'

>
>
>
> template:
>
> 
>   {{ d.html }}
> 

So 'd' will be undefined.


Cheers

Tom

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: AJAX - Class Based View or Function Based View?

2013-08-29 Thread Lee Hinde
On Wed, Aug 28, 2013 at 11:51 PM, Sarthak Dev wrote:

> I'm working on an app which uses a lot of AJAX requests. Having previously
> used FBVs for handling ajax and returning JSON, how efficient will it be to
> use a CBV for the same? I read the django docs and found 
> mixins
>  for
> it, but haven't figured out if using them and CBVs will help in any way.
>
> Anyone?
>
> If you decide on CBV, there's also 
> django-braces which
has some ajax helpers.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Django Form Wizard: Why is this happening?

2013-08-29 Thread Bruno Lottero
*I have a dinamic form wizard step as following:*

class AltaForm6(forms.Form):
CHOICES = ((1, 1,), (2, 2,))

username = ChoiceFieldInvalid(required=True, label="Usuario", 
widget=forms.RadioSelect, choices=CHOICES)
username2 = forms.CharField(required=False, label="Otro")
def clean_username2(self):
  username = self.cleaned_data.get('username')
  username2 = self.cleaned_data.get('username2')

  if username == "Otro" and len(username2) == 0:
raise forms.ValidationError("Debe especificar un nombre de usuario")
  return username2
def clean_username(self):
  username = self.cleaned_data.get('username')
  return username


*Then i dynamically change the choices values:*

class AltaWizard(SessionWizardView):

template_name = 'agroshare/wizard.html'
def get_form(self, step=None, data=None, files=None):
form = super(AltaWizard, self).get_form(step, data, files)
if step == '5':

   import logging
   logger = logging.getLogger(__name__)

   cleaned_data = self.get_cleaned_data_for_step('2') or {}
   logger.error(cleaned_data)
   nombre = cleaned_data.get('nombre')
   apellido = cleaned_data.get('apellido')

   first = possibleUid(nombre, apellido, '1')
   second = possibleUid(nombre, apellido, '2')

   if ' ' in nombre:
  third = possibleUid(nombre, apellido, '3')
  form.fields['username'].choices = ((first, first,), (second, 
second,), (third, third,), ("Otro", "Otro",))
   if ' ' in apellido:
  fourth = possibleUid(nombre, apellido, '4')
  form.fields['username'].choices = ((first, first,), (second, 
second,), (fourth, fourth,), ("Otro", "Otro",))
   else:
  form.fields['username'].choices = ((first, first,), (second, 
second,), ("Otro", "Otro",))
if step == '5':
   form.user = self.request.user
return form

def render(self, form=None, **kwargs):
form = form or self.get_form()
context = self.get_context_data(form=form, **kwargs)
if self.steps.current == '5':
   form2 = self.get_form('5')
   cleaned_data = self.get_cleaned_data_for_step('5') or {}
   username = cleaned_data.get('username')
   form2.fields['username'].choices = [username]
return self.render_to_response(context)

*The problem is, when i go back to this step trough the wizard, it does not 
modify the "choices" values, it shows "CHOICES = ((1, 1,), (2, 2,))"*
* *

*How can i achieve that when i go back to this step, the form can actually 
show the values i want?*



-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Django Form Wizard: Why is this happening?

2013-08-29 Thread Bruno Lottero
*I have a dinamic form wizard step as following:*

class AltaForm6(forms.Form):
CHOICES = ((1, 1,), (2, 2,))

username = ChoiceFieldInvalid(required=True, label="Usuario", 
widget=forms.RadioSelect, choices=CHOICES)
username2 = forms.CharField(required=False, label="Otro")def 
clean_username2(self):
  username = self.cleaned_data.get('username')
  username2 = self.cleaned_data.get('username2')

  if username == "Otro" and len(username2) == 0:
raise forms.ValidationError("Debe especificar un nombre de usuario")
  return username2
def clean_username(self):
  username = self.cleaned_data.get('username')
  return username


*Then i dynamically change the choices values:*

class AltaWizard(SessionWizardView):

template_name = 'agroshare/wizard.html'
def get_form(self, step=None, data=None, files=None):
form = super(AltaWizard, self).get_form(step, data, files)
if step == '5':

   import logging
   logger = logging.getLogger(__name__)

   cleaned_data = self.get_cleaned_data_for_step('2') or {}
   logger.error(cleaned_data)
   nombre = cleaned_data.get('nombre')
   apellido = cleaned_data.get('apellido')

   first = possibleUid(nombre, apellido, '1')
   second = possibleUid(nombre, apellido, '2')

   if ' ' in nombre:
  third = possibleUid(nombre, apellido, '3')
  form.fields['username'].choices = ((first, first,), (second, 
second,), (third, third,), ("Otro", "Otro",))
   if ' ' in apellido:
  fourth = possibleUid(nombre, apellido, '4')
  form.fields['username'].choices = ((first, first,), (second, 
second,), (fourth, fourth,), ("Otro", "Otro",))
   else:
  form.fields['username'].choices = ((first, first,), (second, 
second,), ("Otro", "Otro",))
if step == '5':
   form.user = self.request.user
return form

def render(self, form=None, **kwargs):
form = form or self.get_form()
context = self.get_context_data(form=form, **kwargs)
if self.steps.current == '5':
   form2 = self.get_form('5')
   cleaned_data = self.get_cleaned_data_for_step('5') or {}
   username = cleaned_data.get('username')
   form2.fields['username'].choices = [username]
return self.render_to_response(context)

*The problem is, when i go back to this step trough the wizard, it does not 
modify the "choices" values, it shows "CHOICES = ((1, 1,), (2, 2,))"*
* *

*How can i achieve that when i go back to this step, the form can actually 
show the values i want?*



-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Save data from parent in inline admin form

2013-08-29 Thread George Tsotsos



i have a model admin form with 3 inlines, my problem is that i want one 
of the inline forms be saved with data from parent form. eg. *fieldfrominline = 
fieldfromparent

*class multifield1_inline(admin.TabularInline):
model = multifield1
extra = 1class multifield2_inline(admin.TabularInline):
model = multifield2
extra = 1class multifield3_inline(admin.TabularInline):
model = multifield3
extra = 1class baseform(admin.ModelAdmin):
model = base
inlines=[multifield1_inline,
multifield2_inline,
multifield3_inline,]
def save_model(self, request, obj, form, change):
obj.cuser = request.user
obj.save()

i tried save_formset medthod but probably i am doing something wrong
cause i couldn't get/set the fields of inline form and specify which of
inlines is to be saved..

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Saving google maps values to db

2013-08-29 Thread Nkansah Rexford
I came across this app for displaying Google maps to pages in django. 
https://bitbucket.org/dbinit/django-gmapi/src

Is there a way I can save Google maps values via a form to db for retrieval 
later in a page?

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Saving google maps values to db

2013-08-29 Thread Kelvin Wong
If you have a map on a page, you can add some Javascript that obtains the 
Lat and Lng and Zoom Level from the map and then use that data to fill in a 
form (or do whatever you want with it). This code give some hints

https://developers.google.com/maps/documentation/javascript/examples/map-coordinates

K


On Thursday, August 29, 2013 8:02:31 PM UTC-7, Nkansah Rexford wrote:
>
> I came across this app for displaying Google maps to pages in django. 
> https://bitbucket.org/dbinit/django-gmapi/src
>
> Is there a way I can save Google maps values via a form to db for 
> retrieval later in a page?
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


reload counts

2013-08-29 Thread Harjot Mann
I want to add a feature in my app in which when user opens a template,
it counts the number of clicks done and also count the number of of
times the page reloads. Not have any idea. Can anyone help me?

-- 
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/
Daily Dairy: http://harjotmann.wordpress.com/daily-diary/

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: django refreshing problem

2013-08-29 Thread Harjot Mann
On Mon, Aug 26, 2013 at 2:36 PM, Harjot Mann  wrote:
> In django whenever I make some template I need to refresh it. I am not
> getting what is the problem, is it some cache problem, even I disabled
> it using never_cache but nothing worked, Is there anyone who faced the
> same problem. Please help me I want to know that exactly what is
> happening and why?


Waiting for reply.

-- 
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/
Daily Dairy: http://harjotmann.wordpress.com/daily-diary/

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.