# Path: newserializers/responses.py
# class JsonResponse(SerializedResponse):
#     mimetype = 'application/json'
#     formatter = 'json'
# 
# class XmlResponse(SerializedResponse):
#     mimetype = 'application/xml'
#     formatter = 'xml'


from django.core import serializers
from django.conf import settings
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.models import User
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect
from django.db.models import Sum, Avg
from django.utils import dateformat
from django.views.decorators.cache import cache_page
from datetime import datetime, timedelta
from shr.url.models import *
from shr.functions import *
from newserializers.responses import JsonResponse, XmlResponse
from urlparse import urlparse
from collections import defaultdict
import string, random
import urllib2
import re
    import GeoIP as geoip
        import pygeoip as geoip

    """
    if function == 'post':
        source_url = request.GET.get('url_src')
        domain_app = settings.SITE_URL
        
        if not source_url:
            return HttpResponse('Error')
            
        if request.method == 'GET':
            form = UrlForm(request.GET)
            
            if form.is_valid():
                new_url = form.save(commit=False)
                custom_alias = form.cleaned_data['url_min'] or None
                try:
                    new_url = shorten_url(
                        form.cleaned_data['url_src'],
                        request.META['REMOTE_ADDR'],
                        user=access_api.auteur,
                        model=new_url,
                        custom_alias=custom_alias
                    )
                except ValueError:
                    return HttpResponse('Error')

                if method == 'text':
                    return HttpResponse('%s/%s' % (domain_app, new_url.url_min))
                elif method == 'json':
                    return JsonResponse(Url.objects.filter(pk=new_url.id), method='get_urls')
                else:

# Path: newserializers/responses.py
# class JsonResponse(SerializedResponse):
#     mimetype = 'application/json'
#     formatter = 'json'
# 
# class XmlResponse(SerializedResponse):
#     mimetype = 'application/xml'
#     formatter = 'xml'


# Path: url/views.py
from django.core import serializers
from django.conf import settings
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.models import User
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect
from django.db.models import Sum, Avg
from django.utils import dateformat
from django.views.decorators.cache import cache_page
from datetime import datetime, timedelta
from shr.url.models import *
from shr.functions import *
from newserializers.responses import JsonResponse, XmlResponse
from urlparse import urlparse
from collections import defaultdict
import string, random
import urllib2
import re
    import GeoIP as geoip
        import pygeoip as geoip

    """
    if function == 'post':
        source_url = request.GET.get('url_src')
        domain_app = settings.SITE_URL
        
        if not source_url:
            return HttpResponse('Error')
            
        if request.method == 'GET':
            form = UrlForm(request.GET)
            
            if form.is_valid():
                new_url = form.save(commit=False)
                custom_alias = form.cleaned_data['url_min'] or None
                try:
                    new_url = shorten_url(
                        form.cleaned_data['url_src'],
                        request.META['REMOTE_ADDR'],
                        user=access_api.auteur,
                        model=new_url,
                        custom_alias=custom_alias
                    )
                except ValueError:
                    return HttpResponse('Error')

                if method == 'text':
                    return HttpResponse('%s/%s' % (domain_app, new_url.url_min))
                elif method == 'json':
                    return JsonResponse(Url.objects.filter(pk=new_url.id), method='get_urls')
                else:

                    return XmlResponse(Url.objects.filter(pk=new_url.id), method='get_urls')
