Updates to person model. Removed comments for now in favour of a simple notes section that can be easily modified as a text field. Will look at introducing this again in the future.

This commit is contained in:
tomtom5152
2014-10-31 02:23:20 +00:00
parent c39504a4ce
commit 2a0a223902
9 changed files with 121 additions and 21 deletions

View File

@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('RIGS', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='ModelComment',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('postedAt', models.DateTimeField(auto_now=True)),
('message', models.TextField()),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Person',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=50)),
('phone', models.CharField(max_length=15, null=True, blank=True)),
('email', models.EmailField(max_length=75, null=True, blank=True)),
('address', models.TextField(null=True, blank=True)),
('comments', models.ManyToManyField(to='RIGS.ModelComment')),
],
options={
},
bases=(models.Model,),
),
]

View File

@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('RIGS', '0002_modelcomment_person'),
]
operations = [
migrations.RemoveField(
model_name='modelcomment',
name='user',
),
migrations.RemoveField(
model_name='person',
name='comments',
),
migrations.DeleteModel(
name='ModelComment',
),
migrations.AddField(
model_name='person',
name='notes',
field=models.TextField(null=True, blank=True),
preserve_default=True,
),
]

View File

@@ -16,12 +16,6 @@ class Profile(AbstractUser):
url = "https://www.gravatar.com/avatar/" + hashlib.md5(self.email).hexdigest() + "?d=identicon&s=500"
return url
class ModelComment(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
postedAt = models.DateTimeField(auto_now=True)
message = models.TextField()
@reversion.register
class Person(models.Model):
name = models.CharField(max_length=50)
@@ -30,10 +24,10 @@ class Person(models.Model):
address = models.TextField(blank=True, null=True)
comments = models.ManyToManyField('ModelComment', blank=True)
notes = models.TextField(blank=True, null=True)
def __unicode__(self):
string = self.name
if self.comments.count() > 0:
if len(self.notes) > 0:
string += "*"
return string

View File

@@ -6,8 +6,10 @@
{% block content %}
<div class="col-sm-10 col-sm-offset-1">
<h3>{{ object.name }}</h3>
<div class="pull-right">
<a href="{% url 'person_update' object.pk %}" class="btn btn-primary">Edit <span class="glyphicon glyphicon-pencil"></span></a>
<a href="{% url 'person_update' object.pk %}" class="btn btn-primary">Edit <span
class="glyphicon glyphicon-pencil"></span></a>
</div>
<div class="row col-sm-12">
<div class="col-sm-6">
@@ -23,6 +25,9 @@
<dt>Address</dt>
<dd>{{ object.address|linebreaksbr }}</dd>
<dt>Notes</dt>
<dd>{{ object.notes|linebreaksbr }}</dd>
</dl>
</div>
</div>

View File

@@ -37,6 +37,13 @@
</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>

View File

@@ -16,7 +16,7 @@
<td>Name</td>
<td>Email</td>
<td>Phone</td>
<td>Comments</td>
<td>Notes</td>
<td></td>
</tr>
</thead>
@@ -27,7 +27,7 @@
<td>{{ person.name }}</td>
<td>{{ person.email }}</td>
<td>{{ person.phone }}</td>
<td>{{ person.comment_list|length }}</td>
<td>{{ person.notes|yesno|capfirst }}</td>
<td>Add buttons</td>
</tr>
{% empty %}

View File

@@ -5,17 +5,24 @@ from RIGS import views
from PyRIGS.decorators import permission_required_with_403
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'PyRIGS.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
# Examples:
# url(r'^$', 'PyRIGS.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^closemodal/$', views.CloseModal.as_view(), name='closemodal'),
url('^user/login/$', 'RIGS.views.login', name='login'),
url('^user/login/$', 'RIGS.views.login', name='login'),
# 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+)/edit/$', permission_required_with_403('RIGS.change_person')(views.PersonUpdate.as_view()), name='person_update'),
# 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+)/edit/$',
permission_required_with_403('RIGS.change_person')(views.PersonUpdate.as_view()),
name='person_update'),
)

View File

@@ -12,6 +12,18 @@ def login(request, **kwargs):
from django.contrib.auth.views import login
return login(request)
"""
Called from a modal window (e.g. when an item is submitted to an event/invoice).
May optionally also include some javascript in a success message to cause a load of
the new information onto the page.
"""
class CloseModal(generic.TemplateView):
template_name = 'closemodal.html'
def get_context_data(self, **kwargs):
from django.contrib import messages
return {'messages', messages.get_messages(self.request)}
class PersonIndex(generic.ListView):
model = models.Person