<commit_before>from django.conf.urls.defaults import *
from django.contrib.auth.models import User
from tastypie.utils import trailing_slash

from agora_site.misc.generic_resource import GenericResource, GenericMeta


class UserResource(GenericResource):
    class Meta(GenericMeta):
        queryset = User.objects.all()
        list_allowed_methods = ['get', 'post']
        detail_allowed_methods = ['get']

    def override_urls(self):
        return [
            url(r"^(?P<resource_name>%s)/(?P<username>[\w\d_.-]+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
        ]

    def prepend_urls(self):
        return [
            url(r"^(?P<resource_name>%s)/register%s$" % (self._meta.resource_name, trailing_slash()),
                                                         self.wrap_view('register'), name="user_register"),
            url(r"^(?P<resource_name>%s)/username_available%s$" % (self._meta.resource_name, trailing_slash()),
                                                                   self.wrap_view('username_available'), name="username_available"),
            url(r"^(?P<resource_name>%s)/forgot_password%s$" % (self._meta.resource_name, trailing_slash()),
                                                                self.wrap_view('forgot_password'), name="forgot_password"),
            url(r"^(?P<resource_name>%s)/reset_password%s$" % (self._meta.resource_name, trailing_slash()),
                                                               self.wrap_view('reset_password'), name="reset_password"),
            url(r"^(?P<resource_name>%s)/disable%s$" % (self._meta.resource_name, trailing_slash()),
                                                         self.wrap_view('user_disable'), name="user_disable"),
        ]<commit_msg>We can get the properties of the current user via API<commit_after>import json

from django.conf.urls.defaults import *
from django.contrib.auth.models import User
from tastypie.utils import trailing_slash

from agora_site.misc.generic_resource import GenericResource, GenericMeta


class UserResource(GenericResource):
    class Meta(GenericMeta):
        queryset = User.objects.all()
        list_allowed_methods = ['get', 'post']
        detail_allowed_methods = ['get', 'put']
        excludes = ['password', 'is_staff', 'is_superuser']

    def override_urls(self):
        return [
            url(r"^(?P<resource_name>%s)/username/(?P<username>[\w\d_.-]+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
            url(r"^(?P<resource_name>%s)/settings%s$" % (self._meta.resource_name, trailing_slash()),
                                                         self.wrap_view('user_settings'), name="api_user_settings"),
        ]

    def user_settings(self, request, **kwargs):
        '''
            Get the properties of the user currently authenticated
        '''

        if request.method == 'GET':
            user = User.objects.get(username=request.user)
            bundle = self.build_bundle(obj=user, request=request)
            bundle = self.full_dehydrate(bundle)

            return self.create_response(request, bundle)
        elif request.method == 'PUT':
            # TODO
            pass
{'fraction_non_alphanumeric': 0.13114754098360656, 'fraction_numerical': 0.0, 'mean_word_length': 2.4004127966976263, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3385096', 'n_tokens_mistral': 889, 'n_tokens_neox': 879, 'n_words': 148}