Skip to content

Commit 23c5a2d

Browse files
committed
user stuff is finished
1 parent d84d7f7 commit 23c5a2d

25 files changed

+335
-29
lines changed

metaSearch/mainApp/JoinForm.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class Meta:
88
fields = [] # Excluding updated_at and created_at as the property 'auto_now_add=True'
99
# makes them read-only, resulting in an error when adding them to this form.
1010
for f in Project._meta.get_fields():
11-
if f.name != 'updated_at' and f.name != 'created_at':
11+
if f.name != 'updated_at' and f.name != 'created_at' and f.name!='contact_loc' and f.name!='geo_location':
1212
fields.append(f.name)
1313

14-
contact_loc = CharField(max_length=200, required=True)
15-
geo_location = CharField(max_length=200, required=True)
14+
contact_loc = CharField(max_length=200, required=False)
15+
geo_location = CharField(max_length=200, required=False)

metaSearch/mainApp/forms.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from django import forms
2+
from django.contrib.auth.models import User # fill in custom user info then save it
3+
from django.contrib.auth.forms import UserCreationForm
4+
5+
class MyRegistrationForm(UserCreationForm):
6+
email = forms.EmailField(required = True)
7+
first_name = forms.CharField(required = False)
8+
last_name = forms.CharField(required = False)
9+
10+
11+
12+
class Meta:
13+
model = User
14+
fields = ('username', 'email', 'password1', 'password2')
15+
16+
def save(self,commit = True):
17+
user = super(MyRegistrationForm, self).save(commit = False)
18+
user.email = self.cleaned_data['email']
19+
user.first_name = self.cleaned_data['first_name']
20+
user.last_name = self.cleaned_data['last_name']
21+
22+
23+
if commit:
24+
user.save()
25+
26+
return user
27+
28+
class UpdateProfile(forms.ModelForm):
29+
class Meta:
30+
model = User
31+
fields = ['username', 'email']
32+

metaSearch/mainApp/management/commands/load_csv_data.py

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from mainApp import models
55
from mainApp.models import Project, Category, ProgrammingLanguage, PageLanguage, Kind, GeoLocation
66
from django.core.exceptions import ObjectDoesNotExist
7+
from django.contrib.auth.models import Group
8+
from guardian.shortcuts import assign_perm
79

810

911
# 0 id
@@ -151,6 +153,12 @@ def handle(self, *args, **options):
151153
print("Initializing Categories")
152154
self.init_categories()
153155
print("Initializing Projects")
156+
157+
#group of users, which are allowed to edit each project
158+
editors, created = Group.objects.get_or_create(name='editors')
159+
if created:
160+
editors.save()
161+
154162
csvReader = csv.reader(getProjectCsvData().split('\n'), delimiter=',')
155163
first_line= csvReader.__next__() # skip the first row, because these are the column names
156164
print(first_line)
@@ -307,6 +315,9 @@ def handle(self, *args, **options):
307315
if currentCat.parent != None and len(newPro.categories.all().filter(pk=currentCat.parent.pk)) == 0:
308316
newPro.categories.add(currentCat.parent)
309317

318+
319+
assign_perm('change_project', editors, newPro)
320+
310321
newPro.save()
311322
else:
312323
print("GOT NO TITLE in Project id: " + row[0] )

metaSearch/mainApp/models.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from django.db.models.signals import pre_save
88
from geopy.geocoders import Nominatim
99
from django.core.urlresolvers import reverse
10+
from django.contrib.auth.models import User
11+
1012

1113
import time
1214

@@ -143,7 +145,7 @@ class Project(models.Model):
143145
kind = models.ManyToManyField(Kind)
144146
organisation_name = models.CharField(max_length=200, blank=True, default='')
145147
categories = models.ManyToManyField(Category)
146-
148+
created_by = models.ForeignKey(User, blank=True, null=True)
147149
description_de = models.TextField()
148150
description_en = models.TextField(blank = True, default='')
149151
description_fr = models.TextField(blank = True, default='')

metaSearch/mainApp/templates/mainApp/base.html metaSearch/mainApp/templates/base.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@
7777
<span class="caret"></span>
7878
</button>
7979
<ul class="dropdown-menu" aria-labelledby="userLoggedInDropDown">
80-
<li><a href="#">Profile</a></li>
80+
<li><a href="{% url 'user_profile' %}">Profile</a></li>
8181
<li role="separator" class="divider"></li>
82-
<li><a href="{% url 'logout' %}">Log Out</a></li>
82+
<li><a href="{% url 'auth_logout' %}">Log Out</a></li>
8383
</ul>
8484
</li>
8585
{% else %}
86-
<li><a href="{% url 'login' %}">login</a></li>
86+
<li><a href="{% url 'auth_login' %}">login</a></li>
8787
{% endif %}
8888
</ul>
8989
{% endif %}

metaSearch/mainApp/templates/mainApp/api_index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% extends "mainApp/base.html" %}
1+
{% extends "base.html" %}
22
{% load i18n %}
33
{% block content %}
44
<form action="" method="GETModel could not be found" class="form-inline">

