Ejemplo n.º 1
0
    def post(self, request):
        print request.POST
        # Submitted forms w/appropriate data
        submitted_user_form = UserForm(request.POST, prefix="user")
        submitted_trainee_form = TraineeForm(request.POST, prefix="trainee")

        if all([
                submitted_user_form.is_valid(),
                submitted_trainee_form.is_valid()
        ]):
            u_cleaned_data = submitted_user_form.cleaned_data
            t_cleaned_data = submitted_trainee_form.cleaned_data
            u = user_exists(u_cleaned_data)
            if u != None:  # If exists already
                if u.submitted_tp:  # If already submitted an app ...
                    messages.info(request,
                                  "You already submitted a Core Team App.")
                    return HttpResponseRedirect(reverse('core-team-success'))
                else:  # If just on mailing list
                    u.delete()
                    u = save_user_via_form(submitted_user_form,
                                           submitted_trainee_form, "trainee")
                    slack_message = "New Training Program application: *" + u.first_name + " " + u.last_name + "* | " + u.email
                    slack.post_message(joe_token, '#signups_applications',
                                       slack_message, "Railroad")
                    messages.info(
                        request,
                        "Thank you for applying to our Training Program")
                    return HttpResponseRedirect(
                        reverse('training-program-success'))
            else:  # Never been touched
                u = save_user_via_form(submitted_user_form,
                                       submitted_trainee_form, "trainee")
                slack_message = "New Training Program application: *" + u.first_name + " " + u.last_name + "* | " + u.email
                slack.post_message(joe_token, '#signups_applications',
                                   slack_message, "Railroad")
                mailchimp.add_member_to_list(mailchimp_api_key, info_list_id,
                                             9, u.email, u.first_name,
                                             u.last_name)
                messages.info(
                    request, "Thank you for applying to our Training Program!")
                return HttpResponseRedirect(
                    reverse('training-program-success'))

        else:
            return render(
                request, 'training-program.html', {
                    'request': request,
                    'email_form': self.email_form,
                    'user_form': submitted_user_form,
                    'trainee_form': submitted_trainee_form
                })
Ejemplo n.º 2
0
def register_user(request):

    context = RequestContext(request)

    registered = False
    er = []

    config = get_RegisterConfig_dc_active()

    if config.status == 1:

        if request.method == 'POST':
            user_form = UserForm(data=request.POST)
            profile_form = UserProfileForm(data=request.POST)

            if user_form.is_valid() and profile_form.is_valid():
                user = user_form.save()

                user.set_password(user.password)
                user.is_active = 0
                user.save()

                profile = profile_form.save(commit=False)
                profile.user = user
                profile.status_id = '4'

                if 'avatar' in request.FILES:
                    profile.avatar = request.FILES['avatar']
                profile.save()

                registered = True
            else:
                user_form = UserForm()
                profile_form = UserProfileForm()

        user_form = UserForm()
        profile_form = UserProfileForm()
        dict = {
            'template': template(),
            'footer_dc': footer_dc(),
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered,
            'conf': config.status
        }

        return render_to_response((template() + '/applications/register.html'),
                                  dict, context)
    else:
        dict = {
            'template': template(),
            'footer_dc': footer_dc(),
            'conf': config.status
        }
        return render_to_response((template() + '/applications/register.html'),
                                  dict, context)
Ejemplo n.º 3
0
def add_user(request):

    context = RequestContext(request)

    add = False
    er = []

    status = UserStatus_dc.objects.filter(active=1)

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)
            user.first_name = request.POST['first_name']
            user.last_name = request.POST['last_name']
            user.is_active = 0
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user
            profile.status_id = request.POST['status_id']
            profile.descriptions = request.POST['description']
            if 'avatar' in request.FILES:
                profile.avatar = request.FILES['avatar']
            profile.save()

            add = True
        else:
            user_form = UserForm()
            profile_form = UserProfileForm()

    user_form = UserForm()
    profile_form = UserProfileForm()
    dict = {
        'template': template(),
        'footer_dc': footer_dc(),
        'user_form': user_form,
        'profile_form': profile_form,
        'add': add,
        'status': status
    }

    return render_to_response((template() + '/applications/addUser.html'),
                              dict, context)
