Skip to content

Commit

Permalink
group categories GeoNode#3067 GeoNode#3083
Browse files Browse the repository at this point in the history
  model, api views, regular views
  translate strings update
  tests for group categories
  • Loading branch information
cezio committed May 25, 2017
1 parent 6a592a7 commit 4b2c76a
Show file tree
Hide file tree
Showing 64 changed files with 43,168 additions and 35,541 deletions.
27 changes: 24 additions & 3 deletions geonode/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
from geonode.layers.models import Layer
from geonode.maps.models import Map
from geonode.documents.models import Document
from geonode.groups.models import GroupProfile
from geonode.groups.models import GroupProfile, GroupCategory

from django.core.serializers.json import DjangoJSONEncoder
from tastypie.serializers import Serializer
from tastypie import fields
from tastypie.resources import ModelResource
from tastypie.constants import ALL
from tastypie.constants import ALL, ALL_WITH_RELATIONS
from tastypie.utils import trailing_slash


Expand Down Expand Up @@ -246,12 +246,32 @@ class Meta:
serializer = CountJSONSerializer()


class GroupCategoryResource(TypeFilteredResource):
detail_url = fields.CharField()
member_count = fields.IntegerField()

class Meta:
queryset = GroupCategory.objects.all()
allowed_methods = ['get']
include_resource_uri = False
fields = ['name', 'slug']
filtering = {'slug': ALL,
'name': ALL}

def dehydrate_detail_url(self, bundle):
return bundle.obj.get_absolute_url()

def dehydrate_member_count(self, bundle):
return bundle.obj.groups.all().count()


class GroupResource(ModelResource):
"""Groups api"""

detail_url = fields.CharField()
member_count = fields.IntegerField()
manager_count = fields.IntegerField()
categories = fields.ToManyField(GroupCategoryResource, 'categories', full=True)

def dehydrate_member_count(self, bundle):
return bundle.obj.member_queryset().count()
Expand All @@ -267,7 +287,8 @@ class Meta:
resource_name = 'groups'
allowed_methods = ['get']
filtering = {
'title': ALL
'title': ALL,
'categories': ALL_WITH_RELATIONS,
}
ordering = ['title', 'last_modified']

Expand Down
4 changes: 3 additions & 1 deletion geonode/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from tastypie.api import Api

from .api import TagResource, TopicCategoryResource, ProfileResource, \
GroupResource, RegionResource, OwnersResource, ThesaurusKeywordResource
GroupResource, RegionResource, OwnersResource, ThesaurusKeywordResource, \
GroupCategoryResource
from .resourcebase_api import LayerResource, MapResource, DocumentResource, \
ResourceBaseResource, FeaturedResourceBaseResource

Expand All @@ -39,3 +40,4 @@
api.register(FeaturedResourceBaseResource())
api.register(OwnersResource())
api.register(ThesaurusKeywordResource())
api.register(GroupCategoryResource())
11 changes: 10 additions & 1 deletion geonode/groups/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@

from django.contrib import admin

from geonode.groups.models import GroupMember, GroupProfile, GroupInvitation
from modeltranslation.admin import TranslationAdmin

from geonode.groups.models import (GroupMember, GroupProfile,
GroupInvitation, GroupCategory)


@admin.register(GroupCategory)
class GroupCategoryAdmin(TranslationAdmin):
list_display = ('name', 'slug',)
readonly_fields = ('slug',)


class GroupMemberInline(admin.TabularInline):
Expand Down
5 changes: 3 additions & 2 deletions geonode/groups/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
from django.core.validators import validate_email, ValidationError
from slugify import slugify
from django.utils.translation import ugettext_lazy as _
from modeltranslation.forms import TranslationModelForm

from django.contrib.auth import get_user_model

from geonode.groups.models import GroupProfile


class GroupForm(forms.ModelForm):
class GroupForm(TranslationModelForm):

