Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sijan branch #77

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .env_sample

This file was deleted.

90 changes: 90 additions & 0 deletions dashboard/templates/change_password.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

{% extends 'base.html' %}
{% load static %}
{% block content %}
<main class="dfid-main">
<!-- dfid breadcrumb -->
<div class="dfid-breadcrumb pdt-100">
<ul class="flex-start">
<li>
<a href="#">Usermanagement</a>
</li>
<li>
Change Password
</li>
<!-- <li>New</li>-->
</ul>
</div>
<!-- program form -->
<form class="program-form" method="POST" enctype="multipart/form-data">

{% csrf_token %}

{% if form.errors %}
{% for field in form %}
{% for error in field.errors %}
<div class="alert alert-danger">
<strong>{{ field.name|title }} {{ error|escape }}</strong>
</div>
{% endfor %}
{% endfor %}
{% for error in form.non_field_errors %}
<div class="alert alert-danger">
<strong>{{ error|escape }}</strong>
</div>
{% endfor %}
{% endif %}


<div class="default-form">


<div class="row">
<div class="col-md-6">
<div class="form-group ">
<label for="id_old_password" class="">Old Password</label>
<input type="password" name="old_password" class="form-control" maxlength="150" autofocus required id="id_username"/>

</div>
</div>
<div class="col-md-6">

</div>
</div>


<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="id_new_password1">New Password:</label>
<input type="password" class="form-control" name="new_password1" required id="id_new_password1"/>
</div>
</div>


</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="id_new_password2">Password confirmation:</label>
<input type="password" class="form-control" name="new_password2" required id="id_new_password2"/>
</div>
</div>
</div>


<div class="form-group mrt-100">
<button type="submit" class="dfid-button sm-button">Submit</button>
</div>

</div>


<!-- category form -->


</form>
</main>

{% endblock %}

2 changes: 2 additions & 0 deletions dashboard/templates/user_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Change Password</th>
<th>User Status</th>
<th>role</th>
<th>Partner</th>
Expand All @@ -52,6 +53,7 @@ <h6>{{user.name}}</h6>
</a>
</td>
<td>{{ user.email }}</td>
<td><a href="/dashboard/changepassword" ><button class="border-button dfid-button ">Change Password</button></a></td>
<td>


Expand Down
5 changes: 5 additions & 0 deletions dashboard/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
path('palika-list/', views.PalikaList.as_view(), name='palika-list'),
path('palika-add/', views.PalilkaCreate.as_view(), name='palika-add'),
path('palika-delete/<int:pk>', views.PalikaDelete.as_view(), name='palika-delete'),
path('palika-edit/<int:pk>', views.PalikaUpdate.as_view(), name='palika-update'),

path('user-list/', views.UserList.as_view(), name='user-list'),
path('activate/<int:id>', views.activate_user, name='activate'),
Expand Down Expand Up @@ -129,4 +130,8 @@
path('gis_style_layer_add/<int:pk>', views.StyleCreate.as_view(), name='style-create'),
path('gis_style_layer_edit/<int:pk>', views.StyleUpdate.as_view(), name='style-update'),

path('changepassword', views.change_password, name='change_password'),



]
47 changes: 47 additions & 0 deletions dashboard/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.shortcuts import render, redirect
import pandas as pd
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth import update_session_auth_hash
from django.contrib.auth.forms import PasswordChangeForm
import requests
from django.template.loader import render_to_string
from django.core.mail import EmailMessage
Expand Down Expand Up @@ -1357,6 +1359,32 @@ def form_valid(self, form):
log = Log.objects.create(user=user_data, message=message, type="create")
return HttpResponseRedirect(self.get_success_url())

class PalikaUpdate(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
model = GapaNapa
template_name = 'palika_edit.html'
form_class = PalikaCreateForm
success_message = 'Palika successfully Updated'

def get_context_data(self, **kwargs):
data = super(PalikaUpdate, self).get_context_data(**kwargs)
user = self.request.user
user_data = UserProfile.objects.get(user=user)
data['user'] = user_data
data['province'] = Province.objects.values('id', 'name').order_by('id')
data['district'] = District.objects.values('id', 'name').order_by('id')
data['active'] = 'location'
return data

def get_success_url(self):
return reverse_lazy('palika-list')

def form_valid(self, form):
user_data = UserProfile.objects.get(user=self.request.user)
self.object = form.save()
message = "Municipality " + self.object.name + " has been updated by " + self.request.user.username
log = Log.objects.create(user=user_data, message=message, type="create")
return HttpResponseRedirect(self.get_success_url())


class MarkerValueCreate(SuccessMessageMixin, LoginRequiredMixin, CreateView):
model = MarkerValues
Expand Down Expand Up @@ -2464,3 +2492,22 @@ def get_context_data(self, **kwargs):
def get_success_url(self):
id_gis = GisStyle.objects.get(id=self.kwargs['pk'])
return "/dashboard/gis_style_layer_list/" + str(id_gis.layer.id)



def change_password(request):
if request.method == 'POST':
form = PasswordChangeForm(request.user, request.POST)
if form.is_valid():
user = form.save()
update_session_auth_hash(request, user) # Important!
messages.success(request, 'Your password was successfully updated!')
return redirect('user-list')
else:
messages.error(request, 'Please correct the error below.')
else:
password = request.user.password
form = PasswordChangeForm(request.user)
return render(request, 'change_password.html', {
'form': form
})
11 changes: 0 additions & 11 deletions dvs/local_setting_sample.py

This file was deleted.

37 changes: 36 additions & 1 deletion dvs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
from .settings import *
#import socket

sentry_sdk.init(
dsn="https://[email protected]/1524106",
Expand Down Expand Up @@ -92,17 +94,20 @@
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases


DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'postgres',
'USER': 'postgres',
"PASSWORD": '',
'HOST': 'localhost',
'HOST': 'db',
'PORT': '5432'
}
}

DEBUG = True

# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

Expand Down Expand Up @@ -165,6 +170,36 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/


EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'UW9boQYFZiiM3NsKIuKD'
EMAIL_PORT = 587

LOGIN_URL = '/dashboard/login/'
LOGIN_REDIRECT_URL = '/dashboard/main/'
LOGOUT_REDIRECT_URL = '/dashboard/login/'
SITE_URL = 'http://localhost:8000/'

# MIDDLEWARE += [
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
# ]
#
# INSTALLED_APPS += [
# 'debug_toolbar',
#
# ]

CORS_ORIGIN_ALLOW_ALL = True
# CORS_ORIGIN_WHITELIST = [
# "http://localhost:8001",
# ]

# hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
# INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2']

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
Expand Down