Ejemplo n.º 4
0
	def post(self, request):
		print request.POST
		# Submitted forms w/appropriate data 
		submitted_user_form = UserForm(request.POST, prefix="user")
		submitted_candidate_form = CandidateForm(request.POST, prefix="candidate")

		if all([submitted_user_form.is_valid(), submitted_candidate_form.is_valid()]): 
			u_cleaned_data = submitted_user_form.cleaned_data
			c_cleaned_data = submitted_candidate_form.cleaned_data
			u = user_exists(u_cleaned_data)
			if u != None: 
				if u.submitted_ct:
					messages.info(request, "You already submitted a Core Team App.")
					return HttpResponseRedirect(reverse('core-team-success'))
				else: 
					u.delete()
					u = save_user_via_form(submitted_user_form, submitted_candidate_form, "candidate")
					slack_message = "New Core Team application: *" + u.first_name + " " + u.last_name + "* | " + u.email
					slack.post_message(joe_token, '#signups_applications', slack_message, "Railroad")
					messages.info(request, "Thank you for applying to our Core Team!")
					return HttpResponseRedirect(reverse('core-team-success'))
			else: 
				u = save_user_via_form(submitted_user_form, submitted_candidate_form, "candidate")
				slack_message = "New Core Team application: *" + u.first_name + " " + u.last_name + "* | " + u.email
				slack.post_message(joe_token, '#signups_applications', slack_message, "Railroad")
				mailchimp.add_member_to_list(mailchimp_api_key, info_list_id, 9, u.email, u.first_name, u.last_name)
				messages.info(request, "Thank you for applying to our Core Team!")
				return HttpResponseRedirect(reverse('core-team-success'))		

		else: 
			return render(request, 'core-team.html', {
				'request': request,
				'email_form': self.email_form,
				'user_form': submitted_user_form,
				'candidate_form': submitted_candidate_form
			}); 
Ejemplo n.º 5
0
def edit_self_user(request, name):

    context = RequestContext(request)

    ed = False
    er = []

    status = UserStatus_dc.objects.filter(active=1)
    edit = User.objects.get(username=name)

    if request.method == 'POST':
        if request.user.id != edit.id:
            ed = False
            er.append("Nie masz uprawnien")
        else:
            user_form = UserForm(data=request.POST)
            profile_form = UserProfileForm(data=request.POST)
            edit1 = User.objects.get(id=edit.id)
            prof1 = UserProfile.objects.get(user_id=edit.id)

            edit1.first_name = request.POST['first_name']
            edit1.last_name = request.POST['last_name']
            edit1.email = request.POST['email']

            prof1.website = request.POST['website']
            prof1.status_id = edit1.userprofile.status.status
            prof1.descriptions = request.POST['description']

            if 'avatar' in request.FILES:
                prof1.avatar = request.FILES['avatar']
            prof1.save()

            edit1.save()
            prof1.save()

            ed = True

    dict = {
        'template': template(),
        'footer_dc': footer_dc(),
        'ed': ed,
        'status': status,
        'edit': edit
    }

    return render_to_response((template() + '/applications/editSelfUser.html'),
                              dict, context)
