当前位置: 首页>>代码示例>>Python>>正文


Python models.Survey类代码示例

本文整理汇总了Python中survey.models.Survey的典型用法代码示例。如果您正苦于以下问题:Python Survey类的具体用法?Python Survey怎么用?Python Survey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Survey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: edit

def edit(request, survey_id):
    try:
        survey = Survey.objects.get(id=survey_id)
        survey_form = SurveyForm(instance=survey)
        if request.method == 'POST':
            survey_form = SurveyForm(instance=survey, data=request.POST)
            if survey_form.is_valid():
                Survey.save_sample_size(survey_form)
                messages.success(request, 'Survey successfully edited.')
                return HttpResponseRedirect(reverse('survey_list_page'))
            elif survey_form.errors.get('__all__'):
                messages.error(request, survey_form.errors['__all__'])
        context = {'survey_form': survey_form,
                   'title': "Edit Survey",
                   'button_label': 'Save',
                   'id': 'edit-survey-form',
                   'cancel_url': request.META.get('HTTP_REFERER') or reverse('survey_list_page'),
                   'action': reverse('edit_survey_page', args=(survey_id, ))
                   }
        request.breadcrumbs([
            ('Surveys', reverse('survey_list_page')),
        ])
        return render(request, 'surveys/new.html', context)
    except Survey.DoesNotExist:
        messages.error(request, 'survey does not exists')
        return HttpResponseRedirect(reverse('survey_list_page'))
开发者ID:unicefuganda,项目名称:uSurvey,代码行数:26,代码来源:surveys.py

示例2: deleteItem

def deleteItem():
	form = cgi.FieldStorage();
	vote = form['voteon'].value;	
        item = vote.replace("__"," ");
	survey = form['survey'].value;	
	owner = users.get_current_user();
	oldSurvey = db.GqlQuery("SELECT * FROM Survey WHERE name = :1 and owner = :2",survey,owner);
	oldValues = [];
	oldExpiration="";
	for sur in oldSurvey:
		oldValues = sur.values;
		oldExpiration = sur.expiration;
	oldValues.remove(item);
	newSurvey = Survey(name=survey,owner=owner,values=oldValues,expiration=oldExpiration);
	db.delete(oldSurvey);
	newSurvey.put();
	oldItem = db.GqlQuery("SELECT * FROM Item WHERE name = :1 and owner = :2 and survey = :3",item,owner,survey);
	db.delete(oldItem);
	oldSearch = db.GqlQuery("SELECT * FROM Search WHERE name = :1 and owner = :2 and survey = :3 and entityType = :4",item,owner,survey,"item");
	db.delete(oldSearch);
	oldComment = db.GqlQuery("SELECT * FROM Comments WHERE itemName = :1 AND itemOwner = :2 AND survey = :3",item,owner,surveyName);
	db.delete(oldComment);
	oldCommentValidator = db.GqlQuery("SELECT * FROM CommentValidator WHERE itemName = :1 AND itemOwner = :2 AND survey = :3",item,owner,surveyName);
	db.delete(oldCommentValidator);
	oldVote = db.GqlQuery("SELECT * FROM Vote WHERE name = :1 AND owner = :2 AND survey = :3",item,owner,surveyName);
	db.delete(oldVote);
	return render_template('survey_confirmation.html',survey=survey,option=oldValues);
开发者ID:prasadkapde,项目名称:OstfinalProject,代码行数:27,代码来源:views.py

示例3: test_save_modified_time

 def test_save_modified_time(self):
     s = Survey(name='Survey')
     minute_slice = slice(0, 17)
     time = str(datetime.datetime.now())
     s.save()
     saved_time = str(s.created_at)
     self.assertEqual(saved_time[minute_slice], time[minute_slice])
开发者ID:bbuhai,项目名称:dlp-django-survey,代码行数:7,代码来源:test_models.py

示例4: submit

def submit(request):
    if request.method == 'POST':
        s = Survey(data = request.raw_post_data,
                   remote_addr = request.META["REMOTE_ADDR"],
                   user_agent = request.META["HTTP_USER_AGENT"])
        s.save()

    return HttpResponse("OK")
开发者ID:openmir,项目名称:openmir,代码行数:8,代码来源:views.py

