Re: models, peeking to next record - maybe

2015-02-07 Thread Vijay Khemlani
The direct solution would be something like this in your view

events = Event.objects.order_by('event_date')

event_tuples = []
last_date_seen = None

for event in events:
if last_date_seen:
date_difference = event.date - last_date_seen
else:
date_difference = None

event_tuples.push((event, date_difference))

(date_difference would be a timedelta object)

On Sat, Feb 7, 2015 at 10:02 PM, Lachlan Musicman  wrote:

> My initial suggestion would be to utilise the "order by" option, and
> order by date.
>
> Then, on each model have a find_next function and a until_next function.
>
> The first would work out which was the next event, the other the time.
> They could be coupled, but keeping them separate means you can utilise
> them later if you need to.
>
> cheers
> L.
> --
> "This is a profound psychological violence here. How can one even
> begin to speak of dignity in labor when one secretly feels one's job
> should not exist?"
>
> On the Phenomenon of Bullshit Jobs, David Graeber
> http://strikemag.org/bullshit-jobs/
>
>
> On 8 February 2015 at 09:40, Richard Bowden  wrote:
> > Got an problem that I am struggling to solve..
> >
> > I have:
> >
> > class Address(models.Model):
> > name = models.CharField()
> > event_date = models.DateTime()
> >
> >
> > event1, 25/01/2015
> > event2, 27/01/2015
> > event3, 05/02/2015
> >
> > and so on…
> >
> > what I am trying to figure out is, how to calculate the days between each
> > event.
> >
> > so event2, would be 2 days, event3 would be 9 days etc.
> >
> > want to end up with something like this that is passed to the template
> > event1, 25/01/2015
> > event2, 27/01/2015, 2
> > event3, 05/02/2015, 9
> >
> >
> > its the mechanics I am having trouble working out, my initial though was
> to
> > have a def on the model that accepted a datetime object. Somehow in a
> loop i
> > would get the diatomite from the next event and pass it in and calc days
> on
> > self.event_date… cant think how to do it.
> >
> > has anyone else needed something like this? or am I thinking about it
> > wrong..
> >
> > 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/63b0691e-34b1-4634-bf29-640583f22bae%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/CAGBeqiOF4-or%3DWY4DGbsQY1eFUY0bKR09sTVED9dEUc6tNUY9Q%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/CALn3ei1g-gMx6cqvQ9in8vq%2BkhLd9d6ccHefWKxba-vwpeW9KA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: models, peeking to next record - maybe

2015-02-07 Thread Lachlan Musicman
My initial suggestion would be to utilise the "order by" option, and
order by date.

Then, on each model have a find_next function and a until_next function.

The first would work out which was the next event, the other the time.
They could be coupled, but keeping them separate means you can utilise
them later if you need to.

cheers
L.
--
"This is a profound psychological violence here. How can one even
begin to speak of dignity in labor when one secretly feels one's job
should not exist?"

On the Phenomenon of Bullshit Jobs, David Graeber
http://strikemag.org/bullshit-jobs/


On 8 February 2015 at 09:40, Richard Bowden  wrote:
> Got an problem that I am struggling to solve..
>
> I have:
>
> class Address(models.Model):
> name = models.CharField()
> event_date = models.DateTime()
>
>
> event1, 25/01/2015
> event2, 27/01/2015
> event3, 05/02/2015
>
> and so on…
>
> what I am trying to figure out is, how to calculate the days between each
> event.
>
> so event2, would be 2 days, event3 would be 9 days etc.
>
> want to end up with something like this that is passed to the template
> event1, 25/01/2015
> event2, 27/01/2015, 2
> event3, 05/02/2015, 9
>
>
> its the mechanics I am having trouble working out, my initial though was to
> have a def on the model that accepted a datetime object. Somehow in a loop i
> would get the diatomite from the next event and pass it in and calc days on
> self.event_date… cant think how to do it.
>
> has anyone else needed something like this? or am I thinking about it
> wrong..
>
> 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/63b0691e-34b1-4634-bf29-640583f22bae%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/CAGBeqiOF4-or%3DWY4DGbsQY1eFUY0bKR09sTVED9dEUc6tNUY9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


models, peeking to next record - maybe

2015-02-07 Thread Richard Bowden
Got an problem that I am struggling to solve..

I have:

class Address(models.Model):
name = models.CharField()
event_date = models.DateTime()


event1, 25/01/2015
event2, 27/01/2015
event3, 05/02/2015

and so on…

what I am trying to figure out is, how to calculate the days between each 
event.

so event2, would be 2 days, event3 would be 9 days etc.

want to end up with something like this that is passed to the template
event1, 25/01/2015
event2, 27/01/2015, 2
event3, 05/02/2015, 9


its the mechanics I am having trouble working out, my initial though was to 
have a def on the model that accepted a datetime object. Somehow in a loop 
i would get the diatomite from the next event and pass it in and calc days 
on self.event_date… cant think how to do it.

has anyone else needed something like this? or am I thinking about it 
wrong..

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/63b0691e-34b1-4634-bf29-640583f22bae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


models, peeking to next record - maybe

2015-02-07 Thread Richard Bowden
I am working on a problem that I am trying to figure out, not having much 
luck so far...


I have a model, basic for this example:

class Event(models.Model):

name = models.Charfield(max_length=10)
event_date = models.DateTime()



I am trying to workout how I can calculate the number of days between each 
event, the query set would be orders by event_date

event1, 26/01/2015
event2, 29/01/2015
event3, 03/02/2015

so event 2 would be 3 days and event 3 would be 5 days and so on.

my idea was to have a model def that accepted a datetime from the previous 
record which would calc the days against the self.event_date

its the mechanics of peeking at the next / previous record in a 
queryset...i am struggling with, not sure how to proceed with this 
problem

has anyone seen this before, or am I thinking about wrong ?

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/e70aaa9a-cc2d-41a3-9333-e82618a5a50f%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-07 Thread Henry Versemann
Scot, Thanks for the response. I will try it first thing Monday morning. If 
I have any other questions I may post them then, but this should get most 
of it for me. Thanks again. Henry

On Saturday, February 7, 2015 at 1:35:39 AM UTC-6, Scot Hacker wrote:
>
> 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/5a3b2690-9bfa-4ac9-9a16-76390a5b63ee%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-07 Thread JSON CSV


On Friday, February 6, 2015 at 5:10:32 AM UTC+10, 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.
>
>
>
In case you want to do ad-hoc reports based on JSON data - you may find it 
useful to upload the JSON data to our website https://json-csv.com.  A 
spreadsheet is produced from the API which you can use in Excel to chart on 
/ summarize etc.

-- 
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/b68fa69f-fe11-4ed7-a447-5b8f5492f1cd%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-07 Thread Kakar Nyori
Hello,
thank you for the response. Could you please give an example as to how to 
do that above mentioned?
Thank you.

On Friday, February 6, 2015 at 11:10:50 PM UTC+5:30, Nikolas 
Stevenson-Molnar wrote:
>
>  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...@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/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/b62f01f0-c775-4b8a-afe8-4d6da8e4a351%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Login in all pages

2015-02-07 Thread Scot Hacker


On Thursday, February 5, 2015 at 5:35:09 AM UTC-8, Juan Diego Gonzalez 
wrote:
>
> Hi, I need to put the django login feature in all pages, I mean, the user 
> will be able to login in the reserved area of the web from any public page.
>
>
Install django-stronghold or similar.
https://github.com/mgrouchy/django-stronghold

That'll lock down the entire site to registered users only. You can exempt 
any URLs that need to  be publicly accessible.

./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/efe9a984-e413-46e3-ab8b-20bf90c8f592%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.