metaSearch/mainApp/templates/mainApp/data.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% extends "mainApp/base.html" %}
1+
{% extends "base.html" %}
22

33
{% block content %}
44
<div class="page-header">

metaSearch/mainApp/templates/mainApp/detail.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% extends "mainApp/base.html" %}
1+
{% extends "base.html" %}
22
{% load i18n %}
33

44
{% block content %}

metaSearch/mainApp/templates/mainApp/edit.html

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
{% extends "mainApp/base.html" %}
1+
{% extends "base.html" %}
22
{% load extras %}
33
{% load widget_tweaks %}
4+
{% load i18n %}
45

56
{% block content %}
67
<form action="" method="post" id="EditForm">{% csrf_token %}
@@ -41,10 +42,10 @@ <h3>Edit {{project}}</h3>
4142
{% render_field form.description_ar class+="form-control" style="direction: rtl;" %}
4243
</div>
4344
</div>
44-
<div class="form-group {{ form.contact_loc|is_required }}">
45+
<div class="form-group {{ form.contact_loc }}">
4546
<label for="{{ form.contact_loc.id_for_label }}" class="control-label">Contact Address</label>
4647
<div id="{{ form.contact_loc.id_for_label }}" class="form-group
47-
{{ form.contact_loc|is_required }} form-group-addresses">
48+
{{ form.contact_loc}} form-group-addresses">
4849
<label for="{{ form.contact_address_street.id_for_label }}" class="control-label">Street</label>
4950
{% render_field form.contact_address_street class+="form-control form-control-address" %}
5051
<label for="{{ form.contact_address_housenr.id_for_label }}" class="control-label">Number</label>
@@ -58,10 +59,10 @@ <h3>Edit {{project}}</h3>
5859
</div>
5960
</div>
6061

61-
<div class="form-group {{ form.geo_location|is_required }}">
62+
<div class="form-group {{ form.geo_location }}">
6263
<label for="{{ form.geo_location.id_for_label }}" class="control-label">Area</label>
6364
<div id="{{ form.geo_location.id_for_label }}" class="form-group
64-
{{ form.geo_location|is_required }} form-group-addresses">
65+
{{ form.geo_location }} form-group-addresses">
6566
<label for="{{ form.area_city.id_for_label }}" class="control-label">City</label>
6667
{% render_field form.area_city class+="form-control form-control-address" %}
6768
<label for="{{ form.area_state.id_for_label }}" class="control-label">State</label>
@@ -136,6 +137,7 @@ <h3>Edit {{project}}</h3>
136137
selectableHeader: "<div class='control-label'>Selectable items</div>",
137138
selectionHeader: "<div class='control-label'>Selections</div>"
138139
});
140+
console.log('{{ form.instance.categories}}')
139141
}
140142