示例5: handle

    def handle(self, *args, **options):
        # TODO: Remove or improve before production...
        logger.info('Deleting all surveys...')

        User.objects.filter(is_staff=False).delete()
        Survey.objects.all().delete()
        ChallengeDetail.objects.all().delete()

        logger.info('Starting import...')
        df = pd.read_excel(path.join(settings.BASE_DIR, 'respondents.xlsx'), sheetname='Delegates')
        df.fillna('', inplace=True)

        for idx, survey in df.iterrows():
            data_raw = survey.to_dict()
            data = {k: str(v).strip() for k, v in data_raw.items()}

            try:
                country = Country.objects.get(name=data.get('country_of_operation'))
                data.update({'country_of_operation': country})

            except Country.DoesNotExist:
                logger.warning('Could not find country %s' % data.get('country_of_operation'))
                data.update({'country_of_operation': None})

            del data['countries']

            # Create and associate user
            username = slugify(data.get('name')).replace('-', '_')
            slug = '{0}_{1}'.format(data.get('slug')[2:] or slug_generator(), username)
            logger.info(slug)
            user = User.objects.create_user(username[:30], data.get('email', ''), slug)

            survey = Survey(**data)
            survey.slug = slug
            survey.user = user
            survey.save()
            assign_perm('change_survey', user, obj=survey)

            # Creating challenges
            # for challenge in Challenge.objects.all():
            #     ChallengeDetail.objects.create(owner=slug, challenge=challenge)

            for rank in range(1, 4):
                ChallengeDetail.objects.create(respondent=survey, rank=rank)

            # try:
            #     Survey(**data).save()
            # except IntegrityError:
            #     logger.excep('Integ exisits: %s ' % data)
            # except:
            #     logger.exception(data)
            # else:
            #     for challenge in Challenge.objects.all():
            #         ChallengeDetail.objects.create(slug, challenge)

        logger.info('Done')
开发者ID:jr-minnaar,项目名称:djskel,代码行数:56,代码来源:import_delegates.py

示例6: login_user

def login_user(request, slug):
    logger.info('Slug is: {}, trying to log in...'.format(slug))

    request.session['survey_slug'] = slug
    request.session.save()
    survey_instance = None

    try:
        survey_instance = Survey.objects.get(slug=slug)

    except Survey.DoesNotExist:
        logger.info('Survey does not exist...')
        user = User(username=slug[30:])
        user.set_password(slug)
        user.email = ''
        user.save()
        logger.info('Saved new user... {}'.format(user))
        survey_instance = Survey(slug=slug, user=user)
        survey_instance.save()
        logger.info('Saved new survey... {}'.format(survey_instance))

        for rank in range(1, 4):
            ChallengeDetail.objects.create(respondent=survey_instance, rank=rank)
            logger.info('Added new ChallengeDetail with respondent = {} and rank = {}'.format(survey_instance, rank))

    else:
        logger.info('Found survey and use!:')

    finally:
        if request.user.is_staff:
            logger.info('Staff in the house!!')

        else:
            user = authenticate(username=survey_instance.user.username, password=slug)
            logger.info('Not staff, who is %s' % survey_instance.user.username)

            if user is not None:
                # If staff member is testing
                if user.is_active:
                    logger.info('User is active!')
                    login(request, user)
                    # Redirect to a success page
                else:
                    logger.warn('User not active')
                    pass
                    # Return a 'disabled account' error message
            else:
                logger.warn('Authentication Failed')
                pass
                # Return an 'invalid login' error message.

        # logger.info('Confirming that survey_slug is stored: {}'.format(request.session['survey_slug']))
        return HttpResponseRedirect(reverse('survey:about'))
开发者ID:jr-minnaar,项目名称:djskel,代码行数:53,代码来源:views.py

示例7: post

 def post(self, request, *args, **kwargs):
     warnings = []
     data = json.loads(request.POST.get('r'))
     title = data.get('title', '')
     slug = slugify(data.get('slug') or title)
     if not slug:
         warnings.append(_('Please enter a valid title.'))
         return HttpResponse(json.dumps({'status': 'failure', 'warnings': warnings}), mimetype='application/json')
     try:
         survey = self.get_object()
         if slug != survey.slug:
             warnings.append(_("This survey's URL has been changed. Be sure to update any QR code images."))
     except AttributeError:
         survey = Survey(creator=request.user)
     survey.title = title
     survey.slug = slug
     survey.description = data.get('description', '')
     try:
         survey.save()
     except IntegrityError:
         warnings = [_('That title is already taken. Please choose a different one.')]
         return HttpResponse(json.dumps({'status': 'failure', 'warnings': warnings}), mimetype='application/json')
     # delete existing questions
     # due to cascading deletes, this will also delete choices
     QuestionGroup.objects.filter(pk__in=survey.question_set.all().values_list('group')).delete()
     survey.question_set.all().delete()
     questions = data.get('questions', [])
     groups = data.get('groups', [])
     survey.add_questions(questions, groups)
     return HttpResponse(json.dumps({'status': 'success', 'warnings': warnings, 'url': reverse('surveydashboard', args=[survey.slug])}), mimetype='application/json')
开发者ID:ThatClyde,项目名称:django-resnet-survey,代码行数:30,代码来源:views.py

示例8: get_household_list

 def get_household_list(self, non_response_reporting=False):
     open_survey = Survey.currently_open_survey(self.investigator.location)
     page = self.get_from_session('PAGE')
     self.responseString += "%s\n%s" % (
         self.MESSAGES['HOUSEHOLD_LIST'],
         self.investigator.households_list(page, registered=False, open_survey=open_survey,
                                           non_response_reporting=non_response_reporting))
开发者ID:unicefuganda,项目名称:mics,代码行数:7,代码来源:ussd.py

