def toggle_mark(request, slug): res = {} if request.method == "POST": try: file = POFile.objects.get(slug=slug) except: return XMLResponse({'message': _('File not found.')}) if not file.release.enabled or not file.release.project.enabled: return XMLResponse({'message': _('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): return XMLResponse({'message': _('You are not a member of this team.')}) res['id'] = file.slug if file.assigns.all(): assign = file.assigns.get() else: assign = False if (team.can_manage(request.user) or (assign and (assign.translate==request.user or assign.review==request.user))): # to avoid mark collision current_mark = request.POST.get('mark') if current_mark != None and current_mark != '' and int(current_mark) == file.status: st = None if file.status == 0: file.status = 1 st = 'ST_TRAN' elif file.status == 1: file.status = 2 st = 'ST_REV' elif file.status == 2: file.status = 3 st = 'ST_COMPL' if st: file.save() file.log.create(action=LOG_ACTION[st],user=request.user) if file.status == 1: if assign and assign.review: set_user_language(assign.review) send_pm(assign.review, subject=_("File %s ready for review.") % smart_unicode(file)) else: return XMLResponse({'message': _('You are not authorized to perform this action.')}) page = render_to_string('files/file_list_row.html', {'pofile': file, 'team': team}, context_instance = RequestContext(request)) res['content_HTML'] = page return XMLResponse(res) else: raise Http403
def check_notification(self, pofile_new, pofile_old, add_coord = True): try: new_sum = pofile_new.fuzzy + pofile_new.untrans actual_sum = pofile_old.fuzzy + pofile_old.untrans if new_sum > actual_sum: self.add_notification(pofile_new, add_coord) pofile_new.log.create(user=self.user, action=LOG_ACTION['ACT_UPDATE']) if new_sum > 0 and pofile_new.status > 0: pofile_new.status = 0 pofile_new.log.create(user=self.user, action=LOG_ACTION['ST_UNREV']) elif new_sum == 0 and pofile_new.status < 2: # lets try to guess the status if pofile_new.assigns.all(): assign = pofile_new.assigns.get() if pofile_new.status == 0: if assign.translate: if POFileLog.objects.filter( user=assign.translate, pofile=pofile_new,action=LOG_ACTION['ACT_UPLOAD']).count()>0: pofile_new.status = 1 pofile_new.log.create(user=self.user, action=LOG_ACTION['ST_TRAN']) if assign.review: set_user_language(assign.review) send_pm(assign.review, subject=_("File %s ready for review.") % smart_unicode(pofile_new)) elif pofile_new.status == 1: if assign.review: if POFileLog.objects.filter( user=assign.review, pofile=pofile_new,action=LOG_ACTION['ACT_UPLOAD']).count()>0: pofile_new.status = 2 pofile_new.log.create(user=self.user, action=LOG_ACTION['ST_REV']) except Exception, e: if self.logger: self.logger.error(e)
def confirm_submit(request): if request.method != 'POST': raise Http403 if request.POST.has_key('reject') and request.POST.get('reject')=='True': reject = True; else: reject = False if request.POST.has_key('needuser') and request.POST.get('needuser')=='False': needuser = False; else: needuser = True if reject: form = RejectSubmitForm(request.POST) else: if needuser: form = HttpCredForm(request.POST) else: form = CommentForm(request.POST) fileSet = get_object_or_404(POFileSubmitSet, pk=request.POST.get('file')) if not form.is_valid(): # files = [] # for fid in request.POST.getlist('file'): # try: # sfile = POFileSubmit.objects.get(pk=fid) # files.append(sfile) # except: # pass messages.warning(request, message=_("Complete the form and try again.")) return render_to_response("files/file_submit_confirm.html", {'files': fileSet, 'back': request.POST['back'], 'form': form, 'reject': reject}, context_instance = RequestContext(request)) files = [] for submfile in fileSet.files.all(): if reject: send_pm(submfile.owner, _("Submit rejected"), message=_("The file %(file)s (%(project)s) was rejected by %(user)s [%(comment)s]") % {'file': submfile.pofile.filename, 'user': request.user.username, 'project': submfile.pofile.release.project.name, 'comment': form.cleaned_data.get('message')},) POFileLog.objects.create(pofile=submfile.pofile, user=request.user, action='X', comment=form.cleaned_data.get('message')) submfile.status = SUBMIT_STATUS_ENUM.REJECTED submfile.save() else: files.append(submfile) # for fid in request.POST.getlist('file'): # try: # submfile = POFileSubmit.objects.get(pk=fid) # if reject: # send_pm(submfile.owner, _("Submit rejected"), message=_("The file %(file)s (%(project)s) was rejected by %(user)s [%(comment)s]") % # {'file': submfile.pofile.filename, # 'user': request.user.username, # 'project': submfile.pofile.release.project.name, # 'comment': form.cleaned_data.get('message')},) # POFileLog.objects.create(pofile=submfile.pofile, # user=request.user, action='X', # comment=form.cleaned_data.get('message')) # submfile.status = SUBMIT_STATUS_ENUM.REJECTED # submfile.save() # else: # files.append(submfile) # except: # pass if reject: messages.info(request, message=_("The files were rejected.")) if len(files)>0: if needuser: puser = form.cleaned_data.get('user') ppass = form.cleaned_data.get('password') else: p = get_object_or_404(Project,pk=request.POST.get('p')) puser = p.repo_user ppass = p.get_repo_pwd() do_commit(request, files, request.user, puser, ppass, form.cleaned_data.get('message')) fileSet.delete() return HttpResponseRedirect(request.POST['back'])
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
def private_message(self, subject, message): send_pm(self, subject, message)
# # create a lock for console # lockfile = logfile + ".lock" # open(lockfile).close() # # the components will remain locked for all the process locks = [] try: for component in project.components.all(): canbuild = True rev = None try: b = BuildCache.objects.get(component=component, release=release) if b.is_locked: canbuild = False send_pm(user, subject=_('Component %s is locked at this moment.') % component.name) logger.debug('Component %s is locked.' % component.name) else: b.lock() except BuildCache.DoesNotExist: b = BuildCache.objects.create(component=component, release=release) b.lock() except Exception, e: send_pm(user, _("Build error"), str(e)) logger.error(e) raise if canbuild: locks.append(b) for team in project.teams.all():