Re: how to access json data value(s) returned back to django view from 'GET' request to an api

2015-02-06 Thread Scot Hacker
On Friday, February 6, 2015 at 9:39:00 AM UTC-8, Henry Versemann wrote:
>
> Scot, Thanks for the reply. OK I've gotten down to the point to where I 
> have my version of your json_data in your code below, but I'm not sure I 
> understand exactly what your code is doing, after you have the json_data 
> variable contents. In my case the first object of response data that I'm 
> trying to use is a list of two items, with each item containing multiple 
> keys and internal or sub objects within them.
>

Once your data comes back from the API and has been converted to python 
data structures, it's up to you to parse and extract from it what you need 
- every situation is different. All you need to know is that you access 
list items by their index, and dictionary items by quoted key name. So if I 
assign the response object you show here to a variable "data", I can do the 
following:

print(data[0]['parameters'])
print(data[0]['parameters']['extra_text'])
print(data[1]['attachment']['display_name'])

and the result is:

{u'enrollment_term_id': u'', u'extra_text': u'Term: All Terms;'}
Term: All Terms;
grade_export_csv_22_Oct_2013_2_27551-0.csv

Hope this helps!

./s
 

-- 
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/428cc652-220e-44d8-8818-33725c0b141f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django default auth user but unique email

2015-02-06 Thread Bruce Li
Thanks for your advice, I was too busy to reply. I will learn to use a 
custom model. Thanks.


On Tuesday, January 27, 2015 at 2:36:53 PM UTC+8, James Schneider wrote:
>
> If you want any sort of enforcement of a unique email address at the 
> database level, you'll need a custom user model. If you don't care about 
> that, all you'd need to do is override the user forms and create a custom 
> clean_email function that checks for duplicates before saving the form 
> data. Not 100% guaranteed on a high traffic site unless you wrap it in a 
> transaction, and will become expensive to check as you gather more users in 
> the database, especially since the email field won't be indexed using the 
> standard user model, and would result in a slower string-matching query 
> against the entire table rather than an index-based comparison.
>
> If you have any special requirements for the user in your application, I 
> highly recommend you bite the bullet and create a custom user model. It's 
> not terribly difficult, and will better posture you down the road in the 
> event that your requirements change, not to mention you can enforce 
> uniqueness at the database level. 
>
> -James
> On Jan 26, 2015 7:01 PM, "Bruce Li"  
> wrote:
>
>> To be more specific, I want the username and email in default user model 
>> both to be unique and not blank.
>>
>> On Tuesday, January 27, 2015 at 10:56:14 AM UTC+8, Bruce Li wrote:
>>>
>>> Hi,
>>>
>>> I want to build my user management based on default django users. But I 
>>> want emails to be unique as well. Is it possible to do that without the 
>>> need to create a custom user model and user managment?
>>>
>>>
>>> Thanks,
>>> - Bruce
>>>
>>  -- 
>> 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/e415b13a-2b38-4f1b-80e6-4ba808a09175%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/dd69dcdb-607c-4377-b5b4-b24d5a63d1a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: mark_safe and ValidationError params

2015-02-06 Thread Mike Dewhirst

On 7/02/2015 10:29 AM, Mike Dewhirst wrote:

How do I properly apply mark_safe to text passed to params of exceptions?


mark_safe returns a string-like object so if you embed it inside another 
string it might get missed. I think it is best to apply mark_safe when 
the return value won't be changed by other methods before being displayed.


Mike

--
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/54D54FBB.3080002%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: App for storing ChangeLogs in database

2015-02-06 Thread Russell Keith-Magee
On Fri, Feb 6, 2015 at 8:24 PM, Thomas Güttler  wrote:

> Hi,
>
> we want to make the changes in our applications better visible for our
> customers.
>
> We use several git repos:
>
>  - foo_customer: Here settings.py lives. It is quite small.
>
>  - foo_core: Central part of our application. The same code gets used for
> several customers.
>
>  - foo_plugin_bar: Just an example. There are several optional plugins.
>
> Here is my current road map:
>
> A nice interface for the customer implies: The changes need to be stored in
> the database. This makes it easy to sort and filter the changes.
>
> The origins of the changes are the git repos. I don't want to show
> the customer our commit messages. I want a manual step from
> commits to ChangeLog. But that's ok. This could be optimized later.
>
> Use Case: A developer merged a feature branch into foo_core.
> He needs to create a ChangeLog. The ChangeLog gets stored
> into the git repo, but on the next deploy some tool reads
> the new changes and puts them into the database.
>
> ChangeLogs need to be tag-able: You can apply tags like
> "performance-improvement"
> "new-feature" "bug-fix".
>
>
> I searched the web, but could not find something like this.
>
> Before I start to code, I want to get some feedback:
>
> What do you think?
>

To me - it sounds like something pretty closely tied to your own
development process, branching policies, and customer relationships. I have
no difficulty seeing how this could be implemented as a Django app - and a
fairly trivial one at that - your average change log is really not much
more than:

class Change(Model):
message = TextField()
created = DateTimeField()
change_type = IntegerField(choices=CHANGE_TYPES)

How do you handle your ChangeLogs.
>

Through a process that is completely unrelated to the commit process.

For me, minimising the number of customer communications is key. I have
difficulty getting users to read and comprehend the notifications I *do*
send them - sending them complete change logs would be overkill, and would
result in important messages (like YOU NEED TO UPDATE YOUR ACCOUNT SETTINGS
OR THINGS WILL STOP WORKING) being ignored. As it is, these messages are
often ignored, and I need to follow up with individual users.

My audience would gain nothing from a fine grained commit log telling them
about every bug fix or performance improvement. They just want the system
to work. If it doesn't work, they email me, and they'd like to know when it
is fixed. To that end, I might not even send out a notification for a new
*feature*, unless that feature is something that has been requested by
them, or it will impact on the way they're using the system.

Lets be clear, though - I'm not saying your approach is *wrong*. I'm just
saying it wouldn't work *for me*. You know your own users/customers better
than I do.

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/CAJxq849c2_W-kWxn1jRkmk87S6P6sj4_m2uC9KcBAnnhUM5PHg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: mark_safe and ValidationError params

2015-02-06 Thread Mike Dewhirst

On 7/02/2015 8:32 AM, Andrew Pinkham wrote:

I'm currently running Django 1.7.4. Provided the following clean function on a 
form:

 def clean_slug(self):
 new_slug = self.cleaned_data['slug'].lower()
 if new_slug == 'invalid_value':
 raise ValidationError(
 # _ is ugettext
 mark_safe(_('SlugField may not be '
   '"%(slug_value)s" '
   'for URL reasons.')),
 params={
 'slug_value':
 mark_safe('invalid_value')})
 return new_slug


Have you tried removing mark_safe from the body of the method and 
applying it at the end? ...


   return mark_safe(new_slug)

Mike




I expect the HTML error output to read:

 SlugField may not be create_list for URL 
reasons.

Instead, the HTML output is:

 SlugField may not be codecreate_list/code for 
URL reasons.

Meaning, the user sees the  tags as opposed to having them output as HTML.

The problem occurs when I remove the call to ugettext as well, and while I 
expect to only need to apply mark_safe to the value in params, I apply the 
function to all of the text above.

Am I doing something silly? How do I properly apply mark_safe to text passed to 
params of exceptions? What is the best-practice here?

Thanks,
Andrew

PS
I promise to add a code to my ValidationError before committing.



--
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/54D54E61.5000109%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: App for storing ChangeLogs in database

2015-02-06 Thread Mike Dewhirst
I don't have a solution for you but maybe you are just looking for 
strategies? Like you, I don't like showing users the commit messages.


We use Trac for our ticketing and insist no work gets done without a 
ticket. We added a custom field to Trac called "Release note". So when 
someone raises a ticket they are prompted to immediately write the 
release note they want to see when the work is eventually done and 
tagged for release.


I think this helps developers focus on what they have to deliver. If a 
user writes a ticket (we encourage that) the user writes the release 
note. Obviously it can be edited later if necessary.


The release notes for a tagged release can then be automated as a Trac 
page and the displayed application revision number can be made into a 
link to that page.


Works for me

Mike

On 6/02/2015 11:24 PM, Thomas Güttler wrote:

Hi,

we want to make the changes in our applications better visible for our
customers.

