Skip to content

Commit

Permalink
submit tickets by public user
Browse files Browse the repository at this point in the history
  • Loading branch information
odenypeter committed Feb 15, 2017
1 parent 7b226f4 commit 1578740
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 55 deletions.
115 changes: 61 additions & 54 deletions project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from datetime import datetime as timezone

from helpdesk.views.staff import form_data, user_tickets
from django.contrib.auth.decorators import login_required

def splash(request):
if request.user.is_authenticated():
Expand Down Expand Up @@ -358,7 +359,7 @@ def permission_denied(request):

###Tola Tools API Views
import requests

@login_required
def get_TolaActivity_data(request):

user_details = get_object_or_404(TolaUser, user=request.user)
Expand Down Expand Up @@ -414,75 +415,81 @@ def get_TolaActivity_loggedUser():

return {}


@login_required
def get_TolaTables_data(request):

user_details = get_object_or_404(TolaUser, user=request.user)
token = user_details.activity_api_token
user = {}
my_tables = {}
my_silos = {}

user_url = str(user_details.table_url)+'/api/users/'
table_data = {}

#public_tables
public_table_url =str(user_details.table_url)+'/api/public_tables/'
silo_url = str(user_details.table_url)+'/api/silo/'
if user_details:
try:
token = user_details.tables_api_token

header = {'Authorization': 'token %s' % token}
user_url = str(user_details.table_url)+'/api/users/'

#print email
try:
user_response = requests.get(user_url, headers=header)
public_table_response = requests.get(public_table_url, headers=header)
silo_response = requests.get(silo_url, headers=header)
#public_tables
public_table_url =str(user_details.table_url)+'/api/public_tables/'
silo_url = str(user_details.table_url)+'/api/silo/'

# Consider any status other than 2xx an error
if not user_response.status_code // 100 == 2 and public_table_response.status_code // 100 == 2:
return {}
header = {'Authorization': 'token %s' % token}

if not user_response.status_code // 100 == 2 and silo_response.status_code // 100 == 2:
return {}

json_obj = user_response.json()
json_obj2 = public_table_response.json()
json_obj3 = silo_response.json()

user = {}
my_tables = {}
my_silos = {}

table_data = {}

if request.user.is_authenticated():
email = request.user.email
for data in json_obj:
if data['email'] == email:
user = data
if user:
try:
for table in json_obj2:
if table['owner'] == user['url']:
my_tables.append(table)
except Exception, e:
pass

#get silos
try:
for silo in json_obj3:
if silo['owner'] == user['url']:
my_silos.append(silo)
except Exception, e:
pass
if token and user_details.table_url:
user_response = requests.get(user_url, headers=header)
public_table_response = requests.get(public_table_url, headers=header)
silo_response = requests.get(silo_url, headers=header)

# Consider any status other than 2xx an error
if not user_response.status_code // 100 == 2 and public_table_response.status_code // 100 == 2:
return {}


return table_data{'my_tables': my_tables, 'my_silos': my_silos}
elif not user_response.status_code // 100 == 2 and silo_response.status_code // 100 == 2:
return {}

except requests.exceptions.RequestException as e:
print e
return {}
json_obj = user_response.json()
json_obj2 = public_table_response.json()
json_obj3 = silo_response.json()

except ValueError:
email = request.user.email
for data in json_obj:
if data['email'] == email:
user = data
if user:
try:
for table in json_obj2:
if table['owner'] == user['url']:
my_tables.append(table)
except Exception, e:
pass

#get silos
try:
for silo in json_obj3:
if silo['owner'] == user['url']:
my_silos.append(silo)
except Exception, e:
pass


table_data = {'my_tables': my_tables, 'my_silos': my_silos}

return table_data

except requests.exceptions.RequestException as e:
print e
return {}

except ValueError:

return {}
else:
return {}


#return users logged into TolaWork
def logged_in_users(request):

Expand Down
5 changes: 4 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,17 @@ <h3 class="modal-title font9">Submit a Ticket</h3>
$('#ticket_form').on('submit', function(event){
event.preventDefault();
var data = new FormData($(this)[0]);
if (document.getElementById('id_tags')) {

var tags = $('#id_tags').val();
if (tags !== null) {

for (var i = 0; i < tags.length; i++) {
data.append('tags[]', tags[i]);
};
};

}

console.log(list_of_files);

for(i=0;i<list_of_files.length;i++)
Expand Down

0 comments on commit 1578740

Please sign in to comment.