def clear_recent(request): if not request.is_ajax() or not request.method == 'POST': return error404(request) del request.session['recent_alerts'] response_html = render_to_string('alerts/cleared.html', context_instance=RequestContext(request)) return json_response(request, json={'html': response_html})
def clear_recent(request): if not request.is_ajax() or not request.method == 'POST': return error404(request) try: del request.session['recent_alerts'] except KeyError: pass response_html = render_to_string('alerts/cleared.html', context_instance=RequestContext(request)) return json_response(request, json={'html': response_html})
def error_banned(request, user=None, ban=None): if not ban: ban = request.ban if request.is_ajax(): return json_response(request, status=403, message=_("You are banned.")) response = render_to_response('error403_banned.html', { 'banned_user': user, 'ban': ban, 'hide_signin': True, 'exception_response': True, }, context_instance=RequestContext(request)); response.status_code = 403 return response
def error_view(request, error, message=None): if message: message = unicode(message) if request.is_ajax(): if not message: if error == 404: message = _("Requested page could not be loaded.") if error == 403: message = _("You don't have permission to see requested page.") return json_response(request, status=error, message=message) response = render_to_response(('error%s.html' % error), { 'message': message, 'hide_signin': True, 'exception_response': True, }, context_instance=RequestContext(request)) response.status_code = error return response
def error_view(request, error, message=None): if message: message = unicode(message) if request.is_ajax(): if not message: if error == 404: message = _("Requested page could not be loaded.") if error == 403: message = _("You don't have permission to see requested page.") return json_response(request, status=error, message=message) response = render_to_response(('error%s.html' % error), { 'message': message, 'hide_signin': True, 'exception_response': True, }, context_instance=RequestContext(request)); response.status_code = error return response
def alerts(request): if request.is_ajax(): if request.session.get('recent_alerts'): alerts_qs = request.user.alert_set.filter(date__gte=request.session['recent_alerts']).order_by('-id') else: alerts_qs = () response_html = render_to_string('alerts/modal.html', {'alerts': alerts_qs}, context_instance=RequestContext(request)) if request.user.alerts: request.user.alerts = 0 request.user.alerts_date = timezone.now() request.user.save(force_update=True) return json_response(request, json={'html': response_html}) if not request.user.alerts_date: request.user.alerts_date = request.user.join_date now = localtime(timezone.now()) yesterday = now - timedelta(days=1) alerts = {} for alert in request.user.alert_set.order_by('-id'): alert.new = alert.date > request.user.alerts_date alert_date = localtime(deepcopy(alert.date)) diff = now - alert_date if now.date() == alert_date.date(): try: alerts['today'].append(alert) except KeyError: alerts['today'] = [alert] elif yesterday.date() == alert_date.date(): try: alerts['yesterday'].append(alert) except KeyError: alerts['yesterday'] = [alert] elif diff.days <= 7: try: alerts['week'].append(alert) except KeyError: alerts['week'] = [alert] elif diff.days <= 30: try: alerts['month'].append(alert) except KeyError: alerts['month'] = [alert] else: try: alerts['older'].append(alert) except KeyError: alerts['older'] = [alert] new_alerts = request.user.alerts request.user.alerts = 0 request.user.alerts_date = now request.user.save(force_update=True) return render_to_response('alerts/list.html', { 'new_alerts': new_alerts, 'alerts': alerts, }, context_instance=RequestContext(request))
def alerts(request): if request.is_ajax(): if request.session.get('recent_alerts'): alerts_qs = request.user.alert_set.filter( date__gte=request.session['recent_alerts']).order_by('-id') else: alerts_qs = () response_html = render_to_string( 'alerts/modal.html', {'alerts': alerts_qs}, context_instance=RequestContext(request)) if request.user.alerts: request.user.alerts = 0 request.user.alerts_date = timezone.now() request.user.save(force_update=True) return json_response(request, json={'html': response_html}) if not request.user.alerts_date: request.user.alerts_date = request.user.join_date now = localtime(timezone.now()) yesterday = now - timedelta(days=1) alerts = {} for alert in request.user.alert_set.order_by('-id'): alert.new = alert.date > request.user.alerts_date alert_date = localtime(deepcopy(alert.date)) diff = now - alert_date if now.date() == alert_date.date(): try: alerts['today'].append(alert) except KeyError: alerts['today'] = [alert] elif yesterday.date() == alert_date.date(): try: alerts['yesterday'].append(alert) except KeyError: alerts['yesterday'] = [alert] elif diff.days <= 7: try: alerts['week'].append(alert) except KeyError: alerts['week'] = [alert] elif diff.days <= 30: try: alerts['month'].append(alert) except KeyError: alerts['month'] = [alert] else: try: alerts['older'].append(alert) except KeyError: alerts['older'] = [alert] new_alerts = request.user.alerts request.user.alerts = 0 request.user.alerts_date = now request.user.save(force_update=True) return render_to_response('alerts/list.html', { 'new_alerts': new_alerts, 'alerts': alerts, }, context_instance=RequestContext(request))