We use several git repos:

  - foo_customer: Here settings.py lives. It is quite small.

  - foo_core: Central part of our application. The same code gets used
for several customers.

  - foo_plugin_bar: Just an example. There are several optional plugins.

Here is my current road map:

A nice interface for the customer implies: The changes need to be stored in
the database. This makes it easy to sort and filter the changes.

The origins of the changes are the git repos. I don't want to show
the customer our commit messages. I want a manual step from
commits to ChangeLog. But that's ok. This could be optimized later.

Use Case: A developer merged a feature branch into foo_core.
He needs to create a ChangeLog. The ChangeLog gets stored
into the git repo, but on the next deploy some tool reads
the new changes and puts them into the database.

ChangeLogs need to be tag-able: You can apply tags like
"performance-improvement"
"new-feature" "bug-fix".


I searched the web, but could not find something like this.

Before I start to code, I want to get some feedback:

What do you think?

How do you handle your ChangeLogs.

PS: Our customers are normal (non programmers) people. They
don't want to see diffs or commit messages they don't understand.






--
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/54D54BDC.5090103%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


FormWizard, FileField and going back

2015-02-06 Thread Roodie
Hey all,

I've run into a strange problem. I have a rather large model for a school 
application process. I am using the FormWizard feature with a 
SessionWizardView and 3 ModelForms to present the entry fields in 
manageable chunks. Everything is working properly, except the 3 FileFields. 
The FormWizard saves the uploaded pdf files correctly, but if I advance to 
the next step and then I go back to the previous step where the FileFields 
are, they are empty. If I re-submit the form, the files are still there and 
they will be stored when I save instance at the last step.

I am using the latest 1.6.x version of Django.

