How to use the geonode.groups.models.GroupProfile function in GeoNode

To help you get started, we’ve selected a few GeoNode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MapStory / mapstory / mapstory / storylayers / views.py View on Github external
for atype in e.findall(
                        "./[Name='%s']/Extent[@name='time']" % (layername)):
                    dim_name = atype.get('name')
                    if dim_name:
                        dim_name = str(dim_name).lower()
                        if dim_name == 'time':
                            dim_values = atype.text
                            if dim_values:
                                all_times = dim_values.split(",")
                                break

    group = None
    if layer.group:
        try:
            group = GroupProfile.objects.get(slug=layer.group.name)
        except GroupProfile.DoesNotExist:
            group = None
    # a flag to be used for qgis server
    show_popup = False
    if 'show_popup' in request.GET and request.GET["show_popup"]:
        show_popup = True

    ###
    # MapStory Specific Changes
    ###
    keywords = json.dumps([tag.name for tag in layer.keywords.all()])

    if request.method == "POST":
        keywords_form = KeywordsForm(request.POST, instance=layer)
        metadata_form = MetadataForm(instance=layer)
        distributionurl_form = DistributionUrlForm(
            request.POST, instance=layer)
github GeoNode / geonode / geonode / api / resourcebase_api.py View on Github external
# includes other values
            values = self.VALUES + [
                'alternate',
                'name'
            ]
            formatted_obj = model_to_dict(obj, fields=values)
            username = obj.owner.get_username()
            full_name = (obj.owner.get_full_name() or username)
            formatted_obj['owner__username'] = username
            formatted_obj['owner_name'] = full_name
            if obj.category:
                formatted_obj['category__gn_description'] = obj.category.gn_description
            if obj.group:
                formatted_obj['group'] = obj.group
                try:
                    formatted_obj['group_name'] = GroupProfile.objects.get(slug=obj.group.name)
                except GroupProfile.DoesNotExist:
                    formatted_obj['group_name'] = obj.group

            formatted_obj['keywords'] = [k.name for k in obj.keywords.all()] if obj.keywords else []
            formatted_obj['regions'] = [r.name for r in obj.regions.all()] if obj.regions else []

            # provide style information
            bundle = self.build_bundle(obj=obj)
            formatted_obj['default_style'] = self.default_style.dehydrate(
                bundle, for_list=True)

            # Add resource uri
            formatted_obj['resource_uri'] = self.get_resource_uri(bundle)

            formatted_obj['links'] = self.dehydrate_ogc_links(bundle)
github GeoNode / geonode / geonode / groups / forms.py View on Github external
def clean_title(self):
        if GroupProfile.objects.filter(
                title__iexact=self.cleaned_data["title"]).count() > 0:
            raise forms.ValidationError(
                _("A group already exists with that name."))
        return self.cleaned_data["title"]
github GeoNode / geonode / geonode / security / utils.py View on Github external
user,
                          admin_approval_required=False,
                          unpublished_not_visible=False,
                          private_groups_not_visibile=False):
    is_admin = False
    is_manager = False
    if user:
        is_admin = user.is_superuser if user else False
        try:
            is_manager = user.groupmember_set.all().filter(role='manager').exists()
        except BaseException:
            is_manager = False

    # Get the list of objects the user has access to
    anonymous_group = None
    public_groups = GroupProfile.objects.exclude(access="private").values('group')
    groups = []
    group_list_all = []
    manager_groups = []
    try:
        group_list_all = user.group_list_all().values('group')
    except BaseException:
        pass
    try:
        manager_groups = Group.objects.filter(
            name__in=user.groupmember_set.filter(role="manager").values_list("group__slug", flat=True))
    except BaseException:
        pass
    try:
        anonymous_group = Group.objects.get(name='anonymous')
        if anonymous_group and anonymous_group not in groups:
            groups.append(anonymous_group)
github GeoNode / geonode / geonode / contrib / geosites / models.py View on Github external
# Django doesn't propagate the signals to the parents so we need to add the listeners on the children
if 'geonode.contrib.geosites' in settings.INSTALLED_APPS:
    signals.post_save.connect(post_save_resource, sender=Layer)
    signals.post_save.connect(post_save_resource, sender=Map)
    signals.post_save.connect(post_save_resource, sender=Document)
    signals.post_save.connect(post_save_site, sender=Site)
    signals.post_delete.connect(post_delete_resource, sender=Layer)
    signals.post_delete.connect(post_delete_resource, sender=Map)
    signals.post_delete.connect(post_delete_resource, sender=Document)
    signals.post_delete.connect(post_delete_site, sender=Site)
    signals.post_save.connect(post_save_profile, sender=Profile)
    signals.post_delete.connect(post_delete_profile, sender=Profile)
    signals.post_save.connect(post_save_group, sender=GroupProfile)
    signals.post_delete.connect(post_delete_group, sender=GroupProfile)
