示例#1
0
def home(request, survey_type = 'TEAMTEMP'):
    timezone.activate(pytz.timezone('UTC'))
    if request.method == 'POST':
        form = CreateSurveyForm(request.POST, error_class=ErrorBox)
        if form.is_valid():
            csf = form.cleaned_data
            form_id = utils.random_string(8)
            userid = responses.get_or_create_userid(request)
            user, created = User.objects.get_or_create(id=userid)
            # TODO check that id is unique!
            dept_names = csf['dept_names']
            region_names = csf['region_names']
            site_names = csf['site_names']
            survey = TeamTemperature(creation_date = timezone.now(),
                                     password = make_password(csf['password']),
                                     creator = user,
                                     survey_type = survey_type,
                                     archive_date = timezone.now(),
                                     id = form_id,
                                     dept_names = dept_names,
                                     region_names = region_names,
                                     site_names = site_names,
                                     archive_schedule = 7,
                                     default_tz = 'UTC'
                                     )
            survey.save()
            return HttpResponseRedirect('/team/%s' % (form_id))
    else:
        form = CreateSurveyForm()
    return render(request, 'index.html', {'form': form, 'survey_type': survey_type})
示例#2
0
def home(request, survey_type = 'TEAMTEMP'):
    timezone.activate(pytz.timezone('Australia/Queensland'))
    if request.method == 'POST':
        form = CreateSurveyForm(request.POST, error_class=ErrorBox)
        if form.is_valid():
            csf = form.cleaned_data
            form_id = utils.random_string(8)
            userid = responses.get_or_create_userid(request)
            user, created = User.objects.get_or_create(id=userid)
            # TODO check that id is unique!
            team_name = csf['team_name'].replace(" ", "_")
            survey = TeamTemperature(creation_date = timezone.now(),
                                     password = make_password(csf['password']),
                                     creator = user,
                                     survey_type = survey_type,
                                     archive_date = timezone.now(),
                                     id = form_id)
            survey.save()
            team_details = Teams(request = survey,
                                team_name = team_name)
            team_details.save()
            return HttpResponseRedirect('/admin/%s/%s' % (form_id, team_name))
    else:
        form = CreateSurveyForm()
    return render(request, 'index.html', {'form': form})
示例#3
0
def create_userid(request):
    session = request.session
    session[USER_ID_KEY] = utils.random_string(32)

    session.save()

    return session[USER_ID_KEY]
示例#4
0
def home_view(request, survey_type='TEAMTEMP'):
    timezone.activate(timezone.utc)
    if request.method == 'POST':
        form = CreateSurveyForm(request.POST, error_class=ErrorBox)
        if form.is_valid():
            csf = form.cleaned_data
            form_id = utils.random_string(8)
            user, created = get_or_create_user(request)
            dept_names = csf['dept_names']
            region_names = csf['region_names']
            site_names = csf['site_names']
            survey = TeamTemperature(password=make_password(csf['password']),
                                     creator=user,
                                     survey_type=survey_type,
                                     archive_date=timezone.now(),
                                     id=form_id,
                                     dept_names=dept_names,
                                     region_names=region_names,
                                     site_names=site_names,
                                     archive_schedule=7,
                                     default_tz='UTC'
                                     )
            survey.save()

            responses.add_admin_for_survey(request, survey.id)

            return HttpResponseRedirect('/team/%s' % form_id)
    else:
        form = CreateSurveyForm()
    return render(request, 'index.html', {'form': form, 'survey_type': survey_type})
def admin(request):
    if request.method == 'POST':
        form_id = utils.random_string(8)
        # TODO check that id is unique!
        survey = TeamTemperature(creation_date=datetime.now(), creator=request.user, id=form_id)
        survey.save()
        return HttpResponseRedirect('/admin/%s' % form_id)
    return render(request, 'admin.html')
示例#6
0
    def test_get_temperature_with_previous_response_view(self, mock_session_id):

        responding_user = UserFactory(id=utils.random_string(8))
        mock_session_id.return_value = responding_user.id

        team_temp = TeamTemperatureFactory()
        existing_response = TeamResponseFactory(request=team_temp, responder=responding_user)

        response = self.client.get(reverse('temp', args=[str(team_temp.id)]))

        self.assertTemplateUsed(response, 'form.html')
        self.assertContains(response, 'Submit your temperature')
        self.assertContains(response, existing_response.id)
