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


Python models.Submission类代码示例

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


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

示例1: save

 def save(self, *args, **kwargs):
     changed_with = kwargs.pop("changed_with", None)
     kwargs["commit"] = False
     unit = super(UnitForm, self).save(*args, **kwargs)
     with update_data_after(unit.store):
         current_time = timezone.now()
         if SubmissionFields.TARGET in (f[0] for f in self.updated_fields):
             unit.submitted_by = self.user
             unit.submitted_on = current_time
             unit.reviewed_by = None
             unit.reviewed_on = None
         suggestion = self.cleaned_data["suggestion"]
         user = (
             suggestion.user
             if suggestion
             else self.user)
         unit.save(
             submitted_on=current_time,
             submitted_by=user,
             changed_with=changed_with)
         translation_project = unit.store.translation_project
         for field, old_value, new_value in self.updated_fields:
             if field == SubmissionFields.TARGET and suggestion:
                 old_value = str(suggestion.target_f)
             sub = Submission(
                 creation_time=current_time,
                 translation_project=translation_project,
                 submitter=self.user,
                 unit=unit,
                 field=field,
                 type=SubmissionTypes.WEB,
                 old_value=old_value,
                 new_value=new_value)
             sub.save()
     return unit
开发者ID:claudep,项目名称:pootle,代码行数:35,代码来源:forms.py

示例2: toggle_qualitycheck

    def toggle_qualitycheck(self, check_id, false_positive, user):
        check = self.qualitycheck_set.get(id=check_id)

        if check.false_positive == false_positive:
            return

        self.revision = Revision.incr()
        self.save(
            reviewed_by=user)
        check.false_positive = false_positive
        check.save()

        # create submission
        old_value = MUTED
        new_value = UNMUTED
        if false_positive:
            old_value = UNMUTED
            new_value = MUTED

        update_time = make_aware(timezone.now())
        sub = Submission(
            creation_time=update_time,
            translation_project=self.store.translation_project,
            submitter=user,
            field=SubmissionFields.NONE,
            unit=self,
            type=SubmissionTypes.WEB,
            old_value=old_value,
            new_value=new_value,
            quality_check=check)
        sub.save()
开发者ID:claudep,项目名称:pootle,代码行数:31,代码来源:models.py

示例3: submit

def submit(request, unit):
    """Processes translation submissions and stores them in the database.

    :return: An object in JSON notation that contains the previous and last
             units for the unit next to unit ``uid``.
    """
    json = {}

    translation_project = request.translation_project
    language = translation_project.language

    if unit.hasplural():
        snplurals = len(unit.source.strings)
    else:
        snplurals = None

    # Store current time so that it is the same for all submissions
    current_time = timezone.now()

    form_class = unit_form_factory(language, snplurals, request)
    form = form_class(request.POST, instance=unit, request=request)

    if form.is_valid():
        if form.updated_fields:
            for field, old_value, new_value in form.updated_fields:
                sub = Submission(
                    creation_time=current_time,
                    translation_project=translation_project,
                    submitter=request.profile,
                    unit=unit,
                    store=unit.store,
                    field=field,
                    type=SubmissionTypes.NORMAL,
                    old_value=old_value,
                    new_value=new_value,
                    similarity=form.cleaned_data["similarity"],
                    mt_similarity=form.cleaned_data["mt_similarity"],
                )
                sub.save()

            # Update current unit instance's attributes
            # important to set these attributes after saving Submission
            # because we need to access the unit's state before it was saved
            if SubmissionFields.TARGET in (f[0] for f in form.updated_fields):
                form.instance.submitted_by = request.profile
                form.instance.submitted_on = current_time
                form.instance.reviewed_by = None
                form.instance.reviewed_on = None

            form.instance._log_user = request.profile

            form.save()

            json["checks"] = _get_critical_checks_snippet(request, unit)

        json["user_score"] = request.profile.public_score

        return JsonResponse(json)

    return JsonResponseBadRequest({"msg": _("Failed to process submission.")})
开发者ID:spMohanty,项目名称:pootle,代码行数:60,代码来源:views.py