I found a similar quesion on StackOverflow 
(http://stackoverflow.com/questions/10597021/formwizard-and-filefields-django-1-4)
 
but it is not working for me.

Any ideas?

Thanks!

--
Roodie

   

-- 
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/e14bda54-54c4-409b-8585-4a3e27dba0de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


mark_safe and ValidationError params

2015-02-06 Thread Andrew Pinkham
I'm currently running Django 1.7.4. Provided the following clean function on a 
form:

def clean_slug(self):
new_slug = self.cleaned_data['slug'].lower()
if new_slug == 'invalid_value':
raise ValidationError(
# _ is ugettext 
mark_safe(_('SlugField may not be '
  '"%(slug_value)s" '
  'for URL reasons.')),
params={
'slug_value':
mark_safe('invalid_value')})
return new_slug


I expect the HTML error output to read:

SlugField may not be create_list for URL 
reasons.

Instead, the HTML output is: 

SlugField may not be codecreate_list/code 
for URL reasons.

Meaning, the user sees the  tags as opposed to having them output as HTML.

The problem occurs when I remove the call to ugettext as well, and while I 
expect to only need to apply mark_safe to the value in params, I apply the 
function to all of the text above.

Am I doing something silly? How do I properly apply mark_safe to text passed to 
params of exceptions? What is the best-practice here?

Thanks,
Andrew

PS
I promise to add a code to my ValidationError before committing.

-- 
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/A9EEE119-BF44-48DE-8AEE-E511AEB0F544%40andrewsforge.com.
For more options, visit https://groups.google.com/d/optout.


Re: admin shows `model name` object instead of values for foreign key fields

2015-02-06 Thread Larry Martell
On Fri, Feb 6, 2015 at 4:06 PM, Daniel Roseman 
wrote:

> On Friday, 6 February 2015 20:30:02 UTC, larry@gmail.com wrote:
>>
>> I have a 1.7 app, and in admin when I reference a foreign key field,
>> instead of showing the values in the drop down, it shows "`model name`
>> object":
>>
>>
>
>> How can I get it show the values from the IPGroups table? I'm sure I'm
>> doing something simple and stupid wrong, but I can't see it.
>>
>> Thanks!
>>
>
> You haven't defined a `__unicode__` method (or `__str__` on Python3) on
> the IPGroups model..
>

Thank you very much Daniel.

-- 
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/CACwCsY77AoXKjbH-Cfscu-vugXkr%2BXmpDqbdhRsJzyXdCiecVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: admin shows `model name` object instead of values for foreign key fields

2015-02-06 Thread Daniel Roseman
On Friday, 6 February 2015 20:30:02 UTC, larry@gmail.com wrote:
>
> I have a 1.7 app, and in admin when I reference a foreign key field, 
> instead of showing the values in the drop down, it shows "`model name` 
> object":
>
>  

> How can I get it show the values from the IPGroups table? I'm sure I'm 
> doing something simple and stupid wrong, but I can't see it.
>
> Thanks!
>

You haven't defined a `__unicode__` method (or `__str__` on Python3) on the 
IPGroups model..
--
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/b7a9e67c-9d71-4a22-b144-315f7f38a992%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


admin shows `model name` object instead of values for foreign key fields

2015-02-06 Thread Larry Martell
I have a 1.7 app, and in admin when I reference a foreign key field,
instead of showing the values in the drop down, it shows "`model name`
object":

[image: Inline image 2]
This does not happen in 1.5 (in a different app).

Here are my models:

class IPGroups(models.Model):
groupName = models.CharField(max_length=20)

class AllowedIPs(models.Model):
ip = models.CharField(max_length=15)
group = models.ForeignKey(IPGroups)

Here is my admin code:

class IPGroupsAdmin(admin.ModelAdmin):
list_display = ('groupName',)
list_filter = ('groupName',)
admin.site.register(IPGroups, IPGroupsAdmin)

class AllowedIPsAdmin(admin.ModelAdmin):
list_display = ('ip', 'group')
list_filter = ('ip', 'group')
admin.site.register(AllowedIPs, AllowedIPsAdmin)

How can I get it show the values from the IPGroups table? I'm sure I'm
doing something simple and stupid wrong, but I can't see it.

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/CACwCsY42HrMRhoX-9xvBDfU5BrvKxSwnrKZTfAApKkOgQGsnWw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Strange error with reverse() when running tests

2015-02-06 Thread João Sampaio
Oh, I totally overlooked that! Thank you.

On Friday, February 6, 2015 at 12:10:15 PM UTC-3, Daniel Roseman wrote:
>
>
>
> On Thursday, 5 February 2015 12:34:51 UTC, João Sampaio wrote:
>>
>> There are 3 Python files attached.
>>
>> I have my URL file attached. I'm using django-rest-framework (in case you 
>> are wondering what the routers are). When I use ./manage.py test with the 
>> first file (file1.py), the tests succeed. When I do the very same thing 
>> with the second file, the tests fail. The only thing changed between the 
>> files is the addition of this code:
>>
>> def test_update_member_phone_number(self):
>> member = self.create_national_team_member()
>>
>> url = reverse(r'nationalteam-member-phone-number',
>>   kwargs={r'pk': member.id})
>>
>> The error is this one:
>>
>> ==
>> ERROR: test_update_member_picture (main.tests.test_national_team.
>> NationalTeamTestCase)
>> --
>> Traceback (most recent call last):
>>   File 
>> "/home/jpmelos/devel/ideation_admin/ideation_admin/main/tests/test_national_team.py"
>> , line 177, in test_update_member_picture
>> kwargs={r'pk': member.id})
>>   File 
>> "/home/jpmelos/devel/ideation_admin/venv/lib/python2.7/site-packages/django/core/urlresolvers.py"
>> , line 551, in reverse
>> return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, 
>> **kwargs))
>>   File 
>> "/home/jpmelos/devel/ideation_admin/venv/lib/python2.7/site-packages/django/core/urlresolvers.py"
>> , line 468, in _reverse_with_prefix
>> (lookup_view_s, args, kwargs, len(patterns), patterns))
>>
>> NoReverseMatch: Reverse for 'nationalteam-member-update-picture' with 
>> arguments '()' and keyword arguments '{'pk': 10}' not found. 1 pattern(s) 
>> tried: ['national-team/(?P\\d)/update_picture/$']
>>
>> As you can see in the exception text, the pattern does seem to match. The 
>> error seems to happen in a test method that is not even related to the one 
>> added to the tests. What is going on? It doesn't make any sense to me. How 
>> come the mere addition of a call to reverse can cause the tests to crash?
>>
>
>
> Your regex does *not* match: it only accepts a single digit for pk, but 
>  you are passing a two-digit number (10). Modify your regexes to `
> (?P\d+)`.
> --
> 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/57699dbc-59ff-4722-85b6-070311e59484%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


