Example #1
0
def AddFounderfromForm(request):

    file_path = user_images_file_path
    if request.method == 'POST':
        form = AddUserForm(request.POST, request.FILES)

        if form.is_valid():
            add_another_founder = form.cleaned_data['add_another_founder']
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            email = form.cleaned_data['email']
            startup = form.cleaned_data['startup']
            linkedin_url = form.cleaned_data['linkedin_url']
            facebook_url = form.cleaned_data['facebook_url']
            twitter_handle = form.cleaned_data['twitter_handle']
            about = form.cleaned_data['about']

            if request.FILES['image']:
                image = request.FILES['image']
                file_name = str(image)
                image_file = open(os.path.join(file_path, file_name), 'wb')
                image_file.write(image.read())
                image_file.close()
                image_path = boto_helper.upload_image(file_path, str(image))
                image_s3 = "https://" + CDN_DOMAIN + "/" + file_name
            else:
                image_s3 = ''

            startup = startUp.objects.get(name_of_startup=startup)

            created_user = MyUser.objects.create(username=email,
                                                 email=email,
                                                 first_name=first_name,
                                                 last_name=last_name,
                                                 facebook_url=facebook_url,
                                                 linkedin_url=linkedin_url,
                                                 twitter_handle=twitter_handle,
                                                 image=image_s3,
                                                 startup=startup,
                                                 about=about)

            created_user.save()

            if add_another_founder:
                return redirect('/user/addfounder')
            else:
                return redirect('/approvalrequest/')

        else:
            return render(request, 'users/addfounders.html', {
                'form': form,
                'errors': form.errors
            })
    else:
        form = AddUserForm()
        return render(request, 'users/addfounders.html', {'form': form})
Example #2
0
def AddStartupfromForm(request):

    if request.method == 'POST':

        file_path = startup_images_file_path

        form = AddStartupForm(request.POST, request.FILES)
        if form.is_valid():
            name_of_startup = form.cleaned_data['name_of_startup']
            linkedin_url = form.cleaned_data['linkedin_url']
            facebook_url = form.cleaned_data['facebook_url']
            twitter_handle = form.cleaned_data['twitter_handle']
            inc_year = form.cleaned_data['inc_year']
            type_of_trade = form.cleaned_data['type_of_trade']
            description = form.cleaned_data['description']
            team_size = form.cleaned_data['team_size']
            location = form.cleaned_data['location']
            company_tagline = form.cleaned_data['company_tagline']


            # reading startup_logo and uploading to s3 and saving the url to database
            if request.FILES['startup_logo']:
                startup_logo = request.FILES['startup_logo']
                startup_logo_file_name = 'startup' + ('-').join(str(datetime.now()).split(' ')) + ('-').join(str(startup_logo).split(' '))
                startup_logo_file = open(os.path.join(file_path, startup_logo_file_name), 'wb')
                startup_logo_file.write(startup_logo.read())
                startup_logo_file.close()
                startup_logo_path = boto_helper.upload_image(file_path, startup_logo_file_name)
                startup_logo_s3 = "https://" + CDN_DOMAIN + "/" + startup_logo_file_name

            chat_username = ('').join(name_of_startup.split(' '))
            chat_password = get_random_string(length=8)
            startup = startUp.objects.create(name_of_startup=name_of_startup, linkedin_url=linkedin_url,
                                             facebook_url=facebook_url, twitter_handle=twitter_handle,
                                             inc_year=inc_year, description=description, team_size=team_size,
                                             location=location, company_tagline=company_tagline,
                                             startup_logo=startup_logo_s3, chat_user=chat_username,
                                             chat_password=chat_password)
            startup.save()

            return redirect('/user/addfounder')
        else:
            return render(request, 'startups/addstartup.html', {'form': form, 'errors': form.errors})


    else:
        form = AddStartupForm()
        return render(request, 'startups/addstartup.html', {'form': form})
Example #3
0
    def post(self, request):

        file_path = startup_images_file_path

        try:
            user = request.user
            s_id = request.data['id']
            Startup = startUp.objects.get(id=s_id)

            if user in Startup.cofounders.all():

                # if request.data['company_tagline']:
                #     a = request.data['company_tagline'].split(' ')[0:5]
                #     company_tagline = ' '.join(a)
                #     request.data['company_tagline'] = company_tagline

                if request.FILES.get('startup_logo'):
                    try:
                        startup_logo = request.FILES.get('startup_logo')
                        file_name = 'sl_' + str(startup_logo)
                        image_file = open(os.path.join(file_path, file_name), 'wb')
                        image_file.write(startup_logo.read())
                        image_file.close()
                        startup_logo_path = boto_helper.upload_image(file_path, file_name)
                        startup_logo_s3 = "https://" + CDN_DOMAIN + "/" + file_name
                        request.data['startup_logo'] = startup_logo_s3
                        Startup.startup_logo = startup_logo_s3
                        Startup.save()

                    except Exception as e:
                        err = repr(e)

                        return Response({
                            "success": False,
                            "error": err,
                            "status": status.HTTP_500_INTERNAL_SERVER_ERROR,
                        }, status.HTTP_500_INTERNAL_SERVER_ERROR)

                startup_edited = StartupEditSerializer(Startup, data=request.data)
                if startup_edited.is_valid():
                    startup_edited.save()
                    startup_edited = StartupEditedSerializer(Startup)

                    return Response({
                        'success': True,
                        'message': 'Data successfully edited',
                        'startup': startup_edited.data,
                        'status': status.HTTP_200_OK,
                    })
                else:
                    return Response({
                        'success': False,
                        'error': 'Serializer data is invalid.',
                        'serialized_data': startup_edited.data,
                        'serializer_errors': startup_edited.errors,
                        'status': status.HTTP_400_BAD_REQUEST,
                    }, status.HTTP_400_BAD_REQUEST)

            else:
                return Response({
                    'success': False,
                    'error': 'Cannot edit this Startup, not a cofounder ',
                    'status': status.HTTP_403_FORBIDDEN
                }, status.HTTP_403_FORBIDDEN)

        except startUp.DoesNotExist:
            return Response({
                'success': False,
                'error': 'No startup found. ',
                'status': status.HTTP_404_NOT_FOUND,
            }, status.HTTP_404_NOT_FOUND)
        except AssertionError:
            return Response({
                'success': False,
                'error': 'Parameter Error startup_id Not provided',
                'status': status.HTTP_400_BAD_REQUEST,
            }, status.HTTP_400_BAD_REQUEST)

        except Exception as e:
            err = repr(e)
            return Response({
                'success': False,
                'error': err,
                'status': status.HTTP_500_INTERNAL_SERVER_ERROR,
            }, status.HTTP_500_INTERNAL_SERVER_ERROR)
