Added organisation things. Need to do the form. Committing to push and pull onto server with access to legacy database.

This commit is contained in:
tomtom5152
2014-11-05 15:22:50 +00:00
parent 851e0fd102
commit 12a16d072f
6 changed files with 246 additions and 13 deletions

View File

@@ -1,7 +1,9 @@
__author__ = 'Ghost'
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PyRIGS.settings")
import django
django.setup()
from django.db import connections
@@ -11,6 +13,7 @@ from django.db import transaction
from RIGS import models
import reversion
def setup_cursor():
try:
cursor = connections['legacy'].cursor()
@@ -20,6 +23,7 @@ def setup_cursor():
print(connections._databases)
return None
def import_people():
cursor = setup_cursor()
if cursor is None:
@@ -33,10 +37,11 @@ def import_people():
email += "@nottingham.ac.uk"
notes = ""
if row[5] != "Normal":
if row[5] != "Normal":
notes = row[5]
person, created = models.Person.objects.get_or_create(pk=row[0], name=row[1], phone=row[2], email=email, address=row[4], notes=notes)
person, created = models.Person.objects.get_or_create(pk=row[0], name=row[1], phone=row[2], email=email,
address=row[4], notes=notes)
if created:
print("Created: " + person.__unicode__())
with transaction.atomic(), reversion.create_revision():
@@ -44,6 +49,7 @@ def import_people():
else:
print("Found: " + person.__unicode__())
def import_organisations():
cursor = setup_cursor()
if cursor is None:
@@ -51,15 +57,13 @@ def import_organisations():
sql = """SELECT `id`, `name`, `phone`, `address`, `union_account`, `status` FROM `organisations`"""
cursor.execute(sql)
for row in cursor.fetchall():
unionAccount = False
if row[4] == "1":
unionAccount = True
notes = ""
if row[5] != "Normal":
if row[5] != "Normal":
notes = row[5]
object, created = models.Organisation.objects.get_or_create(pk=row[0], name=row[1], phone=row[2], address=row[3], unionAccount=unionAccount, notes=notes)
object, created = models.Organisation.objects.get_or_create(pk=row[0], name=row[1], phone=row[2],
address=row[3],
unionAccount=row[4], notes=notes)
if created:
print("Created: " + object.__unicode__())
with transaction.atomic(), reversion.create_revision():
@@ -67,9 +71,11 @@ def import_organisations():
else:
print("Found: " + object.__unicode__())
def main():
#import_people()
# import_people()
import_organisations()
if __name__=="__main__":
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,55 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% load widget_tweaks %}
{% block title %}{{ object.name }}{% endblock %}
{% block content %}
<div class="row">
{% if not request.is_ajax %}
<h3>{{ object.name }}</h3>
<div class="pull-right">
<a href="{% url 'organisation_update' object.pk %}" class="btn btn-primary">Edit <span
class="glyphicon glyphicon-pencil"></span></a>
</div>
{% endif %}
<div class="col-sm-10 col-sm-offset-1">
<div class="">
<dl class="dl-horizontal">
<dt>Name</dt>
<dd>{{ object.name }}</dd>
<dt>Phone</dt>
<dd><a href="tel:{{ object.phone }}">{{ object.phone }}</a></dd>
<dt>Email</dt>
<dd><a href="mailto:{{ object.email }}">{{ object.email }}</a></dd>
<dt>Address</dt>
<dd>{{ object.address|linebreaksbr }}</dd>
<dt>Notes</dt>
<dd>{{ object.notes|linebreaksbr }}</dd>
<dt>Union Account</dt>
<dd>{{ object.unionAccount|yesno }}</dd>
</dl>
</div>
</div>
</div>
{% endblock %}
{% if request.is_ajax %}
{% block footer %}
<div class="row">
<div class="col-sm-10 align-left">
Lasted edited at {{ object.last_edited_at|date:"SHORT_DATE_FORMAT" }} by {{ object.last_edited_by }}
</div>
<div class="col-sm-2">
<div class="pull-right">
<a href="{% url 'person_update' object.pk %}" class="btn btn-primary">Edit <span
class="glyphicon glyphicon-pencil"></span></a>
</div>
</div>
</div>
{% endblock %}
{% endif %}

View File