141143
$(function () {
@@ -146,7 +148,7 @@ <h3>Edit {{project}}</h3>
146148
$.each(data, function (key, val) {
147149
var grp = document.createElement('optgroup');
148150
grp.setAttribute("label", val.name)
149-
$.getJSON("../../../api/search/category?format=json&parent=" + val.id, function (data) {
151+
$.getJSON("../../../api/search/category?format=json&parent*id=" + val.id, function (data) {
150152
$.each(data, function (key, val) {
151153
var opt = document.createElement('option')
152154
opt.value = val.id

metaSearch/mainApp/templates/mainApp/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
{% get_current_language as LANGUAGE_CODE %}
44
{% block content %}
55
<div class="row">
6-
<form action="javascript:void(0)" method="GET" class="form-inline col-xs-12"> {% csrf_token %}
6+
<div method="GET" class="form-inline col-xs-12"> {% csrf_token %}
77
<input type="text" name="query" class="form-control" id="search" autocomplete="off">
88
<button type="submit" value="Search" class="btn btn-default hidden">{% trans "Search" %}</button>
9+
</div>
910
</div>
1011
<div class="row">
1112
<div id="filter-area" class="col-xs-4">
@@ -17,7 +18,6 @@
1718
</div>
1819
{% endfor %}
1920
</div>
20-
</form>
2121
<div id="search-results" class="col-xs-8"></div>
2222
</div>
2323
{%endblock%}

metaSearch/mainApp/templates/mainApp/project_confirm_delete.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% extends "mainApp/base.html" %}
1+
{% extends "base.html" %}
22
{% load i18n %}
33

44
{% block content %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% extends "base.html" %}
2+
{% load i18n %}
3+
{% get_current_language as LANGUAGE_CODE %}
4+
{% block content %}
5+
<div class="row">
6+
<div id="area-select" class="col-xs-4">
7+
<p><a href="{% url 'user_profile' %}">Profile</a></p>
8+
<p><a href="{% url 'auth_password_change' %}">Change Password</a></p>
9+
<p><a href="{% url 'user_projects' %}">Projects</a></p>
10+
</div>
11+
<div id="user-site" class="col-xs-8">
12+
{% block usersite %}{% endblock %}
13+
</div>
14+
</div>
15+
{%endblock%}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{% extends "mainApp/userMain.html" %}
2+
{% load i18n %}
3+
{% get_current_language as LANGUAGE_CODE %}
4+
{% block usersite %}
5+
<form action="{% url 'user_profile' %}" method="post">
6+
{% csrf_token %}
7+
{{ form.non_field_errors }}
8+
9+
{% for field in form %}
10+
<div class="fieldWrapper">
11+
{{ field.label_tag }}
12+
{{ field }}
13+
{{ field.errors }}
14+
</div>
15+
{% endfor %}
16+
17+
<input type="submit" value="Submit" />
18+
</form>
19+
20+
21+
22+
{%endblock%}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% extends "mainApp/userMain.html" %}
2+
{% load i18n %}
3+
{% get_current_language as LANGUAGE_CODE %}
4+
{% block usersite %}
5+
{% for project in projects %}
6+
<h4 class="content"><a href="{% url 'detail' project.id %}">{{ project.title }}</a></h4>
7+
{% endfor %}
8+
9+
{%endblock%}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
5+
Logged out!
6+
7+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
5+
{% if form.errors %}
6+
<p>Your username and password didn't match. Please try again.</p>
7+
{% endif %}
8+
9+
{% if next %}
10+
{% if user.is_authenticated %}
11+
<p>Your account doesn't have access to this page. To proceed,
12+
please login with an account that has access.</p>
13+
{% else %}
14+
<p>Please login to see this page.</p>
15+
{% endif %}
16+
{% endif %}
17+
18+
<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
19+
{% csrf_token %}
20+
<table>
21+
<tr>
22+
<td>{{ form.username.label_tag }}</td>
23+
<td>{{ form.username }}</td>
24+
</tr>
25+
<tr>
26+
<td>{{ form.password.label_tag }}</td>
27+
<td>{{ form.password }}</td>
28+
</tr>
29+
</table>
30+
31+
<input type="submit" value="login" />
32+
<input type="hidden" name="next" value="{{ next }}" />
33+
</form>
34+
35+
<p> New? <a href="{% url 'registration_register'%}">Register!</a></p>
36+
{# Assumes you setup the password_reset view in your URLconf #}
37+
{# <p><a href="{% url 'password_reset' %}">Lost password?</a></p>#}
38+
39+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
5+
You are not allowed to edit this page.
6+
7+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% extends "mainApp/userMain.html" %}
2+
3+
{% block usersite %}
4+
<p> Password change Successful!</p>
5+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends "mainApp/userMain.html" %}
2+
3+
{% block usersite %}
4+
<form action="{% url 'auth_password_change' %}" method="post">
5+
{% csrf_token %}
6+
{{form.as_p}}
7+
<input type="submit" value="Submit" />
8+
</form>
9+
10+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
5+
<p> Registration completed!</p>
6+
7+
8+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
<form action="{% url 'registration_register' %}" method="post">
5+
{% csrf_token %}
6+
7+
{{form.as_p}}
8+
9+
<input type="submit" value="Submit" />
10+
</form>
11+
12+
{% endblock %}

metaSearch/mainApp/urls.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
from django.conf.urls import url
1+
from django.conf.urls import url, include
22
from django.views.generic import TemplateView
33
from django.contrib.auth import views as auth_views
4-
54
from . import views
65
from . import views_api
76

87
app_name = 't'
98
urlpatterns = [
109
url(r'^$', views.index, name='index'),
11-
url(r'^login/$', 'django.contrib.auth.views.login', name='login'),
12-
url(r'^logout/$', 'django.contrib.auth.views.logout',{'next_page': '/mainApp/'}, name='logout'),
13-
url(r'^register/$', views.register, name='register'),
10+
# url(r'^login/$', 'django.contrib.auth.views.login', name='login'),
11+
# url(r'^logout/$', 'django.contrib.auth.views.logout',{'next_page': '/mainApp/'}, name='logout'),
12+
# url(r'^register/$', views.register, name='register'),
13+
url(r'^accounts/', include('registration.backends.simple.urls')),
1414
url(r'^(?P<project_id>\d+)/$', views.detail, name='detail'),
1515
url(r'^search/autocomplete', views.search_titles, name='title'),
1616
url(r'^search/fulltext', views.search_fulltext, name='fulltext'),
1717
# url(r'^new/', views.ProjectNewView.as_view(), name='new'),
1818
url(r'^new/', views.join_page, name='new'),
1919
url(r'^(?P<pk>[0-9]+)/delete/$', views.ProjectDelete.as_view(), name='project-delete'),
20-
url(r'^(?P<pk>[0-9]+)/edit/$', views.ProjectEdit.as_view(), name='project-edit'),
20+
url(r'^(?P<project_id>\d+)/edit/$', views.edit_page, name='project-edit'),
2121
url(r'^data/', views.data, name='data'),
22+
url(r'^accounts/profile', views.user_profile, name='user_profile'),
23+
url(r'^accounts/projects', views.user_projects, name='user_projects'),
2224
]

0 commit comments

Comments
 (0)