Exemplo n.º 1
0
    def create_user(self):

        if not self.user:

            __username = slugify(self.name)
            original_username = slugify(self.name)
            _exists = username_is_available(original_username)

            if not _exists:

                inc = 1
                while (_exists == False):
                    __username = '******'.format(original_username, inc)
                    _exists = username_is_available(__username)
                    inc = inc + 1

            company_user = User.objects.create_user(username=__username,
                                                    first_name=self.name,
                                                    last_name='',
                                                    is_active=True,
                                                    usertype=User.ORGANIZATION)

            company_user.save()

            self.user = company_user

            user_profile = self.user.user_profile
            user_profile.profile_picture = self.logo
            user_profile.description = self.description
            user_profile.save()

        return self.user
Exemplo n.º 2
0
def loginSocial(request):
    user = request.user
    try:
        facebook_login = user.social_auth.get(provider='facebook')
    except UserSocialAuth.DoesNotExist:
        facebook_login = None

    try:
        google_login = user.social_auth.get(provider='google-oauth2')
    except UserSocialAuth.DoesNotExist:
        google_login = None

    if facebook_login != None:
        url = 'http://graph.facebook.com/' + facebook_login.extra_data[
            'id'] + '/picture?type=large'
        profile = facebook_login.user.profile
        # save image avatar for user
        avatar = urlopen(url)
        profile.image.save(
            slugify(profile.user.username + " social") + '.jpg',
            ContentFile(avatar.read()))
        profile.birthdate = datetime.strptime(
            facebook_login.extra_data['birthday'], '%m/%d/%Y')
        profile.save()

        # update email
        facebook_login.user.email = facebook_login.extra_data['email']
        facebook_login.user.save()
        return redirect('giasu:profile', user_id=facebook_login.user.id)
    elif google_login != None:
        return redirect('giasu:profile', user_id=google_login.user.id)
Exemplo n.º 3
0
def upload_temp_image(image: bytes, extension: str) -> Optional[str]:
    key = slugify(f"{uuid.uuid4()}") + extension
    success = upload_to_s3(image, key, S3Folders.TEMP)

    if not success:
        LOGGER.error(f"Error uploading the image to S3 with key: {key}")
        return None
    return key
Exemplo n.º 4
0
def save_review_park_kilimanjaro(request, pk):
    if request.method == 'POST':
        data = json.loads(request.body)
        data['slug'] = slugify(data['title'])
        data['date_created'] = datetime.now()
        data['date_modified'] = datetime.now()
        data['email_sent'] = False
        data['visit_date'] = datetime(data['visit_date_year'],
                                      data['visit_date_month'], 1)

        form = ParkKilimanjaroReviewForm(data)
        form.instance.user = request.user
        park = Park.objects.get(pk=pk)
        form.instance.park = park
        ip = get_visitor_data(request)['ip_address']
        form.instance.ip_address = ip
        try:
            iso = get_country_by_ip(ip)
            country = Country.objects.get(iso=iso)
            if country:
                form.instance.country_written = country
        except places.models.Country.DoesNotExist:
            pass

        if form.is_valid():

            form = form.save()
            form.slug = slugify(data['title'])
            obj = json.loads(request.body)

            for key in obj.get('selected_activities'):
                form.activities.add(Activity.objects.get(pk=key))

            for key in obj.get('selected_animals'):
                form.animals.add(Animal.objects.get(pk=key))

            form.save()
            send_review_thank_you_email(request, park.name)
            data = {'status': 'success', 'review_park': form.id}
            return JsonResponse(data)
        else:
            return JsonResponse({'status': 'error', 'errors': form.errors})
Exemplo n.º 5
0
    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):

        if not self.slug:
            self.slug = slugify(self.title)

        super(JobVacancy, self).save(force_insert, force_update, using,
                                     update_fields)
