<commit_before># Copyright 2014 NeuroData (http://neurodata.io)
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re
import string
import random
import MySQLdb
import json
import subprocess
import django.http
from django.core.urlresolvers import get_script_prefix
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from django.shortcuts import redirect
from django.shortcuts import get_object_or_404
from django.template import RequestContext
from django.contrib.auth import authenticate, login, logout, get_user_model
from django.template import Context
from collections import defaultdict
from django.contrib import messages
from django.contrib.auth.models import User
from rest_framework.authtoken.models import Token
from django.conf import settings
from django.forms.models import inlineformset_factory
import django.forms
from datetime import datetime
from contextlib import closing

import ndwsrest
import ndproj
import jsonprojinfo
from ndtype import IMAGE, ANNOTATION, TIMESERIES, UINT8, UINT16, UINT32, UINT64, FLOAT32, ND_VERSION, SCHEMA_VERSION, MYSQL, S3_FALSE 

from models import Project
from models import Dataset
from models import Token
from models import Channel
from models import Backup

from forms import ProjectForm
from forms import DatasetForm
from forms import TokenForm
from forms import ChannelForm
from forms import BackupForm
from forms import dataUserForm


from ndwserror import NDWSError
import logging
logger=logging.getLogger("neurodata")


# Helpers
''' Base url redirects to projects page'''
def default(request):
  return redirect(get_script_prefix()+'nduser/projects/', {"user":request.user})

''' Token Auth '''
@login_required(login_url='/nd/accounts/login/')
def getUserToken(request):
  u=request.user
  # u = User.objects.get(username=user) 
  is_tokened = Token.objects.filter(user=u)
  if is_tokened is []:
    token = Token.objects.create(user=u)
    response = HttpResponse(content_type='text/plain')
    response['Content-Disposition'] = "attachment; filename=\"{}.pem\"".format(user)
    response.write(token)
    return response
  else: 
    response = HttpResponse("You have already downloaded your token, please contact the site administrator if you have lost it")
    return response

''' Little welcome message'''
@login_required(login_url='/nd/accounts/login/')
def getProjects(request):

  try:
    if request.method == 'POST':
      if 'filter' in request.POST:
        # filter projects based on input value<commit_msg>Working Gui<commit_after># Copyright 2014 NeuroData (http://neurodata.io)
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re
import string
import random
import MySQLdb
import json
import subprocess
import django.http
from django.core.urlresolvers import get_script_prefix
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from django.shortcuts import redirect
from django.shortcuts import get_object_or_404
from django.template import RequestContext
from django.contrib.auth import authenticate, login, logout, get_user_model
from django.template import Context
from collections import defaultdict
from django.contrib import messages
from django.contrib.auth.models import User
from rest_framework.authtoken.models import Token as User_token
from django.conf import settings
from django.forms.models import inlineformset_factory
import django.forms
from datetime import datetime
from contextlib import closing

import ndwsrest
import ndproj
import jsonprojinfo
from ndtype import IMAGE, ANNOTATION, TIMESERIES, UINT8, UINT16, UINT32, UINT64, FLOAT32, ND_VERSION, SCHEMA_VERSION, MYSQL, S3_FALSE 

from models import Project
from models import Dataset
from models import Token
from models import Channel
from models import Backup

from forms import ProjectForm
from forms import DatasetForm
from forms import TokenForm
from forms import ChannelForm
from forms import BackupForm
from forms import dataUserForm


from ndwserror import NDWSError
import logging
logger=logging.getLogger("neurodata")


# Helpers
''' Base url redirects to projects page'''
def default(request):
  return redirect(get_script_prefix()+'nduser/projects/', {"user":request.user})

''' Token Auth '''
@login_required(login_url='/nd/accounts/login/')
def getUserToken(request):
  u=request.user
  # u = User.objects.get(username=user) 
  is_tokened = User_Token.objects.filter(user=u)
  if is_tokened is []:
    token = Token.objects.create(user=u)
    response = HttpResponse(content_type='text/plain')
    response['Content-Disposition'] = "attachment; filename=\"{}.pem\"".format(str(u))
    response.write(token)
    return response
  else: 
    response = HttpResponse("You have already downloaded your token, please contact the site administrator if you have lost it")
    return response

''' Little welcome message'''
@login_required(login_url='/nd/accounts/login/')
def getProjects(request):

  try:
    if request.method == 'POST':
      if 'filter' in request.POST:
        # filter projects based on input value
{'fraction_non_alphanumeric': 0.07283001098728614, 'fraction_numerical': 0.006592371684194004, 'mean_word_length': 5.284023668639053, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5411036', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1696, 'n_words': 656}