static files with query strings

2015-02-06 Thread Mark Mikofski
Do I need to make a custom storage or custom template to handle query 
strings in static file URLs or endpoints?

Using the new static template in Django>=1.4 works fine for simple 
endpoints and URLs

For example, the following works fine:

{% load staticfiles %}












However if the ULR or endpoint of the static argument contains a query 
string then it gets URLencoded and then the query doesn't work.

For example, this doesn't work:

{% load staticfiles %}




because the "?" turns into "%3" and the "=" turns into "%3D" and then the js 
doesn't run.


BTW: I know that there is a MathJax Django extension 
(https://pypi.python.org/pypi/django-mathjax/0.0.5) but I want to understand 
how to correctly handle this issue for any URL.


I have seen examples for installing custom storage for s3 which appends the 
signature to the static URL 
(https://django-storages.readthedocs.org/en/latest/index.html) but AFAICT this 
topic wasn't addressed in the main Django documentation.


Is the answer as simple as subclassing StaticFilesStorage 
(https://docs.djangoproject.com/en/1.7/ref/contrib/staticfiles/#staticfiles-storages)
 and overloading the Storage.url() method?


Or is a better path to do what the mathjax django extension does and make a 
totally different template?


Or am I using the wrong static template? IE {% load static %} instead of {% 
load staticfiles %}?


Is there any harm in using {{ STATIC_URL }} instead of the newer static 
template {% get_static_prefix %}?


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/26b996f2-301f-4824-8673-54bc1fc88106%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to access json data value(s) returned back to django view from 'GET' request to an api

2015-02-06 Thread Henry Versemann
Thanks Larry.

On Thursday, February 5, 2015 at 1:17:37 PM UTC-6, larry@gmail.com 
wrote:
>
> On Thu, Feb 5, 2015 at 2:10 PM, Henry Versemann  > wrote: 
> > I have a django view (django v. 1.7 ; python v. 2.7.8) which currently 
> and 
> > successfully sends a request to an api, and receives a good response 
> back. 
> > I'm sending and receiving using the 'requests' library (v. 2.4.3). Now 
> in 
> > addition to sending the raw response data back in an HttpResponse I 
> would 
> > also like to strip out some of the data and create a summary report of 
> it, 
> > to also send back in my HttpResponse. 
> > 
> > I can see the good response data from the request in my command prompt 
> > window, and it contains a list of items inside of the object to which 
> I've 
> > assigned the response data. So my question is how do I get at the list 
> of 
> > items that has been returned back to me as well as all of the data 
> > (key/value pairs) contained in each list item? 
> > 
> > I'm sure there must be some kind of conversion process that I have to 
> run 
> > the raw response data through. I just haven't out what it is yet. 
> > 
> > I've never tried to do this before, from within a django view. If I were 
> > trying to do this on the client side I would use something like this: 
> > 
> >   mydata = jQuery.parseJSON(data); 
> > 
> > to make the data accessible, but never having done anything like this 
> before 
> > on the server side I haven't found anything yet that's been useful or 
> has 
> > worked. 
> > 
> > I would appreciate any help anyone can offer, while I continue to search 
> for 
> > an answer. 
>
> See: https://docs.python.org/3.3/library/json.html 
>
> e.g.: 
>
> import json 
> jsonIn = json.loads(request.POST['json_content']) 
>

-- 
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/9ac36742-6c5d-43e7-a33e-93f06b46f9aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: amazon s3 and django - Allow only the users from my website and not the anonymous users

2015-02-06 Thread Nikolas Stevenson-Molnar
It sounds like you want to use signed URLs. Since you're using storages, 
this should be the default if you use the "url" property. E.g.,


signed_url = status_obj.image.url

Then keep the file itself private. No one will be able to access it 
without a signed URL, and you can control who gets a signed URL in your 
Django app.


_Nik

On 2/6/2015 7:51 AM, Kakar Nyori wrote:

I am using amazon s3 to store uploaded user images. My problems are:

- If I permit or grantee for me, I cannot upload or download the contents.
- If I permit or grantee for everyone, all the users and (especially) 
anonymous users will be able to see the contents, which I don't want.


So, my question is, what do I do so that only the users from my 
website can upload, download and delete the content?


In that I have conditions that:

 1. Only the users (user1, user2, user3, ...) who are following the user
(user0) can download/view the content?
 2. Only the user who uploaded the view can delete the content.

models.py:

*def get_upload_file_name(instance, filename):*
*return "uploaded_files/%s_%s" %(str(time()).replace('.','_'), filename)*
*
*
*PRIVACY = (*
*('H','Hide'),*
*('F','Followers'),*
*('A','All'),*
*)*
*
*
*class Status(models.Model):*
*body = models.TextField(max_length=200)*
*image = models.ImageField(blank=True, null=True, 
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)*

*user = models.ForeignKey(User)*

settings.py:

*DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'*
*
*
*AWS_ACCESS_KEY_ID = 'AKIAJQWEN46SZLYWFDMMA'*
*
*
*AWS_SECRET_ACCESS_KEY = '2COjFM30gC+rty571E8eNSDYnTdV4cE3aEd1iFTH'*
*
*
*AWS_STORAGE_BUCKET_NAME = 'yesme'*
--
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/cbc5c0d5-cc42-4a67-9414-2fb74fceed1e%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/54D4FCDA.3030207%40consbio.org.
For more options, visit https://groups.google.com/d/optout.


Re: how to access json data value(s) returned back to django view from 'GET' request to an api

2015-02-06 Thread Henry Versemann
Scot, Thanks for the reply. OK I've gotten down to the point to where I 
have my version of your json_data in your code below, but I'm not sure I 
understand exactly what your code is doing, after you have the json_data 
variable contents. In my case the first object of response data that I'm 
trying to use is a list of two items, with each item containing multiple 
keys and internal or sub objects within them. 
Can you please explain your code after you have the json_data variable 
formatted further? I'm guessing you're doing some kind of further required 
conversion of the data, and if so I'm not sure I understand why those 
conversions are necessary and being done.
My current piece of response data that I'm trying to work with looks like 
this(when I print it in my command prompt window):


[
{
u'status': u'complete', 
u'parameters': 
{
u'enrollment_term_id': u'', 
u'extra_text': u'Term: All Terms;'
}, 
u'file_url': 
u'https://stchas.test.instructure.com/accounts/1/files/7787/download', 
u'attachment': 
{
u'display_name': 
u'grade_export_csv_10_Feb_2014_40_18363-0.csv', 
u'unlock_at': None, 
u'url': 
u'https://stchas.test.instructure.com/files/7787/download?download_frd=1=nEU8FRMgfMaCFUK0NoIXiGMaQj0M
xWWJ4BM7PrMU', 
u'created_at': u'2014-02-10T15:26:24Z', 
u'updated_at': u'2014-02-10T15:26:24Z', 
u'filename': 
u'1392045984_664__grade_export_csv_10_Feb_2014_40_18363-0.csv', 
u'lock_at': None, 
u'thumbnail_url': None, 
u'hidden_for_user': False, 
u'locked': False, 
u'hidden': False, 
u'locked_for_user': False, 
u'content-type': u'text/csv', 
u'id': 7787, 
u'size': 4744
}, 
u'report': u'grade_export_csv', 
u'progress': 100, 
u'id': 40
}, 
{
u'status': u'complete', 
u'parameters': 
{
u'enrollment_term_id': u'', 
u'extra_text': u'Term: All Terms;'
}, 
u'file_url': 
u'https://stchas.test.instructure.com/accounts/1/files/1033/download', 
u'attachment': 
{
u'display_name': u'grade_export_csv_22_Oct_2013_2_27551-0.csv', 
u'unlock_at': None, 
u'url': 
u'https://stchas.test.instructure.com/files/1033/download?download_frd=1=uhw0oyfb0f3m4GtgJAVvwQkRlDfK0kCbg200SIu4',
 

u'created_at': u'2013-10-22T19:15:45Z', 
u'updated_at': u'2013-10-22T19:15:45Z', 
u'filename': u'grade_export_csv_22_Oct_2013_2_27551-0.csv', 
u'lock_at': None, 
u'thumbnail_url': None, 
u'hidden_for_user':False, 
u'locked': False, 
u'hidden': False, 
u'locked_for_user': False, 
u'content-type': u'text/csv', 
u'id': 1033, 
u'size': 395
}, 
u'report': u'grade_export_csv',
u'progress': 100, 
u'id': 2
}
]

So far I've tried to access the objects inside the list like I normally 
would in python using indexing for the list items like this:

lstobjct = rspnslist[index]

but so far all I've gotten from this is an "exceptions.AttributeError". 

Thanks again for the help.  

On Friday, February 6, 2015 at 9:54:03 AM UTC-6, Scot Hacker wrote:

> On Thursday, February 5, 2015 at 11:10:32 AM UTC-8, Henry Versemann wrote:
>>
>> I have a django view (django v. 1.7 ; python v. 2.7.8) which currently 
>> and successfully sends a request to an api, and receives a good response 
>> back. I'm sending and receiving using the 'requests' library (v. 2.4.3). 
>> Now in addition to sending the raw response data back in an HttpResponse I 
>> would also like to strip out some of the data and create a summary report 
>> of it, to also send back in my HttpResponse.
>>
> What Larry said - you need to convert the javascript data format into a 
> python data format. json.loads() will do that for you. Here's a working 
> example: 
>
>
> import json
>
> def get_nyt_news():
> # NYT API data
> response = requests.get(
> '
> http://api.nytimes.com/svc/mostpopular/v2/mostshared/all-sections/7.json?api-key={apikey}'.format(apikey=settings.NYT_API_KEY)
> )
>
> json_data = json.loads(response.text)
> data = json_data['results'][0:4]
>
> # Rewrite data to conform internal links
> for d in data:
> d['get_absolute_url'] = d['url']
>
> return {'object_list': data}
>
>

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

Re: how to access json data value(s) returned back to django view from 'GET' request to an api

2015-02-06 Thread Scot Hacker
On Thursday, February 5, 2015 at 11:10:32 AM UTC-8, Henry Versemann wrote:
>
> I have a django view (django v. 1.7 ; python v. 2.7.8) which currently and 
> successfully sends a request to an api, and receives a good response back. 
> I'm sending and receiving using the 'requests' library (v. 2.4.3). Now in 
> addition to sending the raw response data back in an HttpResponse I would 
> also like to strip out some of the data and create a summary report of it, 
> to also send back in my HttpResponse.
>
What Larry said - you need to convert the javascript data format into a 
python data format. json.loads() will do that for you. Here's a working 
example: 


import json

def get_nyt_news():
# NYT API data
response = requests.get(

'http://api.nytimes.com/svc/mostpopular/v2/mostshared/all-sections/7.json?api-key={apikey}'.format(apikey=settings.NYT_API_KEY)
)

json_data = json.loads(response.text)
data = json_data['results'][0:4]

# Rewrite data to conform internal links
for d in data:
d['get_absolute_url'] = d['url']

return {'object_list': data}

-- 
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/b7300a03-2200-485f-9d4e-227f08cef92d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


amazon s3 and django - Allow only the users from my website and not the anonymous users

2015-02-06 Thread Kakar Nyori
I am using amazon s3 to store uploaded user images. My problems are:

- If I permit or grantee for me, I cannot upload or download the contents.
- If I permit or grantee for everyone, all the users and (especially) 
anonymous users will be able to see the contents, which I don't want.

So, my question is, what do I do so that only the users from my website can 
upload, download and delete the content? 

In that I have conditions that:

 1. Only the users (user1, user2, user3, ...) who are following the user
(user0) can download/view the content?
 2. Only the user who uploaded the view can delete the content.

models.py:

*def get_upload_file_name(instance, filename):*
*return "uploaded_files/%s_%s" %(str(time()).replace('.','_'), 
filename)*

*PRIVACY = (*
*('H','Hide'),*
*('F','Followers'),*
*('A','All'),*
*)*

*class Status(models.Model):*
*body = models.TextField(max_length=200)*
*image = models.ImageField(blank=True, null=True, 
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)*
*user = models.ForeignKey(User)*

settings.py:

* DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'*

* AWS_ACCESS_KEY_ID = 'AKIAJQWEN46SZLYWFDMMA'*

* AWS_SECRET_ACCESS_KEY = '2COjFM30gC+rty571E8eNSDYnTdV4cE3aEd1iFTH'*

* AWS_STORAGE_BUCKET_NAME = 'yesme'*

-- 
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/cbc5c0d5-cc42-4a67-9414-2fb74fceed1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Strange error with reverse() when running tests

2015-02-06 Thread Daniel Roseman


On Thursday, 5 February 2015 12:34:51 UTC, João Sampaio wrote:
>
> There are 3 Python files attached.
>
> I have my URL file attached. I'm using django-rest-framework (in case you 
> are wondering what the routers are). When I use ./manage.py test with the 
> first file (file1.py), the tests succeed. When I do the very same thing 
> with the second file, the tests fail. The only thing changed between the 
> files is the addition of this code:
>
> def test_update_member_phone_number(self):
> member = self.create_national_team_member()
>
> url = reverse(r'nationalteam-member-phone-number',
>   kwargs={r'pk': member.id})
>
> The error is this one:
>
> ==
> ERROR: test_update_member_picture (main.tests.test_national_team.
> NationalTeamTestCase)
> --
> Traceback (most recent call last):
>   File 
> "/home/jpmelos/devel/ideation_admin/ideation_admin/main/tests/test_national_team.py"
> , line 177, in test_update_member_picture
> kwargs={r'pk': member.id})
>   File 
> "/home/jpmelos/devel/ideation_admin/venv/lib/python2.7/site-packages/django/core/urlresolvers.py"
> , line 551, in reverse
> return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, 
> **kwargs))
>   File 
> "/home/jpmelos/devel/ideation_admin/venv/lib/python2.7/site-packages/django/core/urlresolvers.py"
> , line 468, in _reverse_with_prefix
> (lookup_view_s, args, kwargs, len(patterns), patterns))
>
> NoReverseMatch: Reverse for 'nationalteam-member-update-picture' with 
> arguments '()' and keyword arguments '{'pk': 10}' not found. 1 pattern(s) 
> tried: ['national-team/(?P\\d)/update_picture/$']
>
> As you can see in the exception text, the pattern does seem to match. The 
> error seems to happen in a test method that is not even related to the one 
> added to the tests. What is going on? It doesn't make any sense to me. How 
> come the mere addition of a call to reverse can cause the tests to crash?
>