Exemplo n.º 6
0
def save_review_tour_operator(request, pk):
    if request.method == 'POST':
        data = json.loads(request.body)
        data['title'] = data['review_title']
        data['content'] = data['review_copy']
        data['pearls_of_wisdom'] = data['pearls_of_wisdom']
        data['friend_recommend'] = data['friend_recommend']
        data['reached_summit'] = data['reached_summit']
        data['take_medications'] = data['take_medications']
        data['route_to_climb'] = data['route_to_climb']
        if data['route_to_climb'] == "unselected" or data[
                'route_to_climb'] == None:
            data['route_to_climb'] = None
        data['other_route_to_climb'] = data['other_route_to_climb']
        data['date_created'] = datetime.now()
        data['date_modified'] = datetime.now()
        if data['start_date_year'] > 0:
            data['start_date'] = datetime(data['start_date_year'],
                                          data['start_date_month'], 1)

        if data['is_kilimanjaro'] == True:
            data_kilimanjaro = data
            data_kilimanjaro['crowdedness_rating'] = data_kilimanjaro[
                'crowdedness_rating_kilimanjaro']
            data_kilimanjaro['quality_wildlife_rating'] = 0
            data_kilimanjaro['quality_lodging_rating'] = 0
            data_kilimanjaro['content'] = data_kilimanjaro[
                'content_kilimanjaro']
            data_kilimanjaro['visit_date'] = data['start_date']
            data_kilimanjaro['pearls_of_wisdom'] = data[
                'pearls_of_wisdom_kilimanjaro']

        data['vehicle_rating'] = data['vehicle_rating']
        data['meet_and_greet_rating'] = data['meet_and_greet_rating']
        data['responsiveness_rating'] = data['responsiveness_rating']
        data['safari_quality_rating'] = data['safari_quality_rating']
        data['itinerary_quality_rating'] = data['itinerary_quality_rating']
        data['overall_rating'] = data['overall_rating']
        data['days_booked'] = data['days_booked'] or 0
        data['did_not_go'] = data['did_not_go']
        data['find_out'] = data['find_out']
        data['find_out_website'] = data['find_out_website']

        data['email_sent'] = False
        if data['is_kilimanjaro'] == True:
            data_kilimanjaro['email_sent'] = False

            form_kilimanjaro = ParkKilimanjaroReviewForm(data_kilimanjaro)
            form_kilimanjaro.instance.user = request.user

            form_kilimanjaro.instance.park = Park.objects.get(
                slug='kilimanjaro')
            ip = get_visitor_data(request)['ip_address']
            form_kilimanjaro.instance.ip_address = ip
            try:
                iso = get_country_by_ip(ip)
                country = Country.objects.get(iso=iso)
                if country:
                    form_kilimanjaro.instance.country_written = country
            except places.models.Country.DoesNotExist:
                pass

            if form_kilimanjaro.is_valid():
                form_kilimanjaro = form_kilimanjaro.save()
                form_kilimanjaro.slug = slugify(data['title'])
                obj = json.loads(request.body)

                for key in obj.get('selected_activities'):
                    form_kilimanjaro.activities.add(
                        Activity.objects.get(pk=key))

                for key in obj.get('selected_animals'):
                    form_kilimanjaro.animals.add(Animal.objects.get(pk=key))

                form_kilimanjaro.save()
                data_kilimanjaro = {
                    'status': 'success',
                    'review_park': form_kilimanjaro.id
                }
                # return JsonResponse(data_kilimanjaro)
            else:
                return JsonResponse({
                    'status': 'error',
                    'errors': form_kilimanjaro.errors
                })

        form = TourOperatorReviewForm(data)
        form.instance.user = request.user
        tour_operator = TourOperator.objects.get(pk=pk)
        form.instance.tour_operator = tour_operator
        form.instance.tour_operator.last_review_date = datetime.now()
        form.instance.tour_operator.save()
        if data['safari_type_id'] != "" and data['safari_type_id'] != None:
            form.instance.safari_type = SafariType.objects.get(
                id=data['safari_type_id'])

        ip = get_visitor_data(request)['ip_address']
        form.instance.ip_address = ip
        try:
            iso = get_country_by_ip(ip)
            country = Country.objects.get(iso=iso)
            if country:
                form.instance.country_written = country
        except places.models.Country.DoesNotExist:
            pass

        if form.is_valid():
            review = form.save()
            review.slug = slugify(data['review_title'])

            obj = json.loads(request.body)
            for key in obj.get('selected_activities'):
                review.activities.add(Activity.objects.get(pk=key))

            for key in obj.get('selected_animals'):
                review.animals.add(Animal.objects.get(pk=key))

            for key in obj.get('selected_countries'):
                review.country_indexes.add(CountryIndex.objects.get(pk=key))

            for key in obj.get('selected_parks'):
                review.parks.add(Park.objects.get(pk=key))

            review.save()
            send_review_thank_you_email(request, tour_operator.name)
            data = {'status': 'success', 'review_tour_operator': review.id}
            return JsonResponse(data)
        else:
            return JsonResponse({'status': 'error', 'errors': form.errors})
Exemplo n.º 7
0
 def save(self, *args, **kwargs):
     if not self.slug:
         self.slug = slugify(self.user)
     super(Profile, self).save(*args, **kwargs)