示例#7
0
    def test_get_temperature_with_previous_response_view(
            self, mock_session_id):

        responding_user = UserFactory(id=utils.random_string(8))
        mock_session_id.return_value = responding_user.id

        team_temp = TeamTemperatureFactory()
        existing_response = TeamResponseFactory(request=team_temp,
                                                responder=responding_user)

        response = self.client.get(reverse('temp', args=[str(team_temp.id)]))

        self.assertTemplateUsed(response, 'form.html')
        self.assertContains(response, 'Submit your temperature')
        self.assertContains(response, existing_response.id)
示例#8
0
def home(request):
    if request.method == 'POST':
        form = CreateSurveyForm(request.POST, error_class=ErrorBox)
        if form.is_valid():
            csf = form.cleaned_data
            form_id = utils.random_string(8)
            userid = responses.get_or_create_userid(request)
            user, created = User.objects.get_or_create(id=userid)
            # TODO check that id is unique!
            survey = TeamTemperature(creation_date = datetime.now(),
                                     password = make_password(csf['password']),
                                     creator = user,
                                     id = form_id)
            survey.save()
            return HttpResponseRedirect('/admin/%s' % form_id)
    else:
        form = CreateSurveyForm()
    return render(request, 'index.html', {'form': form})
示例#9
0
def home_view(request, survey_type='TEAMTEMP'):
    timezone.activate(timezone.utc)

    if request.method == 'POST':
        form = CreateSurveyForm(request.POST, error_class=ErrorBox)
        if form.is_valid():
            csf = form.cleaned_data

            survey_id = utils.random_string(8)
            user = get_or_create_user(request)

            survey = TeamTemperature(
                id=survey_id,
                password=make_password(
                    csf['new_password']),
                creator=user,
                survey_type=survey_type,
                archive_date=timezone.now(),
                dept_names=csf['dept_names'],
                region_names=csf['region_names'],
                site_names=csf['site_names'],
                archive_schedule=7,
                default_tz='UTC')
            survey.fill_next_archive_date()
            survey.full_clean()
            survey.save()

            responses.add_admin_for_survey(request, survey.id)

            messages.success(request, 'Survey %s created.' % survey.id)

            return redirect('team', survey_id=survey_id)
    else:
        form = CreateSurveyForm()

    return render(
        request, 'index.html', {
            'form': form, 'survey_type': survey_type})
示例#10
0
def home(request, survey_type='TEAMTEMP'):
    timezone.activate(pytz.timezone('Australia/Queensland'))
    if request.method == 'POST':
        form = CreateSurveyForm(request.POST, error_class=ErrorBox)
        if form.is_valid():
            csf = form.cleaned_data
            form_id = utils.random_string(8)
            userid = responses.get_or_create_userid(request)
            user, created = User.objects.get_or_create(id=userid)
            # TODO check that id is unique!
            team_name = csf['team_name'].replace(" ", "_")
            survey = TeamTemperature(creation_date=timezone.now(),
                                     password=make_password(csf['password']),
                                     creator=user,
                                     survey_type=survey_type,
                                     archive_date=timezone.now(),
                                     id=form_id)
            survey.save()
            team_details = Teams(request=survey, team_name=team_name)
            team_details.save()
            return HttpResponseRedirect('/admin/%s/%s' % (form_id, team_name))
    else:
        form = CreateSurveyForm()
    return render(request, 'index.html', {'form': form})
示例#11
0
def get_or_create_userid(request):
    if 'userid' not in request.session:
        request.session['userid'] = utils.random_string(8)
    return request.session['userid']
示例#12
0
def make_uuid():
    return utils.random_string(8)
示例#13
0
 def test_homepage_create_teamtemp(self):
     password = utils.random_string(8)
     data = {'survey_type': 'TEAMTEMP', 'new_password': password, 'confirm_password': password}
     response = self.client.post(reverse('home'), data, follow=True)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertTemplateUsed(response, 'team.html')
示例#14
0
def get_or_create_userid(request):
    if 'userid' not in request.session:
        request.session['userid'] = utils.random_string(8)
    return request.session['userid']
示例#15
0
def make_uuid():
    return utils.random_string(8)
示例#16
0
def create_userid(request):
    request.session[USER_ID_KEY] = utils.random_string(32)
    return request.session[USER_ID_KEY]