Skip to content

Commit

Permalink
Merge pull request #23 from geoffreynyaga/KCAA-remove
Browse files Browse the repository at this point in the history
Kcaa remove
  • Loading branch information
geoffreynyaga authored Mar 5, 2020
2 parents 467c75b + 3662a9a commit 270ffec
Show file tree
Hide file tree
Showing 35 changed files with 408 additions and 435 deletions.
7 changes: 6 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ AWS_STORAGE_BUCKET_NAME=yourawsbucketname
ALLOWED_HOSTS=localhost,yourdomain.com, youripadrress

EMAIL_HOST_USER=username
EMAIL_HOST_PASSWORD=password
EMAIL_HOST_PASSWORD=password


VAPID_PUBLIC_KEY=yourpublickey
VAPID_PRIVATE_KEY=yourprivatekey
VAPID_ADMIN_EMAIL=[email protected]
12 changes: 5 additions & 7 deletions ANGA_UTM/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# from .base import *
from .production import *

# from .production import *

try:
from .local import *
except:
pass
# try:
# from .local import *
# except:
# pass
142 changes: 0 additions & 142 deletions ANGA_UTM/settings/base.py

This file was deleted.

6 changes: 3 additions & 3 deletions ANGA_UTM/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@


WEBPUSH_SETTINGS = {
"VAPID_PUBLIC_KEY": "BH3eHxegmVIFi5gWT1zfNjJ7Kbzm2syiiIKW05ol8oGC1KCNxQ1UE4bDfwcMpvTHx-mEkJRkkuNyC13cf6JcbH0",
"VAPID_PRIVATE_KEY": "HG-5hGFDX4mdXaH3PPp8JJy6hLA2wodJvTxeZjkni14",
"VAPID_ADMIN_EMAIL": "[email protected]",
"VAPID_PUBLIC_KEY": os.environ.get("VAPID_PUBLIC_KEY"),
"VAPID_PRIVATE_KEY": os.environ.get("VAPID_PRIVATE_KEY"),
"VAPID_ADMIN_EMAIL": os.environ.get("VAPID_ADMIN_EMAIL"),
}
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,18 @@ python manage.py migrate
python manage.py createsuperuser
```

- `log in to the admin and under "Authentication and Authorization" create a group called KCAA and give the group the relevant permissions that Civil Aviation requires e.g. changing reserved airspaces, adding/changing NOTAMs`
- `log in to the admin and under "Authentication and Authorization" create a group called CAA and give the group the relevant permissions that Civil Aviation requires e.g. changing reserved airspaces, adding/changing NOTAMs`

- `One more thing... By default, the application is country-specific, and the default country is Kenya, but this constraint can be removed.`

`If you log in the app, the map will awlays be bound to Kenyan borders. To cahnge this to another country, draw a box on Google maps/earth that covers the entire country of your choice. Then get the North East lattitude/longitude as well as South Eastern lat/long of the bounding box`

`An example for Kenya can be seen in the image below`

![Anga UTM country box](docs/screenshots/bounds.png)

- Finally, take those values and insert them in `applications/templates/applications/airspaces.html` in this line

```javascript
bounds = new L.LatLngBounds(new L.LatLng(<northEastLatitude>,<northEastLongitude>), new L.LatLng(<southWestlattitude>, <southWestLongitude>));
```
80 changes: 48 additions & 32 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.shortcuts import render

from django.contrib.auth import login,logout
from django.contrib.auth import login, logout
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.models import User
Expand All @@ -16,21 +16,24 @@
from flight_plans.models import FlightLog
from rpas.models import Rpas

from . import forms #TODO: where is this needed? see line below and resolve to use just one in this doc
from . import (
forms,
) # TODO: where is this needed? see line below and resolve to use just one in this doc
from .forms import UserForm
from .models import UserProfile

# Create your views here.


class LoginView(generic.FormView):
form_class = AuthenticationForm
success_url = reverse_lazy('view_airspace')
success_url = reverse_lazy("view_airspace")
template_name = "accounts/login.html"

def get_form (self, form_class=None):
def get_form(self, form_class=None):
if form_class is None:
form_class = self.get_form_class()
return form_class(self.request,**self.get_form_kwargs())
return form_class(self.request, **self.get_form_kwargs())

def form_valid(self, form):
login(self.request, form.get_user())
Expand All @@ -39,16 +42,16 @@ def form_valid(self, form):

def logout_view(request):
logout(request)
return HttpResponseRedirect('/account/login')
return HttpResponseRedirect("/account/login")


class SignUp(generic.CreateView):
form_class = forms.UserCreateForm
success_url = reverse_lazy('login')
template_name = 'accounts/signup.html'
success_url = reverse_lazy("login")
template_name = "accounts/signup.html"


@login_required() # only logged in users should access this
@login_required() # only logged in users should access this
def edit_user(request, pk):
# querying the User object with pk from url
user = User.objects.get(pk=pk)
Expand All @@ -57,9 +60,18 @@ def edit_user(request, pk):
user_form = UserForm(instance=user)

# The sorcery begins from here, see explanation below
ProfileInlineFormset = inlineformset_factory(User, UserProfile,
fields=('phone_number','organization','bio','profile_pic',
'location', 'birth_date'))
ProfileInlineFormset = inlineformset_factory(
User,
UserProfile,
fields=(
"phone_number",
"organization",
"bio",
"profile_pic",
"location",
"birth_date",
),
)

formset = ProfileInlineFormset(instance=user)

Expand All @@ -70,19 +82,23 @@ def edit_user(request, pk):

if user_form.is_valid():
created_user = user_form.save(commit=False)
formset = ProfileInlineFormset(request.POST, request.FILES, instance=created_user)
formset = ProfileInlineFormset(
request.POST, request.FILES, instance=created_user
)

if formset.is_valid():
created_user.save()
formset.save()
# return HttpResponseRedirect('/account/profile/')
return HttpResponseRedirect(reverse('accounts:view_profile', args=(user.id,)))

return render(request, "accounts/edit_profile.html", {
"noodle": pk,
"noodle_form": user_form,
"formset": formset,
})
return HttpResponseRedirect(
reverse("accounts:view_profile", args=(user.id,))
)

return render(
request,
"accounts/edit_profile.html",
{"noodle": pk, "noodle_form": user_form, "formset": formset},
)
else:
raise PermissionDenied

Expand All @@ -98,25 +114,25 @@ def edit_user(request, pk):
# return render(request, self.template_name ,args)


class ViewProfile(LoginRequiredMixin,generic.DetailView):
class ViewProfile(LoginRequiredMixin, generic.DetailView):
template_name = "accounts/profile.html"
model = UserProfile

def get_context_data(self,*args,**kwargs):
context = super(ViewProfile,self).get_context_data(**kwargs)
pk = self.kwargs['pk']
def get_context_data(self, *args, **kwargs):
context = super(ViewProfile, self).get_context_data(**kwargs)
pk = self.kwargs["pk"]
thisuser = User.objects.get(pk=pk)
org = thisuser.userprofile.organization
context['myrpas'] = Rpas.objects.filter(organization = org)
context['myflightlogs'] = FlightLog.objects.filter(user = thisuser)
return (context)
context["myrpas"] = Rpas.objects.filter(organization=org)
context["myflightlogs"] = FlightLog.objects.filter(user=thisuser)
return context


def error_404(request):
data = {}
return render(request, 'errors/404.html', data)
def error_404(request, exception):
data = {}
return render(request, "errors/404.html", data)


def error_500(request):
data = {}
return render(request, 'errors/500.html', data)
data = {}
return render(request, "errors/500.html", data)
Loading

0 comments on commit 270ffec

Please sign in to comment.