Example #4
0
    def post(self, request):

        file_path = user_images_file_path

        try:
            assert 'id' in request.data
            mentor = Mentor.objects.get(id=request.data['id'])
            if mentor.id == request.user.id:

                if request.FILES.get('image'):
                    image = request.FILES.get('image')
                    if image._size > 0:

                        file_name = ('-').join(
                            str(datetime.datetime.now()).split(' ')) + str(
                                image)
                        image_file = open(os.path.join(file_path, file_name),
                                          'wb')
                        image_file.write(image.read())
                        image_file.close()
                        image_path = boto_helper.upload_image(
                            file_path, file_name)
                        image_s3 = "https://" + CDN_DOMAIN + "/" + file_name
                        request.data['image'] = image_s3
                    else:
                        pass
                edited_mentor = MentorSerializer(mentor, data=request.data)

                if edited_mentor.is_valid():
                    edited_mentor.save()

                    return Response(
                        {
                            "sucess": True,
                            "error": "Details successfully edited",
                            "mentor": edited_mentor.data,
                            "status": status.HTTP_200_OK
                        }, status.HTTP_200_OK)
                else:

                    return Response(
                        {
                            'success': False,
                            'error': 'Serializer data is invalid.',
                            'serializer_errors': edited_mentor.errors,
                            'status': status.HTTP_400_BAD_REQUEST,
                        }, status.HTTP_400_BAD_REQUEST)
            else:

                return Response(
                    {
                        'success': False,
                        'error': 'Not authorised to edit the details',
                        'status': status.HTTP_403_FORBIDDEN,
                    }, status.HTTP_403_FORBIDDEN)

        except AssertionError:
            return Response(
                {
                    'success': False,
                    'error': 'id not provided',
                    'status_code': status.HTTP_400_BAD_REQUEST
                }, status.HTTP_400_BAD_REQUEST)

        except Mentor.DoesNotExist:
            return Response(
                {
                    'success': False,
                    'error': 'No such Mentor Exists',
                    'status': status.HTTP_404_NOT_FOUND,
                }, status.HTTP_404_NOT_FOUND)

        except Exception as e:
            traceback.print_exc()
            e = repr(e)
            return Response(
                {
                    'success': False,
                    'error': e,
                    'status': status.HTTP_500_INTERNAL_SERVER_ERROR,
                }, status.HTTP_500_INTERNAL_SERVER_ERROR)
Example #5
0
    def post(self, request):

        file_path = user_images_file_path
        try:
            assert 'id' in request.data
            user = MyUser.objects.get(id=request.data['id'])
            if request.user in user.startup.cofounders.all():

                if request.FILES.get('image'):
                    image = request.FILES.get('image')
                    if image._size > 0:
                        file_name = str(image)
                        image_file = open(os.path.join(file_path, file_name),
                                          'wb')
                        image_file.write(image.read())
                        image_file.close()
                        image_path = boto_helper.upload_image(
                            file_path, str(image))
                        image_s3 = "https://" + CDN_DOMAIN + "/" + file_name
                        request.data['image'] = image_s3
                    else:
                        pass

                cofounder_edited = UserSerializer(user, request.data)
                if cofounder_edited.is_valid():
                    cofounder_edited.save()
                    return Response({
                        'success': True,
                        'message': 'All the details have been updated',
                        'cofounder': cofounder_edited.data,
                        'status': status.HTTP_200_OK,
                    })
                else:
                    return Response(
                        {
                            'success': False,
                            'error': 'Serializer data is invalid.',
                            'serializer_errors': cofounder_edited.errors,
                            'status': status.HTTP_400_BAD_REQUEST,
                        }, status.HTTP_400_BAD_REQUEST)

            else:
                return Response(
                    {
                        'success': False,
                        'error': 'Not Authorised to edit the details',
                        'status': status.HTTP_403_FORBIDDEN
                    }, status.HTTP_403_FORBIDDEN)
        except AssertionError:
            return Response(
                {
                    'success': False,
                    'error': ' cofounderid not provided',
                    'status_code': status.HTTP_400_BAD_REQUEST,
                }, status.HTTP_400_BAD_REQUEST)

        except MyUser.DoesNotExist:
            return Response(
                {
                    'success': False,
                    'error': 'No such User Exists',
                    'status': status.HTTP_404_NOT_FOUND
                }, status.HTTP_404_NOT_FOUND)

        except Exception as e:
            e = repr(e)
            return Response(
                {
                    'success': False,
                    'error': e,
                    'status': status.HTTP_500_INTERNAL_SERVER_ERROR,
                }, status.HTTP_500_INTERNAL_SERVER_ERROR)