Permalink
Browse files

Refactor of profiles using django-user-accounts and geonode.people

  • Loading branch information...
jj0hns0n committed Nov 5, 2012
1 parent b34a35b commit 95d43b1e313f88472a38c90d3c7d057363c89481
Showing with 198 additions and 384 deletions.
  1. +3 −3 geonode/layers/forms.py
  2. +6 −6 geonode/layers/models.py
  3. +1 −1 geonode/layers/templates/layers/layer_replace.html
  4. +1 −1 geonode/layers/templates/layers/layer_upload.html
  5. +3 −3 geonode/layers/utils.py
  6. +8 −8 geonode/layers/views.py
  7. +2 −2 geonode/maps/views.py
  8. +3 −3 geonode/people/admin.py
  9. +4 −4 geonode/people/forms.py
  10. +14 −25 geonode/people/models.py
  11. 0 geonode/people/templates/{idios → people}/base.html
  12. +2 −2 geonode/people/templates/people/forgot_username_form.html
  13. +2 −2 geonode/people/templates/{idios → people}/profile_create.html
  14. +6 −5 geonode/people/templates/{idios/profile.html → people/profile_detail.html}
  15. +2 −2 geonode/people/templates/{idios → people}/profile_edit.html
  16. +3 −3 geonode/people/templates/{idios/profiles.html → people/profile_list.html}
  17. +4 −0 geonode/people/urls.py
  18. +46 −0 geonode/people/views.py
  19. +2 −2 geonode/search/extension.py
  20. +7 −7 geonode/search/fixtures/search_testdata.json
  21. +3 −3 geonode/search/populate_search_test_data.py
  22. +2 −2 geonode/search/search.py
  23. +2 −2 geonode/search/tests.py
  24. +2 −2 geonode/search/views.py
  25. +15 −7 geonode/settings.py
  26. +5 −0 geonode/social_signals.py
  27. +1 −1 geonode/templates/401.html
  28. +2 −2 geonode/templates/404.html
  29. +2 −2 geonode/templates/500.html
  30. +2 −2 geonode/templates/_permissions_form_js.html
  31. +1 −1 geonode/templates/activity/actor.html
  32. +1 −1 geonode/templates/announcements/announcement_detail.html
  33. +1 −1 geonode/templates/announcements/announcement_list.html
  34. +5 −5 geonode/templates/base_geonode.html
  35. +1 −1 geonode/templates/developer.html
  36. +1 −1 geonode/templates/help.html
  37. +1 −1 geonode/templates/notification/notice_settings.html
  38. +1 −1 geonode/templates/notification/notices.html
  39. +1 −1 geonode/templates/notification/single.html
  40. +0 −86 geonode/templates/profiles/profile_detail.html
  41. +0 −11 geonode/templates/registration/activate.html
  42. +0 −1 geonode/templates/registration/activation_complete.html
  43. +0 −6 geonode/templates/registration/activation_email.txt
  44. +0 −1 geonode/templates/registration/activation_email_subject.txt
  45. +0 −1 geonode/templates/registration/base.html
  46. +0 −8 geonode/templates/registration/logged_out.html
  47. +0 −24 geonode/templates/registration/login.html
  48. +0 −9 geonode/templates/registration/logout.html
  49. +0 −6 geonode/templates/registration/password_change_done.html
  50. +0 −16 geonode/templates/registration/password_change_form.html
  51. +0 −8 geonode/templates/registration/password_reset_complete.html
  52. +0 −19 geonode/templates/registration/password_reset_confirm.html
  53. +0 −6 geonode/templates/registration/password_reset_done.html
  54. +0 −5 geonode/templates/registration/password_reset_email.html
  55. +0 −15 geonode/templates/registration/password_reset_form.html
  56. +0 −6 geonode/templates/registration/registration_complete.html
  57. +0 −15 geonode/templates/registration/registration_form.html
  58. +1 −1 geonode/templates/relationships/confirm.html
  59. +1 −1 geonode/templates/relationships/relationship_list.html
  60. +1 −1 geonode/templates/relationships/success.html
  61. +1 −0 geonode/templates/site_base.html
  62. +7 −8 geonode/urls.py
  63. +8 −0 requirements.txt
  64. +11 −15 setup.py