Your regex does *not* match: it only accepts a single digit for pk, but 
 you are passing a two-digit number (10). Modify your regexes to `
(?P\d+)`.
--
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/68d809f4-341e-4b10-91df-4ae102720256%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Login in all pages

2015-02-06 Thread Nelson Varela
Take a look at middleware.

You can create a middleware which runs for every request. In 'process_request' 
you can check if the user is authenticated. If not... show or redirect to the 
login view.

The advantage is that you don't have to worry about placing decorators above 
your views.

-- 
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/bb02623a-2439-4c51-b05d-9f0f1bc2a78a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


App for storing ChangeLogs in database

2015-02-06 Thread Thomas Güttler

Hi,

we want to make the changes in our applications better visible for our 
customers.

We use several git repos:

 - foo_customer: Here settings.py lives. It is quite small.

 - foo_core: Central part of our application. The same code gets used for 
several customers.

 - foo_plugin_bar: Just an example. There are several optional plugins.

Here is my current road map:

A nice interface for the customer implies: The changes need to be stored in
the database. This makes it easy to sort and filter the changes.

The origins of the changes are the git repos. I don't want to show
the customer our commit messages. I want a manual step from
commits to ChangeLog. But that's ok. This could be optimized later.

Use Case: A developer merged a feature branch into foo_core.
He needs to create a ChangeLog. The ChangeLog gets stored
into the git repo, but on the next deploy some tool reads
the new changes and puts them into the database.

ChangeLogs need to be tag-able: You can apply tags like 
"performance-improvement"
"new-feature" "bug-fix".


I searched the web, but could not find something like this.

Before I start to code, I want to get some feedback:

What do you think?

How do you handle your ChangeLogs.

PS: Our customers are normal (non programmers) people. They
don't want to see diffs or commit messages they don't understand.




--
Thomas Güttler
http://thomas-guettler.de/

--
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/54D4B260.8030402%40tbz-pariv.de.
For more options, visit https://groups.google.com/d/optout.