示例4: toggle_qualitycheck

    def toggle_qualitycheck(self, check_id, false_positive, user):
        check = self.qualitycheck_set.get(id=check_id)

        if check.false_positive == false_positive:
            return

        check.false_positive = false_positive
        check.save()

        self._log_user = user
        if false_positive:
            self._save_action = MUTE_QUALITYCHECK
        else:
            self._save_action = UNMUTE_QUALITYCHECK

        # create submission
        if false_positive:
            sub_type = SubmissionTypes.MUTE_CHECK
        else:
            sub_type = SubmissionTypes.UNMUTE_CHECK

        sub = Submission(creation_time=make_aware(timezone.now()),
                         translation_project=self.store.translation_project,
                         submitter=user, field=SubmissionFields.NONE,
                         unit=self, store=self.store, type=sub_type,
                         quality_check=check)
        sub.save()

        # update timestamp
        # log user action
        self.save()
开发者ID:SafaAlfulaij,项目名称:pootle,代码行数:31,代码来源:models.py

示例5: do_upload

    def do_upload(self, request, translation_project, directory):
        if self.form.is_valid() and 'file' in request.FILES:
            django_file = self.form.cleaned_data['file']
            overwrite = self.form.cleaned_data['overwrite']
            scan_translation_project_files(translation_project)
            oldstats = translation_project.getquickstats()
            # The URL relative to the URL of the translation project. Thus, if
            # directory.pootle_path == /af/pootle/foo/bar, then
            # relative_root_dir == foo/bar.
            if django_file.name.endswith('.zip'):
                archive = True
                upload_archive(request, directory, django_file, overwrite)
            else:
                archive = False
                upload_file(request, directory, django_file, overwrite)
            scan_translation_project_files(translation_project)
            newstats = translation_project.getquickstats()

            # create a submission, doesn't fix stats but at least
            # shows up in last activity column
            s = Submission(creation_time=datetime.datetime.utcnow(),
                           translation_project=translation_project,
                           submitter=get_profile(request.user))
            s.save()

            post_file_upload.send(sender=translation_project, user=request.user, oldstats=oldstats,
                                  newstats=newstats, archive=archive)
        return {'upload': self}
开发者ID:mellterm,项目名称:pootle,代码行数:28,代码来源:views.py

示例6: submit

def submit(request, unit):
    """Processes translation submissions and stores them in the database.

    :return: An object in JSON notation that contains the previous and last
             units for the unit next to unit ``uid``.
    """
    json = {}

    cantranslate = check_permission("translate", request)
    if not cantranslate:
        raise PermissionDenied(_("You do not have rights to access "
                                 "translation mode."))

    translation_project = request.translation_project
    language = translation_project.language

    if unit.hasplural():
        snplurals = len(unit.source.strings)
    else:
        snplurals = None

    # Update current unit instance's attributes
    unit.submitted_by = request.profile
    unit.submitted_on = datetime.utcnow()

    form_class = unit_form_factory(language, snplurals, request)
    form = form_class(request.POST, instance=unit)

    if form.is_valid():
        if form.updated_fields:
            # Store creation time so that it is the same for all submissions
            creation_time=datetime.utcnow()
            for field, old_value, new_value in form.updated_fields:
                sub = Submission(
                        creation_time=creation_time,
                        translation_project=translation_project,
                        submitter=request.profile,
                        unit=unit,
                        field=field,
                        type=SubmissionTypes.NORMAL,
                        old_value=old_value,
                        new_value=new_value,
                )
                sub.save()

            form.save()
            translation_submitted.send(
                    sender=translation_project,
                    unit=form.instance,
                    profile=request.profile,
            )

        rcode = 200
    else:
        # Form failed
        #FIXME: we should display validation errors here
        rcode = 400
        json["msg"] = _("Failed to process submission.")
    response = jsonify(json)
    return HttpResponse(response, status=rcode, mimetype="application/json")
开发者ID:SinSiXX,项目名称:pootle,代码行数:60,代码来源:views.py

示例7: accept_suggestion

