How to use the geonode.people.models.Profile 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 GeoNode / geonode / geonode / base / populate_test_data.py View on Github external
def dump_models(path=None):
    result = serialize("json", sum([list(x) for x in
                                    [get_user_model().objects.all(),
                                     Profile.objects.all(),
                                     Layer.objects.all(),
                                     Map.objects.all(),
                                     Document.objects.all(),
                                     Tag.objects.all(),
                                     TaggedItem.objects.all(),
                                     ]], []), indent=2, use_natural_keys=True)
    if path is None:
        parent, _ = os.path.split(__file__)
        path = os.path.join(parent, 'fixtures', 'search_testdata.json')
    with open(path, 'w') as f:
        f.write(result)
github GeoNode / geonode / geonode / security / tests.py View on Github external
def test_bobby_cannot_set_all(self):
        """Test that Bobby can set the permissions only only on the ones
        for which he has the right"""

        layer = Layer.objects.all()[0]
        self.client.login(username='admin', password='admin')
        # give bobby the right to change the layer permissions
        assign_perm('change_resourcebase', Profile.objects.get(username='bobby'), layer.get_self_resource())
        self.client.logout()
        self.client.login(username='bobby', password='bob')
        layer2 = Layer.objects.all()[1]
        data = {
            'permissions': json.dumps({"users": {"bobby": ["view_resourcebase"]}, "groups": {}}),
            'resources': [layer.id, layer2.id]
        }
        resp = self.client.post(self.bulk_perms_url, data)
        self.assertTrue(layer2.title in json.loads(resp.content)['not_changed'])
github GeoNode / geonode / geonode / contrib / geosites / tests.py View on Github external
def setUp(self):
        super(SiteTests, self).setUp()
        create_sites()
        create_models(type='layer')

        self.user = 'admin'
        self.passwd = 'admin'
        self.admin = Profile.objects.get(username='admin')
        self.bobby = Profile.objects.get(username='bobby')
        self.master_site = Site.objects.get(name='Master')
        self.slave_site = Site.objects.get(name='Slave')
        self.api_site_url = reverse('api_dispatch_list',
                                    kwargs={
                                        'api_name': 'api',
                                        'resource_name': 'sites'})
        self.api_slave_detail_url = reverse('api_dispatch_detail',
                                            kwargs={
                                                'api_name': 'api',
                                                'resource_name': 'sites',
                                                'pk': self.slave_site.pk})
        self.api_layer_url = reverse('api_dispatch_list',
                                     kwargs={
                                         'api_name': 'api',
                                         'resource_name': 'layers'})
github GeoNode / geonode / geonode / people / forms.py View on Github external
def clean_username(self):
        # Since User.username is unique, this check is redundant,
        # but it sets a nicer error message than the ORM. See #13147.
        username = self.cleaned_data["username"]
        try:
            Profile.objects.get(username=username)
        except Profile.DoesNotExist:
            return username
        raise forms.ValidationError(
            self.error_messages['duplicate_username'],
            code='duplicate_username',
        )
github SP7-Ritmare / starterkit / geosk / mdtools / api.py View on Github external
def _get_or_create_profile(contact):
    _name = contact['name']
    _email = parseaddr(contact['email'])[1] # removing the mailto: prefix
    if _email is None or _email.strip() == '':
        return None
    #guess name
    if _name is None or _name.strip() == '':
        contact['name'] = _guess_name(_email)
    # some cleaning
    fields = Profile._meta.get_all_field_names()
    _defaults= {k:v for k, v in contact.items() if k in fields}
    del(_defaults['email']) #
    # create profile
    profile, is_created = Profile.objects.get_or_create(defaults=_defaults, email=_email)
    return profile
github GeoNode / geonode / scripts / spcgeonode / django / initialize.py View on Github external
# 2. Running the migrations
#########################################################

print("-----------------------------------------------------")
print("2. Running the migrations")
call_command('migrate', '--noinput')


#########################################################
# 3. Creating superuser if it doesn't exist
#########################################################

print("-----------------------------------------------------")
print("3. Creating/updating superuser")
try:
    superuser = Profile.objects.get(username=admin_username)
    superuser.set_password(admin_password)
    superuser.is_active = True
    superuser.email = admin_email
    superuser.save()
    print('superuser successfully updated')
except Profile.DoesNotExist:
    superuser = Profile.objects.create_superuser(
        admin_username,
        admin_email,
        admin_password
    )
    print('superuser successfully created')


#########################################################
# 4. Create an OAuth2 provider to use authorisations keys
github cartologic / cartoview / cartoview / app_manager / context_processors.py View on Github external
def cartoview_processor(request):
    permitted = get_objects_for_user(request.user,
                                     'base.view_resourcebase')
    cartoview_counters = {
        "apps": App.objects.count(),
        "app_instances": AppInstance.objects.filter(id__in=permitted).count(),
        "maps": Map.objects.filter(id__in=permitted).count(),
        "layers": Layer.objects.filter(id__in=permitted).count(),
        "users": Profile.objects.exclude(username="AnonymousUser").count(),
        "groups": Group.objects.exclude(name="anonymous").count()
    }

    defaults = {
        'apps': App.objects.all().order_by('order'),
        'CARTOVIEW_VERSION': get_version(__version__),
        'APPS_MENU': settings.APPS_MENU,
        'apps_instance_count': AppInstance.objects.all().count(),
        "cartoview_counters": cartoview_counters,
        'instances': AppInstance.objects.all().order_by('app__order')[:5]
    }
    return defaults
github cga-harvard / worldmap / certification / views.py View on Github external
def certified_by_user(request, username):
    ''' Get certified objects per user '''
    profile = Profile.objects.get(username=username)
    cert_objects = Certification.objects.certifications_user(profile)

    return render(request, 'certification/certified_by_user.html',
        {
          'cert_objects': cert_objects,
          'profile': profile,
        }
github GeoNode / geonode / geonode / people / autocomplete_light_registry.py View on Github external
from django.db.models import Q
from autocomplete_light.registry import register
from autocomplete_light.autocomplete.shortcuts import AutocompleteModelTemplate
from .models import Profile


class ProfileAutocomplete(AutocompleteModelTemplate):
    choice_template = 'autocomplete_response_people.html'

    def choices_for_request(self):
        self.choices = self.choices.exclude(Q(username='AnonymousUser') | Q(is_active=False))
        return super(ProfileAutocomplete, self).choices_for_request()


register(
    Profile,
    ProfileAutocomplete,
    search_fields=['first_name', 'last_name', 'email', 'username'],
)
github GeoNode / geonode / geonode / base / management / commands / fixgeofencerules.py View on Github external
def handle(self, *args, **options):
        use_geofence = settings.OGC_SERVER['default'].get(
            "GEOFENCE_SECURITY_ENABLED", False)
        if use_geofence:
            profiles = Profile.objects.filter(is_superuser=False)
            authorized = list(get_objects_for_user(profiles[0], 'base.view_resourcebase').values('id'))
            layers = Layer.objects.filter(id__in=[d['id'] for d in authorized])

            for index, layer in enumerate(layers):
                print "[%s / %s] Setting default permissions to Layer [%s] ..." % ((index + 1), len(layers), layer.name)
                try:
                    utils.set_geofence_all(layer)
                except:
                    print "[ERROR] Layer [%s] couldn't be updated" % (layer.name)

            protected_layers = Layer.objects.all().exclude(id__in=[d['id'] for d in authorized])

            for index, layer in enumerate(protected_layers):
                print "[%s / %s] Setting owner permissions to Layer [%s] ..." \
                      % ((index + 1), len(protected_layers), layer.name)
                try: