Exemplo n.º 1
0
def release_populate(request, slug):
    release = get_object_or_404(Release, slug=slug)

    if (not release.project.is_maintainer(request.user) and
         request.user.team_coordinator.filter(project=release.project).count()==0):
        raise Http403
    
    back = HttpResponseRedirect(reverse('release_detail', kwargs={'slug':slug}))
    if request.method == 'POST':
        release_from = get_object_or_404(Release, pk=request.POST.get('copy_from'))
        for lang_id in request.POST.getlist('language_id'):
            for pofile in POFile.objects.filter(release=release_from,language__id=lang_id, assigns__isnull=False):
                try:
                    to_pofile = POFile.objects.get(release=release,
                                                      component=pofile.component,
                                                      language=pofile.language,
                                                      filename=pofile.filename,
                                                      assigns__isnull=True)
                except:
                    logger.debug("Skipped file %s" % smart_unicode(pofile))
                else:
                    assign = pofile.assigns.get()
                    asg = POFileAssign(pofile=to_pofile)
                    if assign.translate and assign.translate.is_active:
                        asg.translate = assign.translate
                    if assign.review and assign.review.is_active:
                        asg.review = assign.review
                    asg.save()
        messages.success(request, _('Success.'))
        return back
    else:
        releases = Release.objects.filter(project=release.project).exclude(pk=release.pk)
        if releases.count() == 0:
            messages.warning(request, _('There are no available releases to populate from.'))
            return back
        if release.project.is_maintainer(request.user):
            languages = [team.language for team in Team.objects.filter(project=release.project)]
        else:
            languages = [team.language for team in request.user.team_coordinator.filter(project=release.project)]
        return render_to_response('releases/release_populate.html',
                                {'release': release,
                                 'releases': releases,
                                 'languages': languages},
                                 context_instance = RequestContext(request))
Exemplo n.º 2
0
def toggle_assigned(request, slug, translator=False, remove=False, template='files/file_list_row.html'):
    res = {}
    if request.method == "POST":
        try:
            file = POFile.objects.get(slug=slug)
        except:
            return XMLResponse({'message': ResponseMessage.error(_('File not found.'))})
        
        if not file.release.enabled or not file.release.project.enabled:
            return XMLResponse({'message': ResponseMessage.error(_('Sorry, you are not supposed to change anything on a disabled component.'))})

        team = Team.objects.get(project=file.component.project, language=file.language)
        if not team.is_member(request.user) and not request.user.is_superuser:
            return XMLResponse({'message': ResponseMessage.error(_('You are not a member of this team.'))})
        can_manage = team.can_manage(request.user)
        
        res['id'] = file.slug
        cmt = ''
        act = None
        if remove:
            if file.assigns.all():
                assign = file.assigns.get()
            if assign:
                if translator:
                    auser = assign.translate
                    if auser:
                        if can_manage or auser == request.user:
                            if file.submits.all_pending() and file.submits.get_pending().owner == auser:
                                return XMLResponse({'message': ResponseMessage.error(_('%s has a pending submit. Cannot be released right now.') % file.filename)})
                            else:
                                assign.translate = None
                                if auser != request.user:
                                    cmt = _('Removed %s') % auser.username
                                res['message'] = ResponseMessage.success(_('%s translator removed.') % file.filename)
                                act=LOG_ACTION['RE_TRA']
                        else:
                            return XMLResponse({'message': ResponseMessage.error(_('You are not authorized to perform this action.'))})
                else:
                    auser = assign.review
                    if auser:
                        if can_manage or auser == request.user:
                            if file.submits.all_pending() and file.submits.get_pending().owner == auser:
                                return XMLResponse({'message': ResponseMessage.error(_('%s has a pending submit. Cannot be released right now.') % file.filename)})
                            else:
                                assign.review = None
                                if auser != request.user:
                                    cmt = _('Removed %s') % auser.username
                                res['message'] = ResponseMessage.success(_('%s reviewer removed.') % file.filename)                            
                                act=LOG_ACTION['RE_REV']
                        else:
                            return XMLResponse({'message': ResponseMessage.error(_('You are not authorized to perform this action.'))})
                if file.locked:
                    if file.locks.get().owner == auser:
                        file.locks.get().delete()
                        POFileLog.objects.create(pofile=file, user=request.user, action=LOG_ACTION['ACT_LOCK_DEL'])
                if act:
                    log = POFileLog.objects.create(pofile=file, user=request.user, action=act, comment=cmt)                        
                    assign.save()
        else:
            if request.POST.has_key('userid'):
                userid = request.POST.get('userid')
            else:
                userid = None
            if file.assigns.all():
                assign = file.assigns.get()
            else:
                #assign = file.assigns.create()
                assign = POFileAssign(pofile=file)
            if translator:
                if assign.translate:
                    return XMLResponse({'message': ResponseMessage.error(_('%s already has an assigned translator.') % file.filename)})
                
                if not can_manage or not userid:
                    assign.translate = request.user 
                else:
                    assign.translate = User.objects.get(id=userid)
                    if assign.translate != request.user:
                        send_pm(assign.translate, _('File assigned'), _('You had been designated as translator of %(file)s') % {'file': smart_unicode(file)})
                    res['message'] = ResponseMessage.success(_('Translator set for %s.') % file.filename)
                if assign.translate != request.user:
                    cmt = _('Assigned to %s') % assign.translate.username                
                act=LOG_ACTION['AS_TRA']
                    
            else:
                if assign.review:
                    return XMLResponse({'message': ResponseMessage.error(_('%s already has an assigned reviewer.') % file.filename)})
                
                if not can_manage or not userid:
                    assign.review = request.user 
                else:
                    assign.review = User.objects.get(id=userid)
                    if assign.review != request.user:
                        send_pm(assign.review, _('File assigned'), _('You had been designated as reviewer of %(file)s') % {'file':smart_unicode(file)})
                    res['message'] = ResponseMessage.success(_('Reviewer set for %s.') % file.filename)
                if assign.review != request.user:
                    cmt = _('Assigned to %s') % assign.review.username                
                act=LOG_ACTION['AS_REV']
                
            if assign.translate == assign.review:
                return XMLResponse({'message': ResponseMessage.error(_('Sorry, the translator and the reviewer cannot be the same user.'))})
            
            POFileLog.objects.create(pofile=file, user=request.user, action=act, comment=cmt)
            assign.save()
            
        page = render_to_string(template,
                                {'pofile': file, 'team': team},
                                context_instance = RequestContext(request))
        res['content_HTML'] = page
        return XMLResponse(res)
    else:
        raise Http403