• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.Survey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: list_qsets

def list_qsets(request):
    if request.GET.get('survey_id'):
        values = Survey.get(
            id=request.GET.get('survey_id')).qsets.values(
            'id', 'name')
    else:
        values = QuestionSet.objects.values('id', 'name')
    return HttpResponse(
        json.dumps(
            list(values)),
        content_type='application/json')
开发者ID:unicefuganda,项目名称:uSurvey,代码行数:11,代码来源:question_set.py


示例17: addItems

def addItems():
	form = cgi.FieldStorage();
	user = users.get_current_user();
	sName = form['addon'].value;
	sName1 = sName.split(" by ");
	sName2 = sName1[0]; 
	surveyName = sName2.replace("__"," ");
	rawOptions = form['additems'].value;
	rawOptions += ',';
	optionList = rawOptions.split(',');
	counter = 0;
	for option in optionList:
			itemPresent = db.GqlQuery("SELECT * FROM Item WHERE name = :1 AND survey = :2 and owner = :3",option,surveyName,user);
			counter1 = itemPresent.count();
			if (counter1 > 0):
				counter = counter + 1;
	if (counter > 0):
		return render_template('failure.html',message="One or more items that you tried to add are already present in this category.None of the items were added.");
	else:
		surveys = db.GqlQuery("SELECT * FROM Survey WHERE name = :1 and owner = :2",surveyName,user);
		oldItemList = [];
		oldExpiration ="";
		for sur in surveys:
			if (sur.name == surveyName):
				oldItemList = sur.values;
				oldExpiration = sur.expiration;
		for newItems in optionList:
			oldItemList.append(newItems);
		newItemList = oldItemList;
		db.delete(surveys);
		newSurvey = Survey(name=surveyName,owner=user,values=newItemList,expiration=oldExpiration);
		newSurvey.put();
		for option in optionList:
                    if option:
                                item = Item(name=option);
                                item.survey = surveyName;
                                item.owner = user;
                                search1 = Search(name=option,entityType="item",survey=surveyName,owner=user);
                                item.put();
                                search1.put();
		return render_template('survey_confirmation.html',survey=surveyName,option=optionList);
开发者ID:prasadkapde,项目名称:OstfinalProject,代码行数:41,代码来源:views.py


示例18: addSurvey

def addSurvey():
	form = cgi.FieldStorage();
	user = users.get_current_user();
	surveyName = form['sname'].value.strip();	
	rawOptions = form['options'].value;
	rawOptions += ',';
	optionList = rawOptions.split(',');
	surveyExpireDate = "";
	if (form.has_key("dateValue")):
		expireDate = form['dateValue'].value;
		expireHour = int(form['hours'].value);
		expireMinutes = int(form['minutes'].value);
		expireSeconds = int(form['seconds'].value);
		rawDate = expireDate.split("/");
		month = int(rawDate[0]);
		day = int(rawDate[1]);
		year = int(rawDate[2]);
		surveyExpireDate = datetime.datetime(year,month,day,expireHour,expireMinutes,expireSeconds);
	else:
		surveyExpireDate = datetime.datetime(2012,12,30,0,0,0);
	surveys = db.GqlQuery("SELECT * FROM Survey WHERE name = :1 and owner = :2",surveyName,user);
	counter = surveys.count();
	if (counter == 0):
		survey = Survey(name=surveyName,expiration=surveyExpireDate);
		survey.values = optionList;
		survey.owner = user;
		survey.put();
		search = Search(name=surveyName,entityType="survey",survey=surveyName,owner=user);
		search.put();
		for option in optionList:
			if option:
				item = Item(name=option);
				item.survey = surveyName;
				item.owner = user;
				item.put();
				search1 = Search(name=option,entityType="item",survey=surveyName,owner=user);
				search1.put();
		return render_template('survey_confirmation.html',survey=surveyName,option=optionList);
	else:
		return render_template('failure.html',message="You already have created this survey! Please create a different survey.");
开发者ID:prasadkapde,项目名称:OstfinalProject,代码行数:40,代码来源:views.py


示例19: renameCategory

def renameCategory():
	form = cgi.FieldStorage();
	user = users.get_current_user();
	newSurveyName = form['renameText'].value.strip();
	oldSurveyName = form['renamesurvey'].value;
	newNameCheck = db.GqlQuery("SELECT * FROM Survey WHERE owner = :1 AND name = :2",user,newSurveyName);
	counter = newNameCheck.count();
	if (counter > 0):
			return render_template('failure.html',message="You already have a survey with given name. Please try with some other name");
	else:
		oldSurvey = db.GqlQuery("SELECT * FROM Survey WHERE owner = :1 AND name = :2",user,oldSurveyName);
		for old in oldSurvey:
			newSurvey = Survey(name=newSurveyName,values=old.values,owner=old.owner,expiration=old.expiration);
			newSurvey.put();
		oldItems = db.GqlQuery("SELECT * FROM Item WHERE survey = :1 and owner = :2",oldSurveyName,user);
		for old in oldItems:
			newItem = Item(name=old.name,image=old.image,survey=newSurveyName,owner=old.owner);
			newItem.put();
		oldVotes = db.GqlQuery("SELECT * FROM Vote WHERE survey = :1 and owner = :2",oldSurveyName,user);
		for old in oldVotes:
			newVote = Vote(name=old.name,owner=old.owner,win=old.win,survey=newSurveyName);
			newVote.put();
		oldComments = db.GqlQuery("SELECT * FROM Comments WHERE itemOwner = :1 AND survey = :2",user,oldSurveyName);
		for old in oldComments:
			newComment = Comments(itemName=old.itemName,itemOwner=old.itemOwner,comment=old.comment,survey=newSurveyName);
			newComment.put();
		oldCommentValidator = db.GqlQuery("SELECT * FROM CommentValidator where itemOwner = :1 and survey = :2",user,oldSurveyName);
		for old in oldCommentValidator:
			newCommentValidator = CommentValidator(itemName=old.itemName,itemOwner=old.itemOwner,commenter=old.commenter,survey=newSurveyName);
			newCommentValidator.put();
		oldSearch = db.GqlQuery("SELECT * FROM  Search WHERE survey = :1 AND owner = :2",oldSurveyName,user);
		for old in oldSearch:
			if(old.entityType == "survey"):
				newSearch = Search(name=newSurveyName,entityType=old.entityType,survey=newSurveyName,owner=old.owner);
				newSearch.put();
			else:
				newSearch = Search(name=old.name,entityType=old.entityType,survey=newSurveyName,owner=old.owner);
				newSearch.put();
		deleteGeneric(surveyName=oldSurveyName);
		return render_template('failure.html',message="Update Successful!");
开发者ID:prasadkapde,项目名称:OstfinalProject,代码行数:40,代码来源:views.py


示例20: index

def index(request, survey_id=None):
    if survey_id:
        survey = Survey.get(pk=survey_id)
    request.breadcrumbs(Batch.index_breadcrumbs(survey=survey))
    if survey_id is None:
        batches = Batch.objects.all()
    else:
        batches = Batch.objects.filter(survey__id=survey_id)
    qset_view = QuestionSetView(model_class=Batch)
    qset_view.questionSetForm = BatchForm
    return qset_view.index(
        request, batches, extra_context={
            'survey': survey}, initial={
            'survey': survey.pk})
开发者ID:unicefuganda,项目名称:uSurvey,代码行数:14,代码来源:batch.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.SurveyForm类代码示例发布时间:2022-05-27
下一篇:
Python survey.AnonymousSurvey类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap