diff --git a/admin.py b/admin.py index a856948bb..9f487b7c9 100755 --- a/admin.py +++ b/admin.py @@ -4,6 +4,8 @@ from .models import * admin.site.register(assigned_users) +admin.site.register(bug) +admin.site.register(bug_client) admin.site.register(contact_history) admin.site.register(costs) admin.site.register(customers) @@ -20,6 +22,7 @@ admin.site.register(kanban_column) admin.site.register(kanban_level) admin.site.register(list_of_amount_type) +admin.site.register(list_of_bug_client) admin.site.register(list_of_currency) admin.site.register(list_of_contact_types) admin.site.register(list_of_countries_regions) diff --git a/forms.py b/forms.py index 890b1aa94..cad34208f 100644 --- a/forms.py +++ b/forms.py @@ -175,6 +175,49 @@ class add_permission_set_to_group_form(forms.Form): ) +class bug_client_form(ModelForm): + # Get data for choice boxes + bug_client_results = list_of_bug_client.objects.filter(is_deleted='FALSE') + + bug_client_name = forms.CharField( + widget=forms.TextInput(attrs={ + 'placeholder': 'Bug Client Name', + }) + ) + list_of_bug_client=forms.ModelChoiceField( + label='Bug Clients', + widget=forms.Select, + queryset=bug_client_results, + empty_label=None, + ) + bug_client_url=forms.CharField( + widget=forms.TextInput(attrs={ + 'placeholder': 'Example: https://bugzilla.nearbeach.org', + }) + ) + class Meta: + model = bug_client + fields = { + 'bug_client_name', + 'list_of_bug_client', + 'bug_client_url', + } + + +class bug_search_form(forms.Form): + #Get the choice box + bug_client_results = bug_client.objects.filter(is_deleted="FALSE") + + #Fields + list_of_bug_client=forms.ModelChoiceField( + label='Bug Clients', + widget=forms.Select, + queryset=bug_client_results, + empty_label=None, + ) + search = forms.CharField(max_length=255) + + class customer_campus_form(ModelForm): customer_phone=forms.CharField( diff --git a/migrations/0004_api_access.py b/migrations/0004_api_access.py new file mode 100644 index 000000000..eec0f8d78 --- /dev/null +++ b/migrations/0004_api_access.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.7 on 2018-03-26 10:33 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('NearBeach', '0003_auto_20180321_1725'), + ] + + operations = [ + migrations.CreateModel( + name='api_access', + fields=[ + ('api_access_id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('date_created', models.DateTimeField(auto_now_add=True)), + ('date_modified', models.DateTimeField(auto_now=True)), + ('is_deleted', models.CharField(choices=[('TRUE', 'TRUE'), ('FALSE', 'FALSE')], default='FALSE', max_length=5)), + ('change_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='api_access_change_user', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'db_table': 'api_access', + }, + ), + ] diff --git a/migrations/0005_api_access_domain_limiter.py b/migrations/0005_api_access_domain_limiter.py new file mode 100644 index 000000000..0cf7918c9 --- /dev/null +++ b/migrations/0005_api_access_domain_limiter.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.7 on 2018-03-26 10:39 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('NearBeach', '0004_api_access'), + ] + + operations = [ + migrations.AddField( + model_name='api_access', + name='domain_limiter', + field=models.URLField(default='localhost:8000;'), + preserve_default=False, + ), + ] diff --git a/migrations/0006_auto_20180331_1353.py b/migrations/0006_auto_20180331_1353.py new file mode 100644 index 000000000..08f5e032e --- /dev/null +++ b/migrations/0006_auto_20180331_1353.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-03-31 02:53 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('NearBeach', '0005_api_access_domain_limiter'), + ] + + operations = [ + migrations.CreateModel( + name='bug', + fields=[ + ('bug_id', models.AutoField(primary_key=True, serialize=False)), + ('bug_code', models.CharField(max_length=255)), + ('bug_description', models.TextField()), + ('bug_status', models.CharField(max_length=50)), + ('date_created', models.DateTimeField(auto_now_add=True)), + ('date_modified', models.DateTimeField(auto_now=True)), + ('is_deleted', models.CharField(choices=[('TRUE', 'TRUE'), ('FALSE', 'FALSE')], default='FALSE', max_length=5)), + ], + options={ + 'db_table': 'bug', + }, + ), + migrations.CreateModel( + name='bug_client', + fields=[ + ('bug_client_id', models.AutoField(primary_key=True, serialize=False)), + ('bug_client_name', models.CharField(max_length=50)), + ('bug_client_url', models.URLField()), + ('date_created', models.DateTimeField(auto_now_add=True)), + ('date_modified', models.DateTimeField(auto_now=True)), + ('is_deleted', models.CharField(choices=[('TRUE', 'TRUE'), ('FALSE', 'FALSE')], default='FALSE', max_length=5)), + ('change_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bug_client_change_user', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'db_table': 'bug_client', + }, + ), + migrations.CreateModel( + name='list_of_bug_client', + fields=[ + ('list_of_bug_client_id', models.AutoField(primary_key=True, serialize=False)), + ('bug_client_name', models.CharField(max_length=50)), + ('bug_client_api_url', models.CharField(max_length=255)), + ('date_created', models.DateTimeField(auto_now_add=True)), + ('date_modified', models.DateTimeField(auto_now=True)), + ('is_deleted', models.CharField(choices=[('TRUE', 'TRUE'), ('FALSE', 'FALSE')], default='FALSE', max_length=5)), + ('change_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='list_of_bug_client_change_user', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'db_table': 'list_of_bug_client', + }, + ), + migrations.RemoveField( + model_name='api_access', + name='change_user', + ), + migrations.DeleteModel( + name='api_access', + ), + migrations.AddField( + model_name='bug_client', + name='list_of_bug_client', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='NearBeach.list_of_bug_client'), + ), + migrations.AddField( + model_name='bug', + name='bug_client', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='NearBeach.bug_client'), + ), + migrations.AddField( + model_name='bug', + name='change_user', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bug_change_user', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='bug', + name='project', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='NearBeach.project'), + ), + migrations.AddField( + model_name='bug', + name='requirements', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='NearBeach.requirements'), + ), + migrations.AddField( + model_name='bug', + name='tasks', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='NearBeach.tasks'), + ), + ] diff --git a/migrations/0007_auto_20180331_1444.py b/migrations/0007_auto_20180331_1444.py new file mode 100644 index 000000000..34be39e65 --- /dev/null +++ b/migrations/0007_auto_20180331_1444.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-03-31 03:44 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('NearBeach', '0006_auto_20180331_1353'), + ] + + operations = [ + migrations.AddField( + model_name='permission_set', + name='bug', + field=models.IntegerField(choices=[(0, 'No Permission'), (1, 'Read Only'), (2, 'Edit Only'), (3, 'Add and Edit'), (4, 'Full Permission')], default=0), + ), + migrations.AddField( + model_name='permission_set', + name='bug_client', + field=models.IntegerField(choices=[(0, 'No Permission'), (1, 'Read Only'), (2, 'Edit Only'), (3, 'Add and Edit'), (4, 'Full Permission')], default=0), + ), + ] diff --git a/migrations/0008_list_of_bug_client_bug_client_open_bugs.py b/migrations/0008_list_of_bug_client_bug_client_open_bugs.py new file mode 100644 index 000000000..21f9b0946 --- /dev/null +++ b/migrations/0008_list_of_bug_client_bug_client_open_bugs.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.7 on 2018-04-03 02:29 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('NearBeach', '0007_auto_20180331_1444'), + ] + + operations = [ + migrations.AddField( + model_name='list_of_bug_client', + name='bug_client_open_bugs', + field=models.CharField(default="?open_status='True'", max_length=255), + preserve_default=False, + ), + ] diff --git a/models.py b/models.py index 060d1e40a..9cc699c2e 100755 --- a/models.py +++ b/models.py @@ -143,6 +143,84 @@ class Meta: db_table="contact_history" +class bug(models.Model): + bug_id=models.AutoField(primary_key=True) + bug_client=models.ForeignKey( + 'bug_client', + on_delete=models.CASCADE, + ) + bug_code=models.CharField(max_length=255) #Just stores the code of the bug + bug_description=models.TextField() + bug_status=models.CharField(max_length=50) #Updated manually? + project=models.ForeignKey( + 'project', + on_delete=models.CASCADE, + null=True, + blank=True, + ) + tasks=models.ForeignKey( + 'tasks', + on_delete=models.CASCADE, + null=True, + blank=True, + ) + requirements=models.ForeignKey( + 'requirements', + on_delete=models.CASCADE, + null=True, + blank=True, + ) + date_created = models.DateTimeField(auto_now_add=True) + date_modified = models.DateTimeField(auto_now=True) + change_user = models.ForeignKey \ + (User, + on_delete=models.CASCADE, + related_name='%(class)s_change_user', + ) + is_deleted = models.CharField( + max_length=5, + choices=IS_DELETED_CHOICE, + default='FALSE' + ) + + def __str__(self): + return self.bug_description.encode('utf8') + + class Meta: + db_table = "bug" + + + + +class bug_client(models.Model): + bug_client_id=models.AutoField(primary_key=True) + bug_client_name=models.CharField(max_length=50) + list_of_bug_client=models.ForeignKey( + 'list_of_bug_client', + on_delete=models.CASCADE, + ) + bug_client_url=models.URLField() + date_created = models.DateTimeField(auto_now_add=True) + date_modified = models.DateTimeField(auto_now=True) + change_user = models.ForeignKey \ + (User, + on_delete=models.CASCADE, + related_name='%(class)s_change_user', + ) + is_deleted = models.CharField( + max_length=5, + choices=IS_DELETED_CHOICE, + default='FALSE' + ) + + def __str__(self): + return self.bug_client_name.encode('utf8') + + class Meta: + db_table = "bug_client" + + + class costs(models.Model): cost_id=models.AutoField(primary_key=True) project_id=models.ForeignKey( @@ -696,6 +774,34 @@ class Meta: ordering=['list_order'] +class list_of_bug_client(models.Model): + list_of_bug_client_id=models.AutoField(primary_key=True) + bug_client_name=models.CharField(max_length=50) + bug_client_api_url=models.CharField(max_length=255) + bug_client_open_bugs=models.CharField(max_length=255) + date_created=models.DateTimeField(auto_now_add=True) + date_modified=models.DateTimeField(auto_now=True) + date_created=models.DateTimeField(auto_now_add=True) + date_modified=models.DateTimeField(auto_now=True) + change_user=models.ForeignKey( + User, + on_delete=models.CASCADE, + related_name='%(class)s_change_user', + blank=True, + null=True + ) + is_deleted=models.CharField( + max_length=5, + choices=IS_DELETED_CHOICE, + default='FALSE' + ) + + def __str__(self): + return self.bug_client_name.encode('utf8') + + class Meta: + db_table="list_of_bug_client" + class list_of_currency(models.Model): @@ -1344,6 +1450,8 @@ def get_by_natural_key( administration_create_users, assign_campus_to_customer, associate_project_and_tasks, + bug, + bug_client, customer, invoice, invoice_product, @@ -1372,6 +1480,8 @@ def get_by_natural_key( administration_create_users=administration_create_users, assign_campus_to_customer=assign_campus_to_customer, associate_project_and_tasks=associate_project_and_tasks, + bug=bug, + bug_client=bug_client, customer=customer, invoice=invoice, invoice_product=invoice_product, @@ -1425,6 +1535,14 @@ class permission_set(models.Model): choices=PERMISSION_LEVEL, default=0, ) + bug=models.IntegerField( + choices=PERMISSION_LEVEL, + default=0, + ) + bug_client=models.IntegerField( + choices=PERMISSION_LEVEL, + default=0, + ) invoice = models.IntegerField( choices=PERMISSION_LEVEL, default=0, diff --git a/static/NearBeach/javascript/bug.js b/static/NearBeach/javascript/bug.js new file mode 100644 index 000000000..ffa25722a --- /dev/null +++ b/static/NearBeach/javascript/bug.js @@ -0,0 +1,29 @@ + + +function add_bug(location_id, destination,bug_id, bug_client_id) { + //Send data to the database + $.ajaxSetup({ + beforeSend: function (xhr, settings) { + if (!csrfSafeMethod(settings.type) && !this.crossDomain) { + xhr.setRequestHeader("X-CSRFToken", csrftoken); + } + } + }); + + $("#id_"+bug_id+"_"+bug_client_id).html("Adding..."); + + + $.ajax({ + url: '/bug_add/' + location_id + '/' + destination + '/' + bug_id + '/' + bug_client_id + '/', + data: {}, + type: 'POST', + success: function(data) { + //$(this).html("Added"); + load_bug_list(); + $("#id_"+bug_id+"_"+bug_client_id).html("Added"); + }, + error: function() { + alert("We are sorry, we experienced an error trying to add your bug to the " + destination); + }, + }); +} \ No newline at end of file diff --git a/templates/NearBeach/bug_client_list.html b/templates/NearBeach/bug_client_list.html new file mode 100644 index 000000000..84ca07ca8 --- /dev/null +++ b/templates/NearBeach/bug_client_list.html @@ -0,0 +1,23 @@ +{% extends "./template.html" %} +{% block content %} +{% load static %} +

