Esempio n. 1
0
    def post(self, request, *args):
        if not request.user.is_authenticated():
            return HttpResponseForbidden()
        data = request.data
        request.user.first_name = data.get('first-name', None)
        request.user.last_name = data.get('last-name', None)
        request.user.email = data.get('email', None)
        request.user.save()

        org_name = data.get('organisation-name', None)
        site_url = data.get('site-url', None)
        if org_name and site_url:
            if site_url:
                site, created = Site.objects.get_or_create(domain=site_url,
                                                           name=site_url)
                organisation, created = Organisation.objects.get_or_create(
                    name=org_name, site=site)
                trusted_user, created = TrustedUser.objects.get_or_create(
                    user=request.user)
                OrganisationSupported.objects.get_or_create(
                    user=trusted_user, organisation=organisation)

        UserApiKey.get_user_api_key(self.request.user, autogenerate=True)

        return HttpResponseRedirect(
            reverse('profile', kwargs={'username': request.user.username}))
Esempio n. 2
0
    def get_context_data(self, *args, **kwargs):
        """
        *debug* toggles GoogleAnalytics support on the main page
        """

        user = get_object_or_404(User, username=kwargs['username'])
        user = get_profile(user)
        context = super(ProfilePage, self).get_context_data(*args, **kwargs)
        context['user'] = user

        context['api_keys'] = None
        if self.request.user == user:
            autogenerate_api_key = False
            if user.is_superuser:
                autogenerate_api_key = True
            context['api_keys'] = UserApiKey.get_user_api_key(
                self.request.user, autogenerate=autogenerate_api_key)
        return context
Esempio n. 3
0
    def get_context_data(self, *args, **kwargs):
        """
        *debug* toggles GoogleAnalytics support on the main page
        """

        user = get_object_or_404(User, username=kwargs['username'])
        user = get_profile(user)
        context = super(ProfilePage, self).get_context_data(*args, **kwargs)
        context['user'] = user

        context['api_keys'] = None
        if self.request.user == user:
            autogenerate_api_key = False
            if user.is_superuser:
                autogenerate_api_key = True
            context['api_keys'] = UserApiKey.get_user_api_key(
                self.request.user, autogenerate=autogenerate_api_key)
        return context
Esempio n. 4
0
    def get_context_data(self, *args, **kwargs):
        """
        *debug* toggles GoogleAnalytics support on the main page
        """

        context = super(ProfilePage, self).get_context_data(*args, **kwargs)
        context['api_keys'] = None
        try:
            user = User.objects.get(username=kwargs['username'])
            user = get_profile(user, self.request)
            osm_user = False

            if self.request.user == user:
                # this is for checking availability old data
                old_data = Locality.objects.filter(
                    changeset__social_user__username=user, migrated=False)

                if old_data:
                    context['old_data_available'] = True

                pathname = \
                    os.path.join(
                        settings.CACHE_DIR, 'data-migration-progress')
                progress_file = \
                    os.path.join(pathname, '{}.txt'.format(user))
                found = os.path.exists(progress_file)

                if found:
                    context['data_migration_in_progress'] = True

                autogenerate_api_key = False
                if user.is_superuser:
                    autogenerate_api_key = True
                context['api_keys'] = UserApiKey.get_user_api_key(
                    self.request.user, autogenerate=autogenerate_api_key)
        except User.DoesNotExist:
            user = {'username': kwargs['username']}
            osm_user = True

        context['user'] = user
        context['osm_user'] = osm_user
        context['osm_API'] = settings.OSM_API_URL
        return context