def accept_suggestion(request, unit, suggid):
    json = {
        'udbid': unit.id,
        'sugid': suggid,
    }
    translation_project = request.translation_project

    if request.POST.get('accept'):
        try:
            suggestion = unit.suggestion_set.get(id=suggid)
        except ObjectDoesNotExist:
            raise Http404

        old_target = unit.target
        success = unit.accept_suggestion(suggid)

        json['newtargets'] = [highlight_whitespace(target)
                              for target in unit.target.strings]
        json['newdiffs'] = {}
        for sugg in unit.get_suggestions():
            json['newdiffs'][sugg.id] = \
                    [highlight_diffs(unit.target.strings[i], target)
                     for i, target in enumerate(sugg.target.strings)]

        if suggestion is not None and success:
            if suggestion.user:
                translation_submitted.send(sender=translation_project,
                                           unit=unit, profile=suggestion.user)

            # FIXME: we need a totally different model for tracking stats, this
            # is just lame
            suggstat, created = SuggestionStat.objects.get_or_create(
                    translation_project=translation_project,
                    suggester=suggestion.user,
                    state='pending',
                    unit=unit.id,
            )
            suggstat.reviewer = request.profile
            suggstat.state = 'accepted'
            suggstat.save()

            # For now assume the target changed
            # TODO: check all fields for changes
            creation_time = timezone.now()
            sub = Submission(
                    creation_time=creation_time,
                    translation_project=translation_project,
                    submitter=suggestion.user,
                    from_suggestion=suggstat,
                    unit=unit,
                    field=SubmissionFields.TARGET,
                    type=SubmissionTypes.SUGG_ACCEPT,
                    old_value=old_target,
                    new_value=unit.target,
            )
            sub.save()

    response = jsonify(json)
    return HttpResponse(response, mimetype="application/json")
开发者ID:darkdreamingdan,项目名称:pootle,代码行数:59,代码来源:views.py

示例8: process_submit

def process_submit(request, unit, type):
    """
    Processes submissions and suggestions and stores them in the database.

    @return: An object in JSON notation that contains the previous
    and last units for the unit next to unit C{uid}.
    """
    json = {}
    cantranslate = check_permission("translate", request)
    cansuggest = check_permission("suggest", request)
    if type == "submission" and not cantranslate or type == "suggestion" and not cansuggest:
        raise PermissionDenied(_("You do not have rights to access translation mode."))

    translation_project = request.translation_project
    language = translation_project.language

    if unit.hasplural():
        snplurals = len(unit.source.strings)
    else:
        snplurals = None

    form_class = unit_form_factory(language, snplurals, request)
    form = form_class(request.POST, instance=unit)

    if form.is_valid():
        if type == "submission":
            if (
                form.instance._target_updated
                or form.instance._translator_comment_updated
                or form.instance._state_updated
            ):
                form.save()
                translation_submitted.send(sender=translation_project, unit=form.instance, profile=request.profile)

                sub = Submission(translation_project=translation_project, submitter=request.profile)
                sub.save()
        elif type == "suggestion":
            if form.instance._target_updated:
                # HACKISH: django 1.2 stupidly modifies instance on
                # model form validation, reload unit from db
                unit = Unit.objects.get(id=unit.id)
                sugg = unit.add_suggestion(form.cleaned_data["target_f"], request.profile)
                if sugg:
                    SuggestionStat.objects.get_or_create(
                        translation_project=translation_project,
                        suggester=request.profile,
                        state="pending",
                        unit=unit.id,
                    )
        rcode = 200
    else:
        # Form failed
        # FIXME: we should display validation errors here
        rcode = 400
        json["msg"] = _("Failed to process submit.")
    response = jsonify(json)
    return HttpResponse(response, status=rcode, mimetype="application/json")
开发者ID:julen,项目名称:pootle,代码行数:57,代码来源:views.py

示例9: _handle_upload_form

