def project_hub_projects_toggler(request, project_slug): project = get_object_or_404(Project, slug=project_slug) url = reverse('project_hub_projects_toggler', args=(project_slug, )) if request.method != 'POST': return json_error(_('Must use POST to activate')) # POST request must have a 'outsourced_project_slug' parameter outsourced_project_slug = request.POST.get('outsourced_project_slug', None) if not outsourced_project_slug: return json_error(_('Bad request.')) try: outsourced_project = project.outsourcing.get( slug=outsourced_project_slug) outsourced_project.outsource = None outsourced_project.save() ## ActionLog & Notification #nt = 'project_hub_added' #context = {'team': team, #'sender': request.user} ## Logging action #action_logging(request.user, [project, team], nt, context=context) #if settings.ENABLE_NOTICES: ## Send notification for those that are observing this project #txnotification.send_observation_notices_for(project, #signal=nt, extra_context=context) ## Send notification for maintainers and coordinators #notification.send(set(itertools.chain(project.maintainers.all(), #team.coordinators.all())), nt, context) result = { 'style': 'undo', 'title': _('Undo'), 'outsourced_project_slug': outsourced_project_slug, 'url': url, 'error': None, } except Project.DoesNotExist: outsourced_project = get_object_or_404(Project, slug=outsourced_project_slug) outsourced_project.outsource = project outsourced_project.save() result = { 'style': 'connect', 'title': _('Disassociate'), 'outsourced_project_slug': outsourced_project_slug, 'url': url, 'error': None, } except Exception, e: return json_error(e.message, result)
def project_hub_projects_toggler(request, project_slug): project = get_object_or_404(Project, slug=project_slug) url = reverse('project_hub_projects_toggler', args=(project_slug,)) if request.method != 'POST': return json_error(_('Must use POST to activate')) # POST request must have a 'outsourced_project_slug' parameter outsourced_project_slug = request.POST.get('outsourced_project_slug', None) if not outsourced_project_slug: return json_error(_('Bad request.')) try: outsourced_project = project.outsourcing.get(slug=outsourced_project_slug) outsourced_project.outsource = None outsourced_project.save() ## ActionLog & Notification #nt = 'project_hub_added' #context = {'team': team, #'sender': request.user} ## Logging action #action_logging(request.user, [project, team], nt, context=context) #if settings.ENABLE_NOTICES: ## Send notification for those that are observing this project #txnotification.send_observation_notices_for(project, #signal=nt, extra_context=context) ## Send notification for maintainers and coordinators #notification.send(set(itertools.chain(project.maintainers.all(), #team.coordinators.all())), nt, context) result = { 'style': 'undo', 'title': _('Undo'), 'outsourced_project_slug': outsourced_project_slug, 'url': url, 'error': None, } except Project.DoesNotExist: outsourced_project = get_object_or_404(Project, slug=outsourced_project_slug) outsourced_project.outsource = project outsourced_project.save() result = { 'style': 'connect', 'title': _('Disassociate'), 'outsourced_project_slug': outsourced_project_slug, 'url': url, 'error': None, } except Exception, e: return json_error(e.message, result)
def project_toggle_watch(request, project_slug): """Add/Remove watches on a project for a specific user.""" if request.method != 'POST': return json_error(_('Must use POST to activate')) if not settings.ENABLE_NOTICES: return json_error(_('Notification is not enabled')) project = get_object_or_404(Project, slug=project_slug) url = reverse('project_toggle_watch', args=(project_slug,)) project_signals = ['project_changed', 'project_deleted', 'project_release_added', 'project_release_deleted', 'project_resource_added', 'project_resource_deleted'] release_signals = ['project_release_changed',] resource_signals = ['project_resource_changed'] try: result = { 'style': 'watch_add', 'title': _('Watch this project'), 'project': True, 'url': url, 'error': None, } for signal in project_signals: try: notification.stop_observing(project, request.user, signal) except notification.ObservedItem.MultipleObjectsReturned, e: notification.ObservedItem.objects.filter(user=request.user, signal=signal, content_type__model='project', object_id = project.id).delete() for release in project.releases.all(): for signal in release_signals: try: notification.stop_observing(release, request.user, signal) except notification.ObservedItem.MultipleObjectsReturned, e: notification.ObservedItem.objects.filter(user=request.user, signal=signal, content_type__model='release', object_id = release.id).delete()
def project_toggle_watch(request, project_slug): """Add/Remove watches on a project for a specific user.""" if request.method != 'POST': return json_error(_('Must use POST to activate')) if not settings.ENABLE_NOTICES: return json_error(_('Notification is not enabled')) project = get_object_or_404(Project, slug=project_slug) url = reverse('project_toggle_watch', args=(project_slug,)) project_signals = ['project_changed', 'project_deleted',] try: result = { 'style': 'watch_add', 'title': _('Watch this project'), 'project': True, 'url': url, 'error': None, } for signal in project_signals: notification.stop_observing(project, request.user, signal) except notification.ObservedItem.DoesNotExist: try: result = { 'style': 'watch_remove', 'title': _('Stop watching this project'), 'project': True, 'url': url, 'error': None, } for signal in project_signals: notification.observe(project, request.user, signal, signal) except WatchException, e: return json_error(e.message, result)
def resource_translation_toggle_watch(request, project_slug, resource_slug, language_code): """Add/Remove a TranslationWatch for a specific user.""" if request.method != 'POST': return json_error(_('Must use POST to activate')) if not settings.ENABLE_NOTICES: return json_error(_('Notification is not enabled')) resource = get_object_or_404(Resource, slug=resource_slug, project__slug=project_slug) project = resource.project language = get_object_or_404(Language, code=language_code) team = Team.objects.get_or_none(project, language_code) check = ProjectPermission(request.user) if not check.submit_translations(team or project) and not \ check.maintain(project) and not \ request.user.has_perm('watches.add_translationwatch') and not \ request.user.has_perm('watches.delete_translationwatch'): return permission_denied(request) url = reverse('resource_translation_toggle_watch', args=(project_slug, resource_slug, language_code)) try: twatch = TranslationWatch.objects.get(resource=resource, language=language) result = { 'style': 'watch_add', 'title': _('Watch it'), 'id': twatch.id, 'url': url, 'error': None, } notification.stop_observing(twatch, request.user, signal='project_resource_translation_changed') except (TranslationWatch.DoesNotExist, notification.ObservedItem.DoesNotExist): try: twatch = TranslationWatch.objects.get_or_create(resource=resource, language=language)[0] result = { 'style': 'watch_remove', 'title': _('Stop watching'), 'id': twatch.id, 'url': url, 'error': None, } notification.observe(twatch, request.user, 'project_resource_translation_changed', signal='project_resource_translation_changed') except WatchException, e: return json_error(e.message, result)
for signal in resource_signals: try: notification.stop_observing(resource, request.user, signal) except notification.ObservedItem.MultipleObjectsReturned, e: notification.ObservedItem.objects.filter(user=request.user, signal=signal, content_type__model='resource', object_id=resource.id).delete() except notification.ObservedItem.DoesNotExist: try: result = { 'style': 'watch_remove', 'title': _('Stop watching this project'), 'project': True, 'url': url, 'error': None, } for signal in project_signals: notification.observe(project, request.user, signal, signal) for release in project.releases.all(): for signal in release_signals: notification.observe(release, request.user, signal, signal) for resource in project.resources.all(): for signal in resource_signals: notification.observe(resource, request.user, signal, signal) except WatchException, e: return json_error(e.message, result) return json_result(result)