slug = forms.SlugField(
max_length=20,
Expand Down Expand Up @@ -62,7 +63,7 @@ def clean(self):

class Meta:
model = GroupProfile
exclude = ['group']
exclude = ['group',]


class GroupUpdateForm(forms.ModelForm):
Expand Down
41 changes: 41 additions & 0 deletions geonode/groups/migrations/0025_group_categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('groups', '24_initial'),
]

operations = [
migrations.CreateModel(
name='GroupCategory',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('slug', models.SlugField(unique=True, max_length=255)),
('name', models.CharField(unique=True, max_length=255)),
('name_en', models.CharField(max_length=255, unique=True, null=True)),
],
options={
'verbose_name_plural': 'Group Categories',
},
),
migrations.AddField(
model_name='groupprofile',
name='description_en',
field=models.TextField(null=True, verbose_name='Description'),
),
migrations.AddField(
model_name='groupprofile',
name='title_en',
field=models.CharField(max_length=50, null=True, verbose_name='Title'),
),
migrations.AddField(
model_name='groupprofile',
name='categories',
field=models.ManyToManyField(related_name='groups', to='groups.GroupCategory', blank=True),
),
]
19 changes: 19 additions & 0 deletions geonode/groups/migrations/0026_group_category_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('groups', '0025_group_categories'),
]

operations = [
migrations.AddField(
model_name='groupcategory',
name='description',
field=models.TextField(default=None, null=True, blank=True),
),
]
25 changes: 25 additions & 0 deletions geonode/groups/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import hashlib

from django.conf import settings
from django.core.urlresolvers import reverse
from django.contrib.auth.models import Group
from django.contrib.auth import get_user_model
from django.db import models, IntegrityError
from django.utils.translation import ugettext_lazy as _
from django.utils.text import slugify
from django.db.models import signals
from django.contrib.sites.models import Site
from django.template.loader import render_to_string
Expand All @@ -35,6 +37,28 @@
from guardian.shortcuts import get_objects_for_group


class GroupCategory(models.Model):
slug = models.SlugField(max_length=255, unique=True, null=False, blank=False)
name = models.CharField(max_length=255, unique=True, null=False, blank=False)
description = models.TextField(null=True, default=None, blank=True)

class Meta:
verbose_name_plural = _('Group Categories')

def __str__(self):
return 'Category: {}'.format(self.name)

def get_absolute_url(self):
return reverse('group_category_detail', args=(self.slug,))


def group_category_pre_save(sender, instance, *args, **kwargs):
instance.slug = slugify(instance.name)


signals.pre_save.connect(group_category_pre_save, sender=GroupCategory)


class GroupProfile(models.Model):
GROUP_CHOICES = [
("public", _("Public")),
Expand Down Expand Up @@ -71,6 +95,7 @@ class GroupProfile(models.Model):
choices=GROUP_CHOICES,
help_text=access_help_text)
last_modified = models.DateTimeField(auto_now=True)
categories = models.ManyToManyField(GroupCategory, blank=True, related_name='groups')

def save(self, *args, **kwargs):
group, created = Group.objects.get_or_create(name=self.slug)
Expand Down
33 changes: 33 additions & 0 deletions geonode/groups/templates/groups/category_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% extends "groups/group_base.html" %}
{% load i18n %}
{% load staticfiles %}

{% block title %} {% trans "Explore Group Categories" %} - {{ block.super }} {% endblock %}

{% block body_class %}groups explore{% endblock %}

{% block body %}
<div class="page-header">
{% if user.is_authenticated %}
<a href="{% url "group_category_create" %}" class="btn btn-primary pull-right">{% trans "Create a New Group Category" %}</a>
{% endif %}
<h2>{% trans "Explore Group Categories" %}</h2>
</div>

{% with include_type_filter='true' %}
{% with facet_type='groupcategories' %}
{% include "search/_search_user_content.html" %}
{% endwith %}
{% endwith %}
{% include "_bulk_permissions_form.html" %}
{% endblock %}

