<commit_before>from django.http import HttpResponse
from django.template.response import TemplateResponse
from django.db.models import Sum, Avg
from django.shortcuts import render_to_response
#from odm2testapp.forms import VariablesForm
from django.shortcuts import render
from django.http import HttpResponseRedirect
from .models import Measurementresultvalues
from .models import Dataloggerfiles
from .models import Dataloggerfilecolumns
from .models import Featureactions
from .models import Samplingfeatures
from .models import Variables
from .models import Units
from .models import Results
from datetime import datetime
import csv
import time
import datetime
from datetime import timedelta
from django.db.models import Q
from django.views.generic import ListView
import csv
import io
import binascii
import unicodedata
from io import TextIOWrapper
import cStringIO as StringIO
from odm2testsite.settings import MEDIA_ROOT
import itertools
from django.core.exceptions import ValidationError
from daterange_filter.filter import DateRangeFilter
from django import template
from django.core.serializers.json import DjangoJSONEncoder
import json
from django.views.generic import View
from django.template import RequestContext
from forms import DataloggerfilesAdmin
from forms import DataloggerfilesAdminForm
register = template.Library()
import admin
def PeopleAndOrgs(request):
    #return HttpResponse("odm2testsite says hello world!")
    if request.user.is_authenticated():
        return TemplateResponse(request, 'PeopleAndOrgs.html', {})
    else:
        return HttpResponseRedirect('/admin/login/?next=/admin/')

def AddSensor(request):
    #return HttpResponse("odm2testsite says hello world!")
    if request.user.is_authenticated():
        return TemplateResponse(request, 'AddSensor.html', {})
    else:
        return HttpResponseRedirect('/admin/login/?next=/admin/')

def RecordAction(request):
    #return HttpResponse("odm2testsite says hello world!")
    if request.user.is_authenticated():
        return TemplateResponse(request, 'RecordAction.html', {})
    else:
        return HttpResponseRedirect('/admin/login/?next=/admin/')
# #
# def dataloggerfilesView(request, id):
#      #model = Dataloggerfiles
#      #template_name = 'admin/odm2testapp/dataloggerfiles/change_form.html'#'DataloggerfilecolumnsDisplay.html'
#      DataloggerfilecolumnsList = Dataloggerfilecolumns.objects.filter(dataloggerfileid=id)
#      DataloggerfilecolumnsListvalues =  str(DataloggerfilecolumnsList.values())
#      #raise ValidationError(DataloggerfilecolumnsListvalues)
#      DataloggerfilecolumnsListvalues= DataloggerfilecolumnsList#DataloggerfilecolumnsListvalues.split('\'')
#      #request.session["DataloggerfilecolumnsList"] =DataloggerfilecolumnsListvalues
#      #fieldsets = Dataloggerfiles.objects.filter(dataloggerfileid=id)
#      adm = DataloggerfilesAdmin(Dataloggerfiles,admin) #.change_form_template
#      admform = DataloggerfilesAdminForm(request.POST)
#      #data =request.POST
#      data = {
#           'opts': Dataloggerfiles._meta,
#           'adminform': admform.formset,
#           'change': True,
#           'is_popup': False,
#           'to_field' : True,
#           'save_as': False,
#           #'prepopulated_fields' : adm.get_prepopulated_fields(request),
#           'has_delete_permission': True,
#           'has_add_permission': True,
#           'has_change_permission': True,
#           'DataloggerfilecolumnsList' : DataloggerfilecolumnsListvalues,}
# #
# # #DataloggerfilecolumnsDisplay.html
#      return render_to_response('admin/odm2testapp/dataloggerfiles/change_form.html', data, context_instance=RequestContext(request)) # DataloggerfilecolumnsDisplay.html

    # def get_context_data(self, **kwargs):
    #     context = super(dataloggercolumnView, self).get_context_data(**kwargs)
    #
    #     data = {'test': 'test',
    #     'opts': Dataloggerfiles._meta,
    #     'change': True,
    #     'is_popup': False,
    #     'save_as': False,
    #     'has_delete_permission': False,
    #     'has_add_permission': False,
    #     'has_change_permission': False}
    #     context['data'] = data
    #     context['DataloggerfilecolumnsList'] = Dataloggerfilecolumns.objects.all()
    #     return context
#register.inclusion_tag('DataloggerfilecolumnsDisplay.html')(dataloggercolumnView)

def get_name_of_sampling_feature(selected_result):

     title_feature_action = Featureactions.objects.filter(featureactionid=selected_result.values('feature_action'))
     title_sampling_feature = Samplingfeatures.objects.filter(samplingfeatureid=title_feature_action.values('sampling_feature'))
     s = str(title_sampling_feature.values_list('samplingfeaturename',flat=True))
     name_of_sampling_feature= s.split('\'')[1]
     return name_of_sampling_feature

def get_name_of_variable(selected_result):
     title_variables = Variables.objects.filter(variableid=selected_result.values('variable'))
     s = str(title_variables.values_list('variable_name',flat=True))
     name_of_variable= s.split('\'')[1]
     return name_of_variable

def get_name_of_units(selected_result):
     title_units = Units.objects.filter(unitsid=selected_result.values('unitsid'))
     s = str(title_units.values_list('unitsname',flat=True))
     name_of_units= s.split('\'')[1]
     return name_of_units

def dumptoMillis(obj):
    """Default JSON serializer."""
    import calendar, datetime

    if isinstance(obj, datetime.datetime):
        if obj.utcoffset() is not None:
            obj = obj - obj.utcoffset()
    millis = int(
        calendar.timegm(obj.timetuple())*1000
    )
    return millis

def ValuesQuerySetToDict(vqs):
    return [item for item in vqs]