github GeoNode / geonode / geonode / groups / __init__.py View on Github external
def init_registered_members_groupprofile():
    from .conf import settings
    from .models import GroupProfile
    from django.contrib.auth import get_user_model

    group_name = settings.REGISTERED_MEMBERS_GROUP_NAME
    logger.debug("Creating %s default Group Profile" % group_name)
    groupprofile, created = GroupProfile.objects.get_or_create(
        slug=group_name)
    if created:
        groupprofile.slug = group_name
        groupprofile.title = "Registered Members"
        groupprofile.access = "private"
        groupprofile.save()

    User = get_user_model()
    for _u in User.objects.filter(is_active=True):
        if not _u.is_anonymous and _u != User.get_anonymous() and \
        not groupprofile.user_is_member(_u):
            groupprofile.join(_u)
github GeoNode / geonode / geonode / layers / views.py View on Github external
def layer_metadata_detail(
        request,
        layername,
        template='layers/layer_metadata_detail.html'):
    layer = _resolve_layer(
        request,
        layername,
        'view_resourcebase',
        _PERMISSION_MSG_METADATA)
    group = None
    if layer.group:
        try:
            group = GroupProfile.objects.get(slug=layer.group.name)
        except GroupProfile.DoesNotExist:
            group = None
    site_url = settings.SITEURL.rstrip('/') if settings.SITEURL.startswith('http') else settings.SITEURL

    register_event(request, 'view_metadata', layer)

    return render(request, template, context={
        "resource": layer,
        "perms_list": get_perms(
            request.user,
            layer.get_self_resource()) + get_perms(request.user, layer),
        "group": group,
        'SITEURL': site_url
    })
github MapStory / mapstory / mapstory / orgs / models.py View on Github external
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.db.models import signals
from geonode.base.enumerations import COUNTRIES
from geonode.groups.models import GroupProfile as Geonode_Group


class Org(models.Model):
    group = models.OneToOneField(Geonode_Group, on_delete=models.CASCADE)

    social_twitter = models.CharField(
        _('Twitter Handle'),
        help_text=_('Provide your Twitter handle or URL'),
        max_length=255,
        null=True,
        blank=True)

    social_facebook = models.CharField(
        _('Facebook Profile'),
        help_text=_('Provide your Facebook handle or URL'),
        max_length=255,
        null=True,
        blank=True)

    date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
github GeoNode / geonode / geonode / people / signals.py View on Github external
def _remove_user_from_registered_members(user):
    if groups_settings.AUTO_ASSIGN_REGISTERED_MEMBERS_TO_REGISTERED_MEMBERS_GROUP_NAME:
        group_name = groups_settings.REGISTERED_MEMBERS_GROUP_NAME
        groupprofile = GroupProfile.objects.filter(slug=group_name).first()
        if groupprofile:
            groupprofile.leave(user)
github GeoNode / geonode / geonode / catalogue / views.py View on Github external
if request.user and request.user.is_authenticated():
                for group in request.user.groups.all():
                    groups_ids.append(group.id)
                group_list_all = []
                try:
                    group_list_all = request.user.group_list_all().values('group')
                except BaseException:
                    pass
                for group in group_list_all:
                    if isinstance(group, dict):
                        if 'group' in group:
                            groups_ids.append(group['group'])
                    else:
                        groups_ids.append(group.id)

            public_groups = GroupProfile.objects.exclude(
                access="private").values('group')
            for group in public_groups:
                if isinstance(group, dict):
                    if 'group' in group:
                        groups_ids.append(group['group'])
                else:
                    groups_ids.append(group.id)

            if len(groups_ids) > 0:
                groups = "(" + (", ".join(str(e) for e in groups_ids)) + ")"
                groups_filter = "(group_id IS NULL OR group_id IN " + groups + ")"
                mdict['repository']['filter'] += " AND " + groups_filter
            else:
                groups_filter = "group_id IS NULL"
                mdict['repository']['filter'] += " AND " + groups_filter