def post(self, request): if 'package' not in request.POST: raise Http404 package = request.POST['package'] user = request.user if 'email' not in request.POST: # Unsubscribe all the user's emails from the package qs = Subscription.objects.filter( email_settings__user_email__in=UserEmail.objects.filter(user=user), package__name=package) else: # Unsubscribe only the given email from the package qs = Subscription.objects.filter( email_settings__user_email__email=request.POST['email'], package__name=package) qs.delete() if request.is_ajax(): return render_to_json_response({ 'status': 'ok', }) else: if 'next' in request.POST: return redirect(request.POST['next']) else: return redirect('dtracker-package-page', package_name=package)
def render_response(self): if self.request.is_ajax(): return render_to_json_response({ 'status': 'ok', }) _next = self.request.POST.get('next', None) return safe_redirect(_next, self.team)
def post(self, request): package = request.POST.get('package', None) emails = request.POST.getlist('email', None) if not package or not emails: raise Http404 # Check whether the logged in user is associated with the given emails users_emails = [e.email for e in request.user.emails.all()] for email in emails: if email not in users_emails: return HttpResponseForbidden() # Create the subscriptions for email in emails: Subscription.objects.create_for( package_name=package, email=email) if request.is_ajax(): return render_to_json_response({ 'status': 'ok', }) else: next = request.POST.get('next', None) if not next: return redirect('dtracker-package-page', package_name=package) return redirect(next)
def get(self, request): if 'q' not in request.GET: raise Http404 query_string = request.GET['q'] package_type = request.GET.get('package_type', None) MANAGERS = { 'pseudo': PseudoPackageName.objects, 'source': SourcePackageName.objects, 'binary': BinaryPackageName.objects, } # When no package type is given include both pseudo and source packages filtered = MANAGERS.get( package_type, PackageName.objects.exclude( source=False, binary=False, pseudo=False) ) filtered = filtered.filter(name__istartswith=query_string) # Extract only the name of the package. filtered = filtered.values('name') # Limit the number of packages returned from the autocomplete AUTOCOMPLETE_ITEMS_LIMIT = 10 filtered = filtered[:AUTOCOMPLETE_ITEMS_LIMIT] return render_to_json_response([query_string, [package['name'] for package in filtered]])
def render_response(self): if self.request.is_ajax(): return render_to_json_response({ 'status': 'ok', }) if 'next' in self.request.POST: return redirect(self.request.POST['next']) else: return redirect(self.team)
def render_response(self): if self.request.is_ajax(): return render_to_json_response({ 'status': 'ok', }) else: if 'next' in request.POST: return redirect(request.POST['next']) else: return redirect('dtracker-index')
def render_response(self): if self.request.is_ajax(): return render_to_json_response({ 'status': 'ok', }) else: _next = self.request.POST.get('next', None) return safe_redirect( _next, resolve_url('dtracker-index'), )
def post(self, request): package = request.POST.get('package', None) emails = request.POST.getlist('email', None) if not package or not emails: raise Http404 # Remember selected emails via session variable request.session['selected_emails'] = emails # Check whether the logged in user is associated with the given emails users_emails = [e.email for e in request.user.emails.all()] for email in emails: if email not in users_emails: return HttpResponseForbidden() _pkg = get_web_package(package) _err = None if _pkg: try: for email in emails: Subscription.objects.create_for( package_name=package, email=email) except ValidationError as e: _err = e.message else: _err = format_html( "Package {pkg} does not exist.", pkg=package, ) if request.is_ajax(): json_result = {'status': 'ok'} if _err is not None: json_result = { 'status': 'failed', 'error': _err, } return render_to_json_response(json_result) else: if _err: return HttpResponseBadRequest(_err) _next = request.POST.get('next', None) return safe_redirect( _next, resolve_url('dtracker-package-page', package_name=package), )
def get(self, request): if 'q' not in request.GET: raise Http404 query_string = request.GET['q'] filtered = Team.objects.filter( Q(name__icontains=query_string) | Q(slug__icontains=query_string)) # Extract only the name and slug of the team. filtered = filtered.values('name', 'slug') # Limit the number of teams returned from the autocomplete AUTOCOMPLETE_ITEMS_LIMIT = 100 filtered = filtered[:AUTOCOMPLETE_ITEMS_LIMIT] return render_to_json_response({ 'query_string': query_string, 'teams': list(filtered) })
def post(self, request): user = request.user if 'email' not in request.POST: emails = user.emails.all() else: emails = user.emails.filter(email__in=request.POST.getlist('email')) # Remove all the subscriptions Subscription.objects.filter(email_settings__user_email__in=emails).delete() if request.is_ajax(): return render_to_json_response({ 'status': 'ok', }) else: if 'next' in request.POST: return redirect(request.POST['next']) else: return redirect('dtracker-index')
def post(self, request): package = request.POST.get('package', None) emails = request.POST.getlist('email', None) if not package or not emails: raise Http404 # Remember selected emails via session variable request.session['selected_emails'] = emails # Check whether the logged in user is associated with the given emails users_emails = [e.email for e in request.user.emails.all()] for email in emails: if email not in users_emails: return HttpResponseForbidden() # Create the subscriptions json_result = {'status': 'ok'} try: for email in emails: Subscription.objects.create_for( package_name=package, email=email) except ValidationError as e: json_result['status'] = 'failed' json_result['error'] = e.message if request.is_ajax(): return render_to_json_response(json_result) else: if 'error' in json_result: return HttpResponseBadRequest(json_result['error']) next = request.POST.get('next', None) if not next: return redirect('dtracker-package-page', package_name=package) return redirect(next)
def get(self, request): user = request.user return render_to_json_response([ email.email for email in user.emails.all() ])
def get(self, request): return render_to_json_response([ keyword.name for keyword in Keyword.objects.order_by('name').all() ])
def get(self, request, item_pk): item = get_object_or_404(ActionItem, pk=item_pk) return render_to_json_response(item.to_dict())