def temp_pivot_chart_view(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/admin/login/?next=/admin/')
    entered_start_date = ''
    entered_end_date = ''
    selected_resultid = 15
    selected_featureactionid = 5


    if 'SelectedFeatureAction' in request.POST:
        if not request.POST['SelectedFeatureAction'] == 'All':<commit_msg>Changed the redirect for user authentication.<commit_after>from django.http import HttpResponse
from django.template.response import TemplateResponse
from django.db.models import Sum, Avg
from django.shortcuts import render_to_response
#from odm2testapp.forms import VariablesForm
from django.shortcuts import render
from django.http import HttpResponseRedirect
from .models import Measurementresultvalues
from .models import Dataloggerfiles
from .models import Dataloggerfilecolumns
from .models import Featureactions
from .models import Samplingfeatures
from .models import Variables
from .models import Units
from .models import Results
from datetime import datetime
import csv
import time
import datetime
from datetime import timedelta
from django.db.models import Q
from django.views.generic import ListView
import csv
import io
import binascii
import unicodedata
from io import TextIOWrapper
import cStringIO as StringIO
from odm2testsite.settings import MEDIA_ROOT
import itertools
from django.core.exceptions import ValidationError
from daterange_filter.filter import DateRangeFilter
from django import template
from django.core.serializers.json import DjangoJSONEncoder
import json
from django.views.generic import View
from django.template import RequestContext
from forms import DataloggerfilesAdmin
from forms import DataloggerfilesAdminForm
register = template.Library()
import admin
def PeopleAndOrgs(request):
    #return HttpResponse("odm2testsite says hello world!")
    if request.user.is_authenticated():
        return TemplateResponse(request, 'PeopleAndOrgs.html', {})
    else:
        return HttpResponseRedirect('../')

def AddSensor(request):
    #return HttpResponse("odm2testsite says hello world!")
    if request.user.is_authenticated():
        return TemplateResponse(request, 'AddSensor.html', {})
    else:
        return HttpResponseRedirect('../')

def RecordAction(request):
    #return HttpResponse("odm2testsite says hello world!")
    if request.user.is_authenticated():
        return TemplateResponse(request, 'RecordAction.html', {})
    else:
        return HttpResponseRedirect('../')
# #
# def dataloggerfilesView(request, id):
#      #model = Dataloggerfiles
#      #template_name = 'admin/odm2testapp/dataloggerfiles/change_form.html'#'DataloggerfilecolumnsDisplay.html'
#      DataloggerfilecolumnsList = Dataloggerfilecolumns.objects.filter(dataloggerfileid=id)
#      DataloggerfilecolumnsListvalues =  str(DataloggerfilecolumnsList.values())
#      #raise ValidationError(DataloggerfilecolumnsListvalues)
#      DataloggerfilecolumnsListvalues= DataloggerfilecolumnsList#DataloggerfilecolumnsListvalues.split('\'')
#      #request.session["DataloggerfilecolumnsList"] =DataloggerfilecolumnsListvalues
#      #fieldsets = Dataloggerfiles.objects.filter(dataloggerfileid=id)
#      adm = DataloggerfilesAdmin(Dataloggerfiles,admin) #.change_form_template
#      admform = DataloggerfilesAdminForm(request.POST)
#      #data =request.POST
#      data = {
#           'opts': Dataloggerfiles._meta,
#           'adminform': admform.formset,
#           'change': True,
#           'is_popup': False,
#           'to_field' : True,
#           'save_as': False,
#           #'prepopulated_fields' : adm.get_prepopulated_fields(request),
#           'has_delete_permission': True,
#           'has_add_permission': True,
#           'has_change_permission': True,
#           'DataloggerfilecolumnsList' : DataloggerfilecolumnsListvalues,}
# #
# # #DataloggerfilecolumnsDisplay.html
#      return render_to_response('admin/odm2testapp/dataloggerfiles/change_form.html', data, context_instance=RequestContext(request)) # DataloggerfilecolumnsDisplay.html

    # def get_context_data(self, **kwargs):
    #     context = super(dataloggercolumnView, self).get_context_data(**kwargs)
    #
    #     data = {'test': 'test',
    #     'opts': Dataloggerfiles._meta,
    #     'change': True,
    #     'is_popup': False,
    #     'save_as': False,
    #     'has_delete_permission': False,
    #     'has_add_permission': False,
    #     'has_change_permission': False}
    #     context['data'] = data
    #     context['DataloggerfilecolumnsList'] = Dataloggerfilecolumns.objects.all()
    #     return context
#register.inclusion_tag('DataloggerfilecolumnsDisplay.html')(dataloggercolumnView)

def get_name_of_sampling_feature(selected_result):

     title_feature_action = Featureactions.objects.filter(featureactionid=selected_result.values('feature_action'))
     title_sampling_feature = Samplingfeatures.objects.filter(samplingfeatureid=title_feature_action.values('sampling_feature'))
     s = str(title_sampling_feature.values_list('samplingfeaturename',flat=True))
     name_of_sampling_feature= s.split('\'')[1]
     return name_of_sampling_feature

def get_name_of_variable(selected_result):
     title_variables = Variables.objects.filter(variableid=selected_result.values('variable'))
     s = str(title_variables.values_list('variable_name',flat=True))
     name_of_variable= s.split('\'')[1]
     return name_of_variable

def get_name_of_units(selected_result):
     title_units = Units.objects.filter(unitsid=selected_result.values('unitsid'))
     s = str(title_units.values_list('unitsname',flat=True))
     name_of_units= s.split('\'')[1]
     return name_of_units

def dumptoMillis(obj):
    """Default JSON serializer."""
    import calendar, datetime

    if isinstance(obj, datetime.datetime):
        if obj.utcoffset() is not None:
            obj = obj - obj.utcoffset()
    millis = int(
        calendar.timegm(obj.timetuple())*1000
    )
    return millis

def ValuesQuerySetToDict(vqs):
    return [item for item in vqs]


def temp_pivot_chart_view(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('../')
    entered_start_date = ''
    entered_end_date = ''
    selected_resultid = 15
    selected_featureactionid = 5


    if 'SelectedFeatureAction' in request.POST:
        if not request.POST['SelectedFeatureAction'] == 'All':
{'fraction_non_alphanumeric': 0.09716965608030279, 'fraction_numerical': 0.0027974329438867863, 'mean_word_length': 4.50747621205256, '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': '470887', 'n_tokens_mistral': 3562, 'n_tokens_neox': 3541, 'n_words': 720}