Ejemplo n.º 6
0
class CoreTeam(FormView):

    email_form = EmailForm()

    # Sets up appropriate forms w/proper prefixes for the purposes of validating
    # two forms on a single post request... one for the user, one for the candidate
    # associated with the user
    user_form = UserForm(prefix="user")
    candidate_form = CandidateForm(prefix="candidate")

    def get(self, request):
        template = loader.get_template('core-team.html')
        context = {
            'request': request,
            'email_form': self.email_form,
            'user_form': self.user_form,
            'candidate_form': self.candidate_form,
            'can_submit': limit > datetime.datetime.now()
        }

        return HttpResponse(template.render(context, request))

    def post(self, request):
        print request.POST
        # Submitted forms w/appropriate data
        submitted_user_form = UserForm(request.POST, prefix="user")
        submitted_candidate_form = CandidateForm(request.POST,
                                                 prefix="candidate")

        if all([
                submitted_user_form.is_valid(),
                submitted_candidate_form.is_valid()
        ]):
            u_cleaned_data = submitted_user_form.cleaned_data
            c_cleaned_data = submitted_candidate_form.cleaned_data
            u = user_exists(u_cleaned_data)
            if u != None:
                if u.submitted_ct:
                    messages.info(request,
                                  "You already submitted a Core Team App.")
                    return HttpResponseRedirect(reverse('core-team-success'))
                else:
                    u.delete()
                    u = save_user_via_form(submitted_user_form,
                                           submitted_candidate_form,
                                           "candidate")
                    slack_message = "New Core Team application: *" + u.first_name + " " + u.last_name + "* | " + u.email
                    slack.post_message(joe_token, '#signups_applications',
                                       slack_message, "Railroad")
                    messages.info(request,
                                  "Thank you for applying to our Core Team!")
                    return HttpResponseRedirect(reverse('core-team-success'))
            else:
                u = save_user_via_form(submitted_user_form,
                                       submitted_candidate_form, "candidate")
                slack_message = "New Core Team application: *" + u.first_name + " " + u.last_name + "* | " + u.email
                slack.post_message(joe_token, '#signups_applications',
                                   slack_message, "Railroad")
                mailchimp.add_member_to_list(mailchimp_api_key, info_list_id,
                                             9, u.email, u.first_name,
                                             u.last_name)
                messages.info(request,
                              "Thank you for applying to our Core Team!")
                return HttpResponseRedirect(reverse('core-team-success'))

        else:
            return render(
                request, 'core-team.html', {
                    'request': request,
                    'email_form': self.email_form,
                    'user_form': submitted_user_form,
                    'candidate_form': submitted_candidate_form
                })
Ejemplo n.º 7
0
class TrainingProgram(FormView):

    email_form = EmailForm()

    # Prefixed separate form processing
    user_form = UserForm(prefix="user")
    trainee_form = TraineeForm(prefix="trainee")

    def get(self, request):
        template = loader.get_template('training-program.html')
        context = {
            'request': request,
            'email_form': self.email_form,
            'user_form': self.user_form,
            'trainee_form': self.trainee_form,
            'can_submit': limit >
            datetime.datetime.now()  # True if can submit, false if otherwise 
        }
        return HttpResponse(template.render(context, request))

    def post(self, request):
        print request.POST
        # Submitted forms w/appropriate data
        submitted_user_form = UserForm(request.POST, prefix="user")
        submitted_trainee_form = TraineeForm(request.POST, prefix="trainee")

        if all([
                submitted_user_form.is_valid(),
                submitted_trainee_form.is_valid()
        ]):
            u_cleaned_data = submitted_user_form.cleaned_data
            t_cleaned_data = submitted_trainee_form.cleaned_data
            u = user_exists(u_cleaned_data)
            if u != None:  # If exists already
                if u.submitted_tp:  # If already submitted an app ...
                    messages.info(request,
                                  "You already submitted a Core Team App.")
                    return HttpResponseRedirect(reverse('core-team-success'))
                else:  # If just on mailing list
                    u.delete()
                    u = save_user_via_form(submitted_user_form,
                                           submitted_trainee_form, "trainee")
                    slack_message = "New Training Program application: *" + u.first_name + " " + u.last_name + "* | " + u.email
                    slack.post_message(joe_token, '#signups_applications',
                                       slack_message, "Railroad")
                    messages.info(
                        request,
                        "Thank you for applying to our Training Program")
                    return HttpResponseRedirect(
                        reverse('training-program-success'))
            else:  # Never been touched
                u = save_user_via_form(submitted_user_form,
                                       submitted_trainee_form, "trainee")
                slack_message = "New Training Program application: *" + u.first_name + " " + u.last_name + "* | " + u.email
                slack.post_message(joe_token, '#signups_applications',
                                   slack_message, "Railroad")
                mailchimp.add_member_to_list(mailchimp_api_key, info_list_id,
                                             9, u.email, u.first_name,
                                             u.last_name)
                messages.info(
                    request, "Thank you for applying to our Training Program!")
                return HttpResponseRedirect(
                    reverse('training-program-success'))

        else:
            return render(
                request, 'training-program.html', {
                    'request': request,
                    'email_form': self.email_form,
                    'user_form': submitted_user_form,
                    'trainee_form': submitted_trainee_form
                })