@@ -0,0 +1,53 @@
{% extends request.is_ajax|yesno:'base_ajax.html,base.html' %}
{% load widget_tweaks %}
{% block title %}{% if object.pk %}Edit {{ object.name }}{% else %}Add Person{% endif %}{% endblock %}
{% block content %}
<div class="col-sm-offset-1 col-sm-10">
<h3>Add Person</h3>
<div class="col-md-6">
<form action="{{ form.action }}" method="post" class="form-horizontal">{% csrf_token %}
{% include 'form_errors.html' %}
<div class="form-group">
<label for="{{ form.name.id_for_label }}" class="col-sm-2 control-label">{{ form.name.label }}</label>
<div class="col-sm-10">
{% render_field form.name class+="form-control" placeholder=form.name.label %}
</div>
</div>
<div class="form-group">
<label for="{{ form.phone.id_for_label }}" class="col-sm-2 control-label">{{ form.phone.label }}</label>
<div class="col-sm-10">
{% render_field form.phone class+="form-control" type="tel" placeholder=form.phone.label %}
</div>
</div>
<div class="form-group">
<label for="{{ form.email.id_for_label }}" class="col-sm-2 control-label">{{ form.email.label }}</label>
<div class="col-sm-10">
{% render_field form.email class+="form-control" type="email" placeholder=form.email.label %}
</div>
</div>
<div class="form-group">
<label for="{{ form.address.id_for_label }}" class="col-sm-2 control-label">{{ form.address.label }}</label>
<div class="col-sm-10">
{% render_field form.address class+="form-control" placeholder=form.address.label %}
</div>
</div>
<div class="form-group">
<label for="{{ form.notes.id_for_label }}" class="col-sm-2 control-label">{{ form.notes.label }}</label>
<div class="col-sm-10">
{% render_field form.notes class+="form-control" placeholder=form.notes.label %}
</div>
</div>
<div class="form-group">
<input class="btn btn-primary pull-right" type="submit" />
</div>
</form>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,71 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% load widget_tweaks %}
{% load paginator from filters %}
{% load url_replace from filters %}
{% load orderby from filters %}
{% block title %}Organisations{% endblock %}
{% block content %}
<div class="col-sm-10 col-sm-offset-1">
<div class="row">
<div class="col-sm-10">
<h3>Organisations</h3>
</div>
<div class="col-sm-2">
<a href="{% url 'organisation_create' %}" class="btn btn-default pull-right">New <span
class="glyphicon glyphicon-plus"></span></a>
</div>
<div class="col-sm-3 col-sm-offset-9">
<form class="form form-horizontal col-sm-12">
<div class="form-group">
<input type="search" name="q" placeholder="Search" value="{{ request.GET.q }}"
class="form-control"/>
</div>
</form>
</div>
</div>
<div class="pull-right">{% paginator %}</div>
<div>
<table class="table table-striped">
<thead>
<tr>
<td></td>
<td>Name<a href="?{% orderby request 'orderBy' 'name' %}"><span class="caret"></span></a></td>
<td>Email</td>
<td>Phone</td>
<td>Notes</td>
l
<td>Union Account</td>
<td></td>
</tr>
</thead>
<tbody>
{% for object in object_list %}
<tr>
<td>{{ object.pk }}</td>
<td>{{ object.name }}</td>
<td>{{ object.email }}</td>
<td>{{ object.phone }}</td>
<td>{{ object.notes|yesno|capfirst }}</td>
<td>{{ object.unionAccount|yesno|capfirst }}</td>
<td>
<a href="{% url 'organisation_detail' object.pk %}" class="btn btn-default modal-href">
<span class="glyphicon glyphicon-eye-open"></span>
</a>
<a href="{% url 'organisation_update' object.pk %}" class="btn btn-default"><span
class="glyphicon glyphicon-pencil"></span></a>
</td>
</tr>
{% empty %}
<tr>
<td></td>
<td colspan="5">No people stored</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="align-right">{% paginator %}</div>
</div>
{% endblock %}

View File

@@ -15,14 +15,28 @@ urlpatterns = patterns('',
# People
url(r'^people/$', permission_required_with_403('RIGS.view_person')(views.PersonIndex.as_view()),
name='person_list'),
url(r'^people/(?P<pk>\d+)/$',
permission_required_with_403('RIGS.view_person')(views.PersonDetail.as_view()),
name='person_detail'),
url(r'^people/add/$',
permission_required_with_403('RIGS.add_person')(views.PersonCreate.as_view()),
name='person_add'),
url(r'^people/(?P<pk>\d+)/$',
permission_required_with_403('RIGS.view_person')(views.PersonDetail.as_view()),
name='person_detail'),
url(r'^people/(?P<pk>\d+)/edit/$',
permission_required_with_403('RIGS.change_person')(views.PersonUpdate.as_view()),
name='person_update'),
# Organisations
url(r'^organisations/$',
permission_required_with_403('RIGS.view_organisation')(views.OrganisationIndex.as_view()),
name='organisation_index'),
url(r'^organisations/add/$',
permission_required_with_403('RIGS.add_organisation')(views.OrganisationCreate.as_view()),
name='organisation_create'),
url(r'^organisations/(?P<pk>\d+)/$',
permission_required_with_403('RIGS.view_organisation')(views.OrganisationDetail.as_view()),
name='organisation_detail'),
url(r'^organisation/(?P<pk>\d+)/edit/$',
permission_required_with_403('RIGS.change_organisation')(views.OrganisationUpdate.as_view()),
name='organisation_update'),
)

View File

@@ -58,4 +58,38 @@ class PersonUpdate(generic.UpdateView):
def get_success_url(self):
return reverse_lazy('person_detail', kwargs={
'pk': self.object.pk,
})
class OrganisationIndex(generic.ListView):
model = models.Organisation
paginate_by = 20
def get_queryset(self):
q = self.request.GET.get('q', "")
if len(q) >= 3:
object_list = self.model.objects.filter(Q(name__icontains=q) | Q(address__icontains=q))
else:
object_list = self.model.objects.all()
orderBy = self.request.GET.get('orderBy', "")
if orderBy is not "":
object_list = object_list.order_by(orderBy)
return object_list
class OrganisationDetail(generic.DetailView):
model = models.Organisation
class OrganisationCreate(generic.CreateView):
model = models.Organisation
def get_success_url(self):
return reverse_lazy('organisation_detail', kwargs={
'pk': self.object.pk,
})
class OrganisationUpdate(generic.UpdateView):
model = models.Organisation
def get_success_url(self):
return reverse_lazy('organisation_detail', kwargs={
'pk': self.object.pk,
})