def _handle_upload_form(request, translation_project):
    """Process the upload form in TP overview."""
    from pootle_app.signals import post_file_upload

    upload_form_class = upload_form_factory(request)

    if request.method == 'POST' and 'file' in request.FILES:
        upload_form = upload_form_class(request.POST, request.FILES)

        if not upload_form.is_valid():
            return upload_form
        else:
            django_file = upload_form.cleaned_data['file']
            overwrite = upload_form.cleaned_data['overwrite']
            upload_to = upload_form.cleaned_data['upload_to']
            upload_to_dir = upload_form.cleaned_data['upload_to_dir']

            # XXX Why do we scan here?
            translation_project.scan_files(vcs_sync=False)
            oldstats = translation_project.get_stats()

            # The URL relative to the URL of the translation project. Thus, if
            # directory.pootle_path == /af/pootle/foo/bar, then
            # relative_root_dir == foo/bar.
            if django_file.name.endswith('.zip'):
                archive = True
                target_directory = upload_to_dir or request.directory
                upload_archive(request, target_directory, django_file,
                               overwrite)
            else:
                archive = False
                upload_file(request, request.directory, django_file, overwrite,
                            store=upload_to)

            translation_project.scan_files(vcs_sync=False)
            newstats = translation_project.get_stats()

            # Create a submission. Doesn't fix stats but at least shows up in
            # last activity column.
            from django.utils import timezone
            s = Submission(
                creation_time=timezone.now(),
                translation_project=translation_project,
                submitter=request.user,
                type=SubmissionTypes.UPLOAD,
                # The other fields are only relevant to unit-based changes.
            )
            s.save()

            post_file_upload.send(sender=translation_project,
                                  user=request.user, oldstats=oldstats,
                                  newstats=newstats, archive=archive)

    # Always return a blank upload form unless the upload form is not valid.
    return upload_form_class()
开发者ID:alain-andre,项目名称:pootle,代码行数:55,代码来源:views.py

示例10: _create_comment_submission

def _create_comment_submission(unit, user, creation_time, comment):
    sub = Submission(
        creation_time=creation_time,
        translation_project=unit.store.translation_project,
        submitter=user,
        unit=unit,
        field=SubmissionFields.COMMENT,
        type=SubmissionTypes.WEB,
        new_value=comment,
    )
    sub.save()
    return sub
开发者ID:claudep,项目名称:pootle,代码行数:12,代码来源:submission.py

示例11: accept_suggestion

def accept_suggestion(request, uid, suggid):
    unit = get_object_or_404(Unit, id=uid)
    directory = unit.store.parent
    translation_project = unit.store.translation_project

    if not check_profile_permission(
        get_profile(request.user), 'review', directory):
        raise PermissionDenied

    response = {
        'udbid': unit.id,
        'sugid': suggid,
        }

    if request.POST.get('accept'):
        try:
            suggestion = unit.suggestion_set.get(id=suggid)
        except ObjectDoesNotExist:
            suggestion = None

        response['success'] = unit.accept_suggestion(suggid)
        response['newtargets'] = [
            highlight_whitespace(target) for target in unit.target.strings]
        response['newdiffs'] = {}
        for sugg in unit.get_suggestions():
            response['newdiffs'][sugg.id] = [
                highlight_diffs(unit.target.strings[i], target) \
                for i, target in enumerate(sugg.target.strings)]

        if suggestion is not None and response['success']:
            if suggestion.user:
                translation_submitted.send(
                    sender=translation_project, unit=unit,
                    profile=suggestion.user)
            # FIXME: we need a totally different model for tracking
            # stats, this is just lame
            suggstat, created = SuggestionStat.objects.get_or_create(
                translation_project=translation_project,
                suggester=suggestion.user,
                state='pending',
                unit=unit.id)
            suggstat.reviewer = get_profile(request.user)
            suggstat.state = 'accepted'
            suggstat.save()

            sub = Submission(translation_project=translation_project,
                             submitter=get_profile(request.user),
                             from_suggestion=suggstat)
            sub.save()

    response = simplejson.dumps(response)
    return HttpResponse(response, mimetype="application/json")
开发者ID:itsjeyd,项目名称:wikitrans-pootle,代码行数:52,代码来源:views.py

示例12: accept_suggestion

def accept_suggestion(request, uid, suggid):
    json = {}
    try:
        unit = Unit.objects.get(id=uid)
        directory = unit.store.parent
        translation_project = unit.store.translation_project
        profile = get_profile(request.user)

        if not check_profile_permission(profile, 'review', directory):
            json["success"] = False
            json["msg"] = _("You do not have rights to access review mode.")
        else:
            json["udbid"] = unit.id
            json["sugid"] = suggid
            if request.POST.get('accept'):
                try:
                    sugg = unit.suggestion_set.get(id=suggid)
                except ObjectDoesNotExist:
                    sugg = None

                json['success'] = unit.accept_suggestion(suggid)
                json['newtargets'] = [highlight_whitespace(target) for target in unit.target.strings]
                json['newdiffs'] = {}
                for sugg in unit.get_suggestions():
                    json['newdiffs'][sugg.id] = [highlight_diffs(unit.target.strings[i], target) \
                                                     for i, target in enumerate(sugg.target.strings)]

                if sugg is not None and json['success']:
                    #FIXME: we need a totally different model for tracking stats, this is just lame
                    suggstat, created = SuggestionStat.objects.get_or_create(translation_project=translation_project,
                                                                    suggester=sugg.user,
                                                                    state='pending',
                                                                    unit=unit.id)
                    suggstat.reviewer = profile
                    suggstat.state = 'accepted'
                    suggstat.save()

                    sub = Submission(translation_project=translation_project,
                                     submitter=profile,
                                     from_suggestion=suggstat)
                    sub.save()
    except Unit.DoesNotExist:
        json["success"] = False
        json["msg"] = _("Unit %(uid)s does not exist." %
                        {'uid': uid})

    response = simplejson.dumps(json)
    return HttpResponse(response, mimetype="application/json")
开发者ID:sabinehunsicker,项目名称:wikitrans-pootle,代码行数:48,代码来源:views.py

示例13: _create_comment_on_unit

def _create_comment_on_unit(unit, user, comment):
    from pootle_statistics.models import (Submission, SubmissionFields,
                                          SubmissionTypes)

    unit.translator_comment = comment
    unit.save(user=user)
    sub = Submission(
        creation_time=unit.change.commented_on,
        translation_project=unit.store.translation_project,
        submitter=user,
        unit=unit,
        field=SubmissionFields.COMMENT,
        type=SubmissionTypes.WEB,
        new_value=comment,
    )
    sub.save()
开发者ID:ta2-1,项目名称:pootle,代码行数:16,代码来源:store.py

示例14: _mark_unit_fuzzy

def _mark_unit_fuzzy(unit, user):
    from pootle_store.constants import FUZZY
    from pootle_statistics.models import (Submission, SubmissionFields,
                                          SubmissionTypes)
    unit.markfuzzy()
    unit.save()
    sub = Submission(
        creation_time=unit.mtime,
        translation_project=unit.store.translation_project,
        submitter=user,
        unit=unit,
        field=SubmissionFields.STATE,
        type=SubmissionTypes.WEB,
        old_value=unit.state,
        new_value=FUZZY,
    )
    sub.save()
开发者ID:ta2-1,项目名称:pootle,代码行数:17,代码来源:store.py

示例15: GET

    def GET(self, template_vars, request, translation_project, directory,
            store=None):
        can_edit = check_permission('administrate', request)

        project = translation_project.project
        language = translation_project.language

        path_obj = store or directory

        path_stats = get_raw_stats(path_obj, include_suggestions=True)
        path_summary = get_path_summary(path_obj, path_stats)
        actions = action_groups(request, path_obj, path_stats=path_stats)

        template_vars.update({
            'translation_project': translation_project,
            'project': project,
            'language': language,
            'directory': directory,
            'path_summary': path_summary,
            'stats': path_stats,
            'topstats': gentopstats_translation_project(translation_project),
            'feed_path': directory.pootle_path[1:],
            'action_groups': actions,
            'can_edit': can_edit,
        })

        if store is not None:
            template_vars.update({
                'store': store
            })
        else:
            table_fields = ['name', 'progress', 'total', 'need-translation',
                            'suggestions']
            template_vars.update({
                'table': {
                    'id': 'tp',
                    'proportional': True,
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'items': get_children(translation_project, directory),
                }
            })

            # If current directory is the TP root directory.
            if not directory.path:
                template_vars.update({
                    'latest_action': translation_project.get_latest_submission()
                })
            else:
                template_vars.update({
                    'latest_action': Submission.get_latest_for_dir(path_obj)
                })

        if can_edit:
            from pootle_translationproject.forms import DescriptionForm
            template_vars['form'] = DescriptionForm(instance=translation_project)

        return template_vars
开发者ID:denji,项目名称:pootle,代码行数:58,代码来源:views.py


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