Ignore authentication on a single list_route within ViewSet?

2017-01-04 Thread Dan
Hi everyone,


I am trying to figure out how to remove authentication from a single view 
within a ViewSet. I essentially want this endpoint to be public, but not 
effect any other view in here.

In settings.py I have:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'oauth2_provider.ext.rest_framework.OAuth2Authentication',
),

'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),...
}


My ViewSet is just a basic viewsets.ViewSet with no decorators or variables 
being modified on the class.

In this ViewSet I have the following view:
@list_route(methods=['GET'], url_path='package/(?P[^\/]+)')
def get_package(self, request, package_id):


I have tried just about every possible combination 
of @authentication_classes() and @permission_classes() decorators, trying 
different orders too, and no matter what I get:
{
  "detail": "Authentication credentials were not provided."
}

I've even tried making my own authentication class:
class NoAuthentication(BaseAuthentication):
def authenticate(self, request):
return True


def authenticate_header(self, request):
pass

And then using it as such:
@list_route(methods=['GET'], url_path='package/(?P[^\/]+)')
@authentication_classes([NoAuthentication, ])
@permission_classes([AllowAny, ])
def get_package(self, request, package_id):
Which does a whole lot of nothing.


Removing this view from the ViewSet is a last resort as I'd rather not have 
to hard-code a URL that mimics the ViewSet's route. I would really like to 
know why I can't disable auth on a single view.


Any help here would be much appreciated!


Thanks
Dan

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


Re: Django Rest Framework Temperature Data Querying

2017-01-04 Thread Marco Silva
On a custom serializer field, (eg SerializerMethodField) use the django
aggregate functions for max and min
https://docs.djangoproject.com/en/1.10/topics/db/aggregation/

On Wed, 4 Jan 2017, 11:59 Burak Özdemir,  wrote:

> There are lots of temperature data for one day. For instance, there are
> nearly 5000 records for 03 January. I want to get highest and lowest of
> these records for one specific day.
>
> 4 Ocak 2017 Çarşamba 14:43:55 UTC+3 tarihinde Marco Silva yazdı:
>
> Actually, I  think he wants a custom serializer that has one of 2 get
> arguments(start and end date) and then generates the desired json with
> fields using the django aggregate methods
>
> On Tue, 3 Jan 2017, 22:43 gordon,  wrote:
>
> List_route or detail route decorators sounds like what you are looking for
> http://www.django-rest-framework.org/api-guide/viewsets/#marking-extra-actions-for-routing
>
> On Jan 3, 2017 5:09 AM, "Burak Özdemir"  wrote:
>
> I want to create an API endpoint for daily temperatures.(highest and
> lowest tempereture of a day).
>
> 3 Ocak 2017 Salı 13:06:03 UTC+3 tarihinde Marco Silva yazdı:
>
> What exactly do you need help in?
>
>
> segunda-feira, 2 de Janeiro de 2017 às 22:16:24 UTC, Burak Özdemir
> escreveu:
>
> My sensor measures the temperature value every 5 seconds and records it to
> the database. I want to see the highest and lowest temperature of every
> recorded day via API. It should be like that(for instance, values are not
> correct):
> 
>
> The modal:
>
> class SensorModel(models.Model):
> measurementTime = models.DateTimeField()
> ldr = models.IntegerField()
> temperature = models.IntegerField()
> humidity = models.IntegerField()
>
> class Meta:
> ordering = ['measurementTime']
>
> def __unicode__(self):
> return str(self.id)
>
>
>
> Database:
>
> 
>
> Current API:
>
> 
>
> Thanks in advance.
>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-rest-framework+unsubscr...@googlegroups.com.
>
>
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django REST framework" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-rest-framework/bhGJR4tndMc/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> django-rest-framework+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django REST framework" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-rest-framework/bhGJR4tndMc/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> django-rest-framework+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Django Rest Framework Temperature Data Querying

2017-01-04 Thread Burak Özdemir
There are lots of temperature data for one day. For instance, there are 
nearly 5000 records for 03 January. I want to get highest and lowest of 
these records for one specific day.

4 Ocak 2017 Çarşamba 14:43:55 UTC+3 tarihinde Marco Silva yazdı:
>
> Actually, I  think he wants a custom serializer that has one of 2 get 
> arguments(start and end date) and then generates the desired json with 
> fields using the django aggregate methods
>
> On Tue, 3 Jan 2017, 22:43 gordon,  wrote:
>
>> List_route or detail route decorators sounds like what you are looking 
>> for 
>> http://www.django-rest-framework.org/api-guide/viewsets/#marking-extra-actions-for-routing
>>
>> On Jan 3, 2017 5:09 AM, "Burak Özdemir" > > wrote:
>>
>>> I want to create an API endpoint for daily temperatures.(highest and 
>>> lowest tempereture of a day).
>>>
>>> 3 Ocak 2017 Salı 13:06:03 UTC+3 tarihinde Marco Silva yazdı:

 What exactly do you need help in?


 segunda-feira, 2 de Janeiro de 2017 às 22:16:24 UTC, Burak Özdemir 
 escreveu:
>
> My sensor measures the temperature value every 5 seconds and records 
> it to the database. I want to see the highest and lowest temperature of 
> every recorded day via API. It should be like that(for instance, values 
> are 
> not correct):  
> 
>
> The modal:
>
> class SensorModel(models.Model):
> measurementTime = models.DateTimeField()
> ldr = models.IntegerField()
> temperature = models.IntegerField()
> humidity = models.IntegerField()
>
> class Meta:
> ordering = ['measurementTime']
>
> def __unicode__(self):
> return str(self.id)
>
>
>
> Database:
>
> 
>
> Current API: 
>
> 
>
> Thanks in advance.
>
>
> -- 
>>>
>> You received this message because you are subscribed to the Google Groups 
>>> "Django REST framework" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-rest-framework+unsubscr...@googlegroups.com 
>>> .
>>
>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Django REST framework" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/django-rest-framework/bhGJR4tndMc/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to 
>> django-rest-framework+unsubscr...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

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


Re: Django Rest Framework Temperature Data Querying

2017-01-04 Thread Marco Silva
Actually, I  think he wants a custom serializer that has one of 2 get
arguments(start and end date) and then generates the desired json with
fields using the django aggregate methods

On Tue, 3 Jan 2017, 22:43 gordon,  wrote:

> List_route or detail route decorators sounds like what you are looking for
> http://www.django-rest-framework.org/api-guide/viewsets/#marking-extra-actions-for-routing
>
> On Jan 3, 2017 5:09 AM, "Burak Özdemir"  wrote:
>
> I want to create an API endpoint for daily temperatures.(highest and
> lowest tempereture of a day).
>
> 3 Ocak 2017 Salı 13:06:03 UTC+3 tarihinde Marco Silva yazdı:
>
> What exactly do you need help in?
>
>
> segunda-feira, 2 de Janeiro de 2017 às 22:16:24 UTC, Burak Özdemir
> escreveu:
>
> My sensor measures the temperature value every 5 seconds and records it to
> the database. I want to see the highest and lowest temperature of every
> recorded day via API. It should be like that(for instance, values are not
> correct):
> 
>
> The modal:
>
> class SensorModel(models.Model):
> measurementTime = models.DateTimeField()
> ldr = models.IntegerField()
> temperature = models.IntegerField()
> humidity = models.IntegerField()
>
> class Meta:
> ordering = ['measurementTime']
>
> def __unicode__(self):
> return str(self.id)
>
>
>
> Database:
>
> 
>
> Current API:
>
> 
>
> Thanks in advance.
>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-rest-framework+unsubscr...@googlegroups.com.
>
>
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django REST framework" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-rest-framework/bhGJR4tndMc/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> django-rest-framework+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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