示例9: __init__

 def __init__(self, *args, **kwargs):
     super(IndicatorForm, self).__init__(*args, **kwargs)
     if kwargs.get('instance'):
         qset = kwargs['instance'].question_set
         survey = kwargs['instance'].survey
         self.fields['survey'].initial = survey
         self.fields['survey'].widget.attrs['readonly'] = 'readonly'
         self.fields['question_set'].queryset = survey.qsets
         self.fields['question_set'].initial = qset
         self.fields['question_set'].widget.attrs['readonly'] = 'readonly'
         self.fields['variables'].initial = kwargs['instance'].variables.all()
     self.fields['variables'].queryset = self.available_variables()
     self.fields['variables'].icons = {
             'add': {
                 'data-toggle': "modal",
                 'data-target': "#add_variable",
                 'id': 'add_new_variable',
                 'title': 'Add Variable'},
             'edit': {
                 'data-toggle': "modal",
                 'title': 'Edit Variable',
                 'id': 'edit_variable'},
             'delete': {
                 'data-toggle': "modal",
                 'data-target': "#remove-selected-variable",
                 'id': 'delete_variable',
                 'title': 'Delete Variable'}}
     self.fields['formulae'].icons = {'check': {'id': 'validate', 'title': 'Validate'}, }
     if self.data.get('survey'):
         self.fields['question_set'].queryset = Survey.get(
             pk=self.data['survey']).qsets
     self.fields['name'].label = 'Indicator'
     self.order_fields(['survey', 'question_set', 'name',
                        'description', 'variables', 'formulae'])
开发者ID:unicefuganda,项目名称:uSurvey,代码行数:34,代码来源:indicator.py

示例10: get

    def get(self, request):
        from django.http import HttpResponse
        surveys = Survey.objects.all()
        temp = path(tempfile.mkdtemp())
        filename = temp / 'survey.xls'

        wb = xlwt.Workbook()
        ws = wb.add_sheet('Survey')

        # adding columns
        columns = Survey.get_fields_for_serialization()
        for i, field in enumerate(columns):
            ws.write(0, i, capfirst(field.verbose_name))
        # adding rows
        for i, survey in enumerate(surveys):
            for j, field in enumerate(columns):
                ws.write(i+1, j, survey.serialize_field(field))

        wb.save(filename)

        # keep the file open until the download is finished
        # temp folder will be deleted after
        try:
            file_path = open(filename)
        finally:
            temp.rmtree()

        response = StreamingHttpResponse(self.read_file(file_path),
                                         content_type='application/xls')
        response['Content-Disposition'] = 'attachment; filename="survey.xls"'
        return response
开发者ID:eaudeweb,项目名称:eea.tavl,代码行数:31,代码来源:views.py

示例11: wipe_survey_data

def wipe_survey_data(request, survey_id):
    from survey.models import Interview
    from survey.utils import views_helper
    if views_helper.has_super_powers(request):
        survey = Survey.get(pk=survey_id)
        Interview.objects.filter(survey=survey).delete()
        messages.info(request, 'Data has been cleared for %s' % survey.name)
    return HttpResponseRedirect(reverse('survey_list_page'))
开发者ID:unicefuganda,项目名称:uSurvey,代码行数:8,代码来源:surveys.py

示例12: select_household

 def select_household(self, answer, non_response_reporting=False):
     try:
         answer = int(answer)
         open_survey = Survey.currently_open_survey(self.investigator.location)
         self.household = self.investigator.all_households(open_survey, non_response_reporting)[answer - 1]
         self.set_in_session('HOUSEHOLD', self.household)
     except (ValueError, IndexError) as e:
         self.responseString += "INVALID SELECTION: "
开发者ID:unicefuganda,项目名称:mics,代码行数:8,代码来源:ussd.py

示例13: load_data

def load_data(apps, schema_editor):

    model_survey = apps.get_model("survey", "Survey")

    for survey in model_survey.objects.all():

        # update survey
        survey.code = Survey.create_random_survey_code()
        survey.save()
开发者ID:INCF,项目名称:nes,代码行数:9,代码来源:0003_questionnaire_code_migration.py

示例14: render_homepage

    def render_homepage(self):
        open_survey = Survey.currently_open_survey(self.investigator.location)
        answer = self.request['ussdRequestString'].strip()

        if not self.investigator.has_households(survey=open_survey):
            self.action = self.ACTIONS['END']
            self.responseString = self.MESSAGES['NO_HOUSEHOLDS']
        else:
            self.render_household_or_household_member(answer, open_survey)
开发者ID:xkmato,项目名称:mics,代码行数:9,代码来源:ussd_survey.py

示例15: set_household_form

def set_household_form(uid=None, data=None, is_edit=False, instance=None):
    household_form = {}
    if not is_edit:
        household_form['householdHead'] = HouseholdHeadForm(data=data, auto_id='household-%s', label_suffix='')

    open_survey = Survey.currently_open_survey()

    household_form['household'] = HouseholdForm(data=data, instance=instance, is_edit=is_edit, uid=uid,
                                                survey=open_survey, auto_id='household-%s', label_suffix='')
    return household_form
开发者ID:unicefuganda,项目名称:mics,代码行数:10,代码来源:household.py


注:本文中的survey.models.Survey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。