View
@@ -27,7 +27,7 @@
from django.utils.translation import ugettext_lazy as _
from geonode.layers.models import Layer, Attribute
-from geonode.people.models import Contact
+from geonode.people.models import Profile
class JSONField(forms.CharField):
@@ -48,11 +48,11 @@ class LayerForm(forms.ModelForm):
poc = forms.ModelChoiceField(empty_label = "Person outside GeoNode (fill form)",
label = "Point Of Contact", required=False,
- queryset = Contact.objects.exclude(user=None))
+ queryset = Profile.objects.exclude(user=None))
metadata_author = forms.ModelChoiceField(empty_label = "Person outside GeoNode (fill form)",
label = "Metadata Author", required=False,
- queryset = Contact.objects.exclude(user=None))
+ queryset = Profile.objects.exclude(user=None))
keywords = taggit.forms.TagField(required=False,
help_text=_("A space or comma-separated list of keywords"))
class Meta:
View
@@ -42,7 +42,7 @@
from geonode import GeoNodeException
from geonode.utils import _wms, _user, _password, get_wms, bbox_to_wkt
from geonode.gs_helpers import cascading_delete
-from geonode.people.models import Contact, Role
+from geonode.people.models import Profile, Role
from geonode.security.models import PermissionLevelMixin
from geonode.security.models import AUTHENTICATED_USERS, ANONYMOUS_USERS
from geonode.layers.ows import wcs_links, wfs_links, wms_links
@@ -85,7 +85,7 @@ def admin_contact(self):
if superusers.count() == 0:
raise RuntimeError('GeoNode needs at least one admin/superuser set')
- contact = Contact.objects.get_or_create(user=superusers[0],
+ contact = Profile.objects.get_or_create(user=superusers[0],
defaults={"name": "Geonode Admin"})[0]
return contact
@@ -316,7 +316,7 @@ class Layer(ResourceBase):
popular_count = models.IntegerField(default=0)
share_count = models.IntegerField(default=0)
- contacts = models.ManyToManyField(Contact, through='ContactRole')
+ contacts = models.ManyToManyField(Profile, through='ContactRole')
default_style = models.ForeignKey(Style, related_name='layer_default_style', null=True, blank=True)
styles = models.ManyToManyField(Style, related_name='layer_styles')
@@ -492,9 +492,9 @@ def __str__(self):
class ContactRole(models.Model):
"""
- ContactRole is an intermediate model to bind Contacts and Layers and apply roles.
+ ContactRole is an intermediate model to bind Profiles as Contacts to Layers and apply roles.
"""
- contact = models.ForeignKey(Contact)
+ contact = models.ForeignKey(Profile)
layer = models.ForeignKey(Layer, null=True)
role = models.ForeignKey(Role)
@@ -641,7 +641,7 @@ def geoserver_pre_save(instance, sender, **kwargs):
if instance.poc and instance.poc.user:
gs_layer.attribution = str(instance.poc.user)
- profile = Contact.objects.get(user=instance.poc.user)
+ profile = Profile.objects.get(user=instance.poc.user)
gs_layer.attribution_link = settings.SITEURL[:-1] + profile.get_absolute_url()
gs_catalog.save(gs_layer)
@@ -9,7 +9,7 @@
{{ block.super }}
{% endblock %}
-{% block main %}
+{% block body %}
{% if errors %}
<div id="errors">
@@ -237,7 +237,7 @@ <h2 class="page-title">{% trans "Upload Layers" %}</h2>
var permissionsEditor = new GeoNode.PermissionsEditor({
renderTo: "permissions_form",
- userLookup: "{% url auth_ajax_lookup %}",
+ userLookup: "{% url account_ajax_lookup %}",
listeners: {
updated: function(pe) {
permissionsField.setValue(Ext.util.JSON.encode(pe.writePermissions()));
View
@@ -40,7 +40,7 @@
from geonode.people.utils import get_valid_user
from geonode.layers.models import Layer
from geonode.layers.metadata import set_metadata
-from geonode.people.models import Contact
+from geonode.people.models import Profile
from geonode.gs_helpers import cascading_delete
from geonode.gs_helpers import get_sld_for
from geonode.gs_helpers import delete_from_postgis
@@ -465,9 +465,9 @@ def save(layer, base_file, user, overwrite=True, title=None,
# A user without a profile might be uploading this
logger.info('>>> Step 9. Creating points of contact records for '
'[%s]', name)
- pc, __ = Contact.objects.get_or_create(user=user,
+ pc, __ = Profile.objects.get_or_create(user=user,
defaults={"name": user.username})
- ac, __ = Contact.objects.get_or_create(user=user,
+ ac, __ = Profile.objects.get_or_create(user=user,
defaults={"name": user.username}
)
View
@@ -53,7 +53,7 @@
from geonode.layers.utils import save
from geonode.layers.utils import layer_set_permissions
from geonode.utils import resolve_object
-from geonode.people.forms import ContactForm, PocForm
+from geonode.people.forms import ProfileForm, PocForm
from geonode.security.views import _perms_info_json
from geonode.security.models import AUTHENTICATED_USERS, ANONYMOUS_USERS
from django.forms.models import inlineformset_factory
@@ -224,12 +224,12 @@ def layer_metadata(request, layername, template='layers/layer_metadata.html'):
new_keywords = layer_form.cleaned_data['keywords']
if new_poc is None:
- poc_form = ContactForm(request.POST, prefix="poc")
+ poc_form = ProfileForm(request.POST, prefix="poc")
if poc_form.has_changed and poc_form.is_valid():
new_poc = poc_form.save()
if new_author is None:
- author_form = ContactForm(request.POST, prefix="author")
+ author_form = ProfileForm(request.POST, prefix="author")
if author_form.has_changed and author_form.is_valid():
new_author = author_form.save()
@@ -251,17 +251,17 @@ def layer_metadata(request, layername, template='layers/layer_metadata.html'):
return HttpResponseRedirect(reverse('layer_detail', args=(layer.typename,)))
if poc.user is None:
- poc_form = ContactForm(instance=poc, prefix="poc")
+ poc_form = ProfileForm(instance=poc, prefix="poc")
else:
layer_form.fields['poc'].initial = poc.id
- poc_form = ContactForm(prefix="poc")
+ poc_form = ProfileForm(prefix="poc")
poc_form.hidden=True
if metadata_author.user is None:
- author_form = ContactForm(instance=metadata_author, prefix="author")
+ author_form = ProfileForm(instance=metadata_author, prefix="author")
else:
layer_form.fields['metadata_author'].initial = metadata_author.id
- author_form = ContactForm(prefix="author")
+ author_form = ProfileForm(prefix="author")
author_form.hidden=True
return render_to_response(template, RequestContext(request, {
@@ -691,4 +691,4 @@ def feature_edit_check(request, layername):
layer = get_object_or_404(Layer, typename=layername);
return HttpResponse(
status=200 if request.user.has_perm('maps.change_layer', obj=layer) and layer.storeType == 'dataStore' else 401
- )
+ )
View
@@ -48,7 +48,7 @@
from geonode.utils import default_map_config
from geonode.utils import resolve_object
from geonode.maps.forms import MapForm
-from geonode.people.models import Contact
+from geonode.people.models import Profile
from geonode.security.models import AUTHENTICATED_USERS, ANONYMOUS_USERS
from geonode.security.views import _perms_info
@@ -651,7 +651,7 @@ def _maps_search(query, start, limit, sort_field, sort_dir):
for m in map_query.all()[start:start+limit]:
try:
- owner_name = Contact.objects.get(user=m.owner).name
+ owner_name = Profile.objects.get(user=m.owner).name
except Exception:
owner_name = m.owner.first_name + " " + m.owner.last_name
View
@@ -19,14 +19,14 @@
#########################################################################
from django.contrib import admin
-from geonode.people.models import Contact, Role
+from geonode.people.models import Profile, Role
from geonode.layers.models import ContactRole
class ContactRoleInline(admin.TabularInline):
model = ContactRole
-class ContactAdmin(admin.ModelAdmin):
+class ProfileAdmin(admin.ModelAdmin):
inlines = [ContactRoleInline]
-admin.site.register(Contact, ContactAdmin)
+admin.site.register(Profile, ProfileAdmin)
admin.site.register(Role)
View
@@ -18,7 +18,7 @@
#
#########################################################################
-from geonode.people.models import Contact
+from geonode.people.models import Profile
from geonode.layers.models import ContactRole
from django import forms
from django.utils.translation import ugettext_lazy as _
@@ -40,12 +40,12 @@ class Meta:
class PocForm(forms.Form):
contact = forms.ModelChoiceField(label = "New point of contact",
- queryset = Contact.objects.exclude(user=None))
+ queryset = Profile.objects.exclude(user=None))
-class ContactForm(forms.ModelForm):
+class ProfileForm(forms.ModelForm):
keywords = taggit.forms.TagField(required=False,
help_text=_("A space or comma-separated list of keywords"))
class Meta:
- model = Contact
+ model = Profile
exclude = ('user',)
View
@@ -21,18 +21,18 @@
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
-from django.db.models import signals
+from django.db.models.signals import post_save
+from django.dispatch import receiver
from django.utils.translation import ugettext as _
from django.contrib.auth.models import User, Permission
-from idios.models import ProfileBase, create_profile
-
from geonode.layers.enumerations import COUNTRIES
from geonode.people.enumerations import ROLE_VALUES, CONTACT_FIELDS
-class Contact(ProfileBase):
+class Profile(models.Model):
+ user = models.OneToOneField(User, related_name="profile", null=True, blank=True)
name = models.CharField(_('Individual Name'), max_length=255, blank=True, null=True, help_text=_('name of the responsible personsurname, given name, title separated by a delimiter'))
organization = models.CharField(_('Organization Name'), max_length=255, blank=True, null=True, help_text=_('name of the responsible organization'))
profile = models.TextField(_('Profile'), null=True, blank=True)
@@ -71,24 +71,13 @@ class Role(models.Model):
def __unicode__(self):
return self.get_value_display()
-
-def create_user_profile(instance, sender, created, **kwargs):
- try:
- profile = Contact.objects.get(user=instance)
- except Contact.DoesNotExist:
- profile = Contact(user=instance)
- profile.name = instance.username
- profile.save()
-
-def relationship_post_save(instance, sender, created, **kwargs):
- if "notification" in settings.INSTALLED_APPS:
- from notification import models as notification
- notification.queue([instance.to_user], "user_follow", {"from_user": instance.from_user})
-
-# Remove the idios create_profile handler, which interferes with ours.
-signals.post_save.disconnect(create_profile, sender=User)
-signals.post_save.connect(create_user_profile, sender=User)
-
-if 'relationships' in settings.INSTALLED_APPS:
- from relationships.models import Relationship
- signals.post_save.connect(relationship_post_save, sender=Relationship)
+@receiver(post_save, sender=User)
+def user_post_save(sender, **kwargs):
+ """
+ Create a Profile instance for all newly created User instances. We only
+ run on user creation to avoid having to check for existence on each call
+ to User.save.
+ """
+ user, created = kwargs["instance"], kwargs["created"]
+ if created:
+ Profile.objects.create(user=user, name=user.username)
@@ -5,7 +5,7 @@
<a id="logo" href="{% url geonode.views.index %}"><img src="{{STATIC_URL}}theme/img/WorldMap-Logo_26px.png" border="0"></a>
<div id="page-breadcrumb"><span>{% trans "Forgot Username" %}</span></div>
{% endblock %}
-{% block main %}
+{% block body %}
<div class="twocol">
<p>{% trans "Enter your email address and click the submit button. Your username will be sent to you." %}</p>
@@ -24,4 +24,4 @@
{% endif %}
</div>
-{% endblock %}
+{% endblock %}
@@ -1,9 +1,9 @@
-{% extends "idios/base.html" %}
+{% extends "people/base.html" %}
{% load i18n %}
{% load bootstrap_tags %}
-{% block main %}
+{% block body %}
<form action="" class="form-horizontal" method="post">
<legend>{% trans "Create Profile" %}</legend>
{% csrf_token %}
@@ -1,8 +1,8 @@
-{% extends "idios/base.html" %}
+{% extends "people/base.html" %}
{% load friendly_loader %}
{% friendly_load i18n avatar_tags relationship_tags %}
-{% block main %}
+{% block body %}
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
@@ -65,7 +65,8 @@ <h3>{{ profile.name }}</h3>
<h3>{% trans "Actions" %}</h3>
<ul class="nav nav-list">
<li><a href="{% url profile_edit user.username %}">{% trans "Edit profile information" %}</a></li>
- <li><a href="{% url auth_password_change %}">{% trans "Change password" %}</a></li>
+ <li><a href="{% url account_settings %}">{% trans "Account Settings" %}</a></li>
+ <li><a href="{% url account_password %}">{% trans "Change password" %}</a></li>
<li><a href="{% url layer_upload %}">{% trans "Upload new layers" %}</a></li>
<li><a href="{% url new_map %}">{% trans "Create a new map" %}</a></li>
</ul>
@@ -92,11 +93,11 @@ <h3>{% trans "Manage Connections" %}</h3>
{% if_has_tag if_relationship %}
<h3>Following</h3>
{% for u in profile.user.relationships.following %}
- <a href="{% url profile_detail u %}">{% avatar u 65 %}</a>
+ <a href="{% url profile_detail u.username %}">{% avatar u 65 %}</a>
{% endfor %}
<h3>Followers</h3>
{% for u in profile.user.relationships.followers %}
- <a href="{% url profile_detail u %}">{% avatar u 65 %}</a>
+ <a href="{% url profile_detail u.username %}">{% avatar u 65 %}</a>
{% endfor %}
{% endif_has_tag %}
{% endblock %}
@@ -1,8 +1,8 @@
-{% extends "idios/base.html" %}
+{% extends "people/base.html" %}
{% load i18n avatar_tags %}
{% load bootstrap_tags %}
-{% block main %}
+{% block body %}
{% avatar user %}
{% if not avatars %}
<p>{% trans "You haven't uploaded an avatar yet. Please upload one now." %}</p>
@@ -1,16 +1,16 @@
-{% extends "idios/base.html" %}
+{% extends "people/base.html" %}
{% load friendly_loader %}
{% friendly_load avatar_tags %}
{% friendly_load relationship_tags %}
{% block body_class %}profiles{% endblock %}
-{% block main %}
+{% block body %}
<ul>
{% for profile in object_list %}
{% if profile.user %}
<li>
- {% avatar profile.user 50 %}<a href="{{ profile.get_absolute_url }}">{{ profile.name }}</a>
+ {% avatar profile.user 50 %}<a href="{% url profile_detail profile.user.username %}">{{ profile.name }}</a>
{% if request.user != profile.user %}
{% if_has_tag if_relationship remove_relationship_url %}
{% if_relationship request.user profile.user "following" %}
View
@@ -19,7 +19,11 @@
from django.conf.urls.defaults import *
+from geonode.people.views import ProfileListView
urlpatterns = patterns('geonode.people.views',
+ url(r'^$', ProfileListView.as_view(), name='profile_browse'),
+ url(r"^edit/(?P<username>[^/]*)$", "profile_edit", name="profile_edit"),
+ url(r"^profile/(?P<username>[^/]*)/$", "profile_detail", name="profile_detail"),
url(r'^forgotname','forgot_username',name='forgot_username'),
)
Oops, something went wrong.

0 comments on commit 95d43b1

Please sign in to comment.