{% block extra_script %}
{{ block.super }}
<script type="text/javascript">
SEARCH_URL = '{% url 'api_dispatch_list' api_name='api' resource_name='groupcategory' %}'
</script>
{% with include_spatial='false' %}
{% include 'search/search_scripts.html' %}
{% endwith %}
{% endblock extra_script %}
4 changes: 2 additions & 2 deletions geonode/groups/templates/groups/group_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% block body %}
<div class="block">
<div class="col-md-10">
<h2 class="page-title">{% trans "Create a Group" %}</h2>
<h2 class="page-title">{% block body_page_title %}{% trans "Create a Group" %}{% endblock %}</h2>
{% if errors %}
<div id="errors">
{% for error in errors %}
Expand All @@ -23,7 +23,7 @@ <h2 class="page-title">{% trans "Create a Group" %}</h2>
{{ form|as_bootstrap }}
<div class="form_block">
<input type="hidden" name="action" value="create" />
<input type="submit" class="btn btn-primary" value="{% trans 'Create' %}"/>
<input type="submit" class="btn btn-primary" value="{% block form_button %}{% trans 'Create' %}{% endblock %}"/>
</div>
</fieldset>
</form>
Expand Down
9 changes: 9 additions & 0 deletions geonode/groups/templates/groups/group_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ <h2 class="page-title">{{ object.title|default:object.slug }}</h2>
<a href="mailto:{{ object.email }}">{{ object.email }}</a>
</p>
{% endif %}

{% if object.categories.exists %}
<p>
{% for category in object.categories.all %}
<a href="{{ category.get_absolute_url }}"><span class="label label-info">{{ category.name }}</span></a>
{% endfor %}
</p>
{% endif %}

</div>
</div>
</div>
Expand Down
51 changes: 51 additions & 0 deletions geonode/groups/templates/groups/groupcategory_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% extends "groups/group_detail.html" %}
{% load i18n %}


{% block title %}{{ object.name|default:object.slug }} — {{ block.super.super }}{% endblock %}

{% block body_outer %}
<div class="page-header">
<h2 class="page-title">{{ object.name|default:object.slug }}</h2>
</div>
<div class="row">
<div class="col-md-8 group-details">
<div class="row">
<div class="col-xs-12 col-md-12 group-details">
<p class="group-desc">{{ object.description|default_if_none:'' }}</p>

</div>
</div>
</div>

<div class="col-md-4">
<ul class="list-group">
{% if request.user.is_staff %}
<li class="list-group-item"><a href="{% url "group_category_update" object.slug %}">{% trans "Edit Group Category Details" %}</a></li>
{% endif %}
</ul>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h4>{% trans "Groups" %}</h4>
<div class="tab-content paginate paginate-auto" id="search-content">
{% include 'groups/_group_list_item.html' %}
</div>
</div>
{% include 'search/_pagination.html' %}
</div>
{% endblock %}


{% block extra_script %}
{{ block.super.super }}
<script type="text/javascript">
SEARCH_URL = '{% url 'api_dispatch_list' api_name='api' resource_name='groups' %}'+ '?categories__slug='+ '{{ object.slug }}';
</script>
{% with include_spatial='false' %}
{% include 'search/search_scripts.html' %}
{% endwith %}
{% endblock extra_script %}


6 changes: 6 additions & 0 deletions geonode/groups/templates/groups/groupcategory_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends "groups/group_create.html" %}
{% load i18n %}

{% block head_title %}{% trans "Create Group Category" %}{% endblock %}

{% block body_page_title %}{% trans "Create a Group Category" %}{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "groups/group_create.html" %}
{% load i18n %}

{% block head_title %}{% trans "Edit Group Category" %} {{ object.name }}{% endblock %}

{% block body_page_title %}{% trans "Edit Group Category" %} {{ object.name }}{% endblock %}

{% block form_button %}{% trans "Save" %}{% endblock %}
Loading

0 comments on commit 4b2c76a

Please sign in to comment.