<commit_before>"""
Busine-me API
Universidade de Brasilia - FGA
Tecnicas de Programacao, 2/2015
@file views.py
Views (on classic MVC, controllers) with methods that control the requisitions
for the user authentication and manipulation.
"""
from django.views.generic import View
from core.serializers import serialize_objects
from core.serializers import serialize
from .models import BusinemeUser
from django.http import JsonResponse
from core.return_message import return_message
import logging

STATUS_OK = 200
STATUS_NOT_FOUND = 404
STATUS_CREATED = 201
STATUS_SERVER_ERROR = 500


FORMAT = '%(levelname)s: %(asctime)s %(message)s'
logging.basicConfig(format=FORMAT,
                    filename='authentication/logging/modelsLogging.log',
                    level=logging.DEBUG)


class LoginView(View):

    """Class used to control the views from login of users."""

    http_method_names = [u'get', u'post']

    def get(self, request):
        """
        Returns all users.
        """

        logging.info("All users request")

        json_data = serialize_objects(BusinemeUser.objects.all())
        return JsonResponse(json_data, content_type='application/json')

    def get_user(self, user_id):
        """Return a user given a id"""

        try:
            user = BusinemeUser.objects.get(pk=user_id)
            json_data = serialize(user)
        except:
            json_data = return_message(STATUS_NOT_FOUND)

        return JsonResponse(json_data, content_type='application/json')<commit_msg>exception for not existent user<commit_after>"""
Busine-me API
Universidade de Brasilia - FGA
Tecnicas de Programacao, 2/2015
@file views.py
Views (on classic MVC, controllers) with methods that control the requisitions
for the user authentication and manipulation.
"""
from django.views.generic import View
from core.serializers import serialize_objects
from core.serializers import serialize
from .models import BusinemeUser
from django.http import JsonResponse
from core.return_message import return_message
import logging

STATUS_OK = 200
STATUS_NOT_FOUND = 404
STATUS_CREATED = 201
STATUS_SERVER_ERROR = 500


FORMAT = '%(levelname)s: %(asctime)s %(message)s'
logging.basicConfig(format=FORMAT,
                    filename='authentication/logging/viewsLogging.log',
                    level=logging.DEBUG)


class LoginView(View):

    """Class used to control the views from login of users."""

    http_method_names = [u'get', u'post']

    def get(self, request):
        """Returns all users."""

        logging.info("All users request")

        json_data = serialize_objects(BusinemeUser.objects.all())
        return JsonResponse(json_data, content_type='application/json')

    def get_user(self, user_id):
        """Return a user given a id"""

        try:
            user = BusinemeUser.objects.get(pk=user_id)
            json_data = serialize(user)
        except BusinemeUser.DoesNotExist:
            json_data = return_message(STATUS_NOT_FOUND)

        return JsonResponse(json_data, content_type='application/json')
{'fraction_non_alphanumeric': 0.08918654034629206, 'fraction_numerical': 0.01110748121528912, 'mean_word_length': 3.5228951255539145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3200168', 'n_tokens_mistral': 916, 'n_tokens_neox': 853, 'n_words': 244}