Bug Client List

+New Bug Client +{% if bug_client_results %} + + + + + + {% for row in bug_client_results %} + + + + + {% endfor %} +
Client NameType
{{ row.bug_client_name }}{{ row.list_of_bug_client }}
+{% else %} +

There are no bug clients listed. Please create a new one

+{% endif %} + +{% endblock %} \ No newline at end of file diff --git a/templates/NearBeach/bug_list.html b/templates/NearBeach/bug_list.html new file mode 100644 index 000000000..00bc0405c --- /dev/null +++ b/templates/NearBeach/bug_list.html @@ -0,0 +1,5 @@ +{% extends "./template.html" %} +{% block content %} +{% load static %} +

Bug List

+{% endblock %} \ No newline at end of file diff --git a/templates/NearBeach/bug_list_specific.html b/templates/NearBeach/bug_list_specific.html new file mode 100644 index 000000000..f380c7abb --- /dev/null +++ b/templates/NearBeach/bug_list_specific.html @@ -0,0 +1,23 @@ +

Assigned Bugs

+ + + + + + + {% if bug_permission == 4 %} + + {% endif %} + + {% for row in bug_results %} + + + + + + {% if bug_permission == 4 %} + + {% endif %} + + {% endfor %} +
Bug IDBug ClientBug DescriptionBug StatusRemove Bug
{{ row.bug_code }}{{ row.bug_client }}{{ row.bug_description }}{{ row.bug_status }}Remove Bug
\ No newline at end of file diff --git a/templates/NearBeach/bug_search.html b/templates/NearBeach/bug_search.html new file mode 100644 index 000000000..04d4cf3f3 --- /dev/null +++ b/templates/NearBeach/bug_search.html @@ -0,0 +1,27 @@ +{% csrf_token %} +

Bug Search

+ +{% if bug_results %} + + + + + + + + {% for row in bug_results %} + + + + + + + {% endfor %} +
SelectBug IDBug DescriptionBug Status
Add Bug{{ row.id }}{{ row.summary|escape|safe }}{{ row.status }}
+{% endif %} \ No newline at end of file diff --git a/templates/NearBeach/new_bug_client.html b/templates/NearBeach/new_bug_client.html new file mode 100644 index 000000000..84d2a04ff --- /dev/null +++ b/templates/NearBeach/new_bug_client.html @@ -0,0 +1,23 @@ +{% extends "./template.html" %} +{% block content %} +{% load static %} +

New Bug Client

+
+ {% csrf_token %} + +
+{% endblock %} \ No newline at end of file diff --git a/templates/NearBeach/project_information.html b/templates/NearBeach/project_information.html index 4002ba054..c4a741998 100755 --- a/templates/NearBeach/project_information.html +++ b/templates/NearBeach/project_information.html @@ -8,6 +8,8 @@ + + +

Requirement Information - {{ requirement_id }}

@@ -55,7 +56,38 @@

Requirement Documents

Loading... + +

Requirement Bug List

+ Loading... +
+ + + + @@ -67,11 +69,17 @@

  • Administration
    +
  • +
  • + Configuration
    +
  • {% endif %} diff --git a/urls.py b/urls.py index 177065f46..b71bce010 100755 --- a/urls.py +++ b/urls.py @@ -248,6 +248,17 @@ url(r'^kanban_new_link/(?P[0-9]+)/(?P[0-9]+)/(?P["project","task","requirement"]+)/$', views.kanban_new_link,name='kanban_new_link'), url(r'^to_do/(?P[0-9]+)/(?P["project","task"]+)/$', views.to_do_list, name='to_do'), url(r'^to_do_complete/(?P[0-9]+)/$', views.to_do_complete, name='to_do_complete'), + + url(r'^bug_client_list/$',views.bug_client_list,name='bug_client_list'), + url(r'^new_bug_client/$',views.new_bug_client, name='new_bug_client'), + + url(r'^bug_list/$', views.bug_list, name='bug_list'), + url(r'^bug_list/(?P[0-9]+)/(?P["project","task","requirement"]+)/$', views.bug_list, name='bug_list'), + + url(r'^bug_search/(?P[0-9]+)/(?P["project","task","requirement"]+)/$', views.bug_search, name='bug_search'), + + url(r'^bug_add/(?P[0-9]+)/(?P["project","task","requirement"]+)/(?P[0-9]+)/(?P[0-9]+)',views.bug_add,name='bug_add'), + ] if settings.DEBUG: diff --git a/views.py b/views.py index 3b4795e7f..c6cfba288 100755 --- a/views.py +++ b/views.py @@ -301,6 +301,175 @@ def associated_tasks(request, project_id): return HttpResponse(t.render(c, request)) +@login_required(login_url='login') +def bug_add(request,location_id, destination,bug_id, bug_client_id): + if request.method == "POST": + """ + Method + ~~~~~~ + 1.) Bring in all the data we need via the URL :) + 2.) Extract the bug_client information - we will use this to contact the bug client server + 3.) Extract an up to date bug information. This is done here (even though it is slow), because at a + later date, we might require to gather more information about this bug. This will help. + 4.) Write the information collected VIA the JSON into the database :) + 5.) Notify the end user that this has occurred. This might be by changing the text from "ADD" to "ADDING..." to "ADDED :)" + """ + + #Get the bug client instance - we need to reload this + bug_client_instance = bug_client.objects.get( + bug_client_id=bug_client_id, + ) + + #https://bugzilla.nearbeach.org/rest/bug?id=12 example of bugzilla rest platform + #Most of this will be stored in the database, so we can implement more bug clients simply. :) YAY + url = bug_client_instance.bug_client_url + bug_client_instance.list_of_bug_client.bug_client_api_url + \ + 'bug?id=' + bug_id # This will be implemented into the database as a field + print(url) + req = urllib2.Request(url) + response = urllib2.urlopen(req) + json_data = json.load(response) + + #Save the bug + bug_submit = bug( + bug_client=bug_client_instance, + bug_code=bug_id, #I could not have bug_id twice, so the bug's id becomes bug_code + bug_description=str(json_data['bugs'][0]['summary']), + bug_status=str(json_data['bugs'][0]['status']), + change_user=request.user, + ) + if destination=="project": + bug_submit.project_id=project.objects.get(project_id=location_id) + elif destination=="task": + bug_submit.tasks = tasks.objects.get(tasks_id=location_id) + else: + bug_submit.requirements=requirements.objects.get(requirement_id=location_id) + + #Save the bug + bug_submit.save() + + # Load the template + t = loader.get_template('NearBeach/blank.html') + + # context + c = {} + + return HttpResponse(t.render(c, request)) + + else: + return HttpResponseBadRequest("Only POST requests allowed") + + +@login_required(login_url='login') +def bug_client_list(request): + #ADD IN PERMISSIONS LATER + + + #Get Data + bug_client_results = bug_client.objects.filter( + is_deleted='FALSE', + ) + + # Load the template + t = loader.get_template('NearBeach/bug_client_list.html') + + # context + c = { + 'bug_client_results': bug_client_results, + } + + return HttpResponse(t.render(c, request)) + + +@login_required(login_url='login') +def bug_client_search(request, location_id=None, destination=None): + print("hello world") + + +@login_required(login_url='login') +def bug_list(request, location_id=None, destination=None): + #Add permissions later + if destination == "project": + bug_results = bug.objects.filter( + is_deleted="FALSE", + project=location_id, + ) + elif destination == "task": + bug_results = bug.objects.filter( + is_deleted="FALSE", + tasks=location_id, + ) + elif destination == "requirement": + bug_results = bug.objects.filter( + is_deleted="FALSE", + requirements=location_id, + ) + else: + bug_results = bug.objects.filter( + is_deleted="FALSE", + ) + + # Load the template + if destination == None: + t = loader.get_template('NearBeach/bug_list.html') + else: + t = loader.get_template('NearBeach/bug_list_specific.html') + + # context + c = { + 'bug_results': bug_results, + } + + return HttpResponse(t.render(c, request)) + + +@login_required(login_url='login') +def bug_search(request, location_id=None, destination=None): + #Do permissions later + bug_results = None + bug_client_id = None + if request.method == "POST": + form = bug_search_form(request.POST) + if form.is_valid(): + #Get the bug client instance + bug_client_instance = form.cleaned_data['list_of_bug_client'] + bug_client_id = bug_client_instance.list_of_bug_client_id + + #Get the bug client information + bug_client_results = bug_client.objects.get( + bug_client_id=bug_client_instance.list_of_bug_client_id + ) + #TEMP CODE# + url = bug_client_results.bug_client_url \ + + bug_client_results.list_of_bug_client.bug_client_api_url \ + + 'bug?bug_status=__open__' #Note - this last section should be moved into the database + + print(url) + req = urllib2.Request(url) + response = urllib2.urlopen(req) + json_data = json.load(response) + bug_results = json_data['bugs'] #This could change depending on the API + + #print bug_results['bugs'] + + #END TEMP CODE# + else: + print(form.errors) + + # Load the template + t = loader.get_template('NearBeach/bug_search.html') + + # context + c = { + 'bug_search_form': bug_search_form(request.POST or None), + 'bug_results': bug_results, + 'location_id': location_id, + 'destination': destination, + 'bug_client_id': bug_client_id, + } + + return HttpResponse(t.render(c, request)) + + @login_required(login_url='login') def campus_information(request, campus_information): permission_results = return_user_permission_level(request, None, 'organisation_campus') @@ -1597,6 +1766,58 @@ def logout(request): return HttpResponseRedirect(reverse('login')) +@login_required(login_url='login') +def new_bug_client(request): + permission_results = return_user_permission_level(request, None, 'bug_client') + + if permission_results['bug_client'] < 3: + return HttpResponseRedirect(reverse('permission_denied')) + form_errors = '' + if request.method == "POST": + form = bug_client_form(request.POST) + if form.is_valid(): + #Get required data + bug_client_name = form.cleaned_data['bug_client_name'] + list_of_bug_client = form.cleaned_data['list_of_bug_client'] + bug_client_url = form.cleaned_data['bug_client_url'] + + #Test the link first before doing ANYTHING! + try: + url = bug_client_url + list_of_bug_client.bug_client_api_url + 'bug?bug_status=__open__' + print(url) + req = urllib2.Request(url) + response = urllib2.urlopen(req) + print("Response gotten") + data = json.load(response) + print("Got the JSON") + + bug_client_submit = bug_client( + bug_client_name = bug_client_name, + list_of_bug_client = list_of_bug_client, + bug_client_url = bug_client_url, + change_user=request.user, + ) + bug_client_submit.save() + return HttpResponseRedirect(reverse('bug_client_list')) + except: + form_errors = "Could not connect to the API" + + + else: + print(form.errors) + form_errors(form.errors) + + # load template + t = loader.get_template('NearBeach/new_bug_client.html') + + # context + c = { + 'bug_client_form': bug_client_form(), + 'form_errors': form_errors, + } + + return HttpResponse(t.render(c, request)) + @login_required(login_url='login') def new_campus(request, organisations_id): permission_results = return_user_permission_level(request, None, 'organisation_campus') diff --git a/views_administration.py b/views_administration.py index f167ce64e..f87108f06 100644 --- a/views_administration.py +++ b/views_administration.py @@ -195,7 +195,7 @@ def group_information_list(request): permission_results = return_user_permission_level(request, None,'administration_create_groups') - if permission_results['administration_create_group'] == 0: + if permission_results['administration_create_groups'] == 0: return HttpResponseRedirect(reverse('permission_denied')) group_results = groups.objects.filter(