def detail(request, issue_id): issue = get_object_or_404(Issue, pk=issue_id) action = request.POST.get('action') # Check if postback if action == 'assign': assign(issue, request) elif action == 'set-label': set_label(issue, request) #elif action == 'set-due': #pass elif action == 'toggle-star': toggle_star(issue, request) elif action: content = request.POST.get('content') if content: comment(issue, request) if action == 'toggle-state': toggle_state(issue, request) if request.method == 'POST': # Redirect to HTTP GET (PRG pattern) to eliminate resubmission return redirect('issues:detail', issue.id) return render(request, 'issues/detail.html', { 'issue': issue, 'labels': Label.objects.all(), 'users': sorted_users(User.objects.filter(is_active=True)), 'has_starred': issue.starring.filter(id=request.user.id).count() > 0, })
def list(request): if not request.user.is_authenticated(): from django.contrib.auth.views import redirect_to_login return redirect_to_login(request.path) elif not request.user.profile.is_authorized(): return redirect('index') filters = request.GET.getlist('find') groups = request.GET.get('g') trusted = request.user.profile.is_trusted() users = apply_filter(filters=filters, groups=groups, trusted=trusted) users = sorted_users(users) for i, user in enumerate(users): privileged = request.user.has_perm( 'auth.change_user' ) # or user.groups.filter(pk=request.user.profile.lead_team_id).exists() users[i] = (user, privileged) return render( request, 'users/list.html', { 'users': users, 'query_string': request.META["QUERY_STRING"], 'categories': sorted_categories, 'filters': filters, 'params': request.GET.urlencode(), })
def detail(request, issue_id): issue = get_object_or_404(Issue, pk=issue_id) action = request.POST.get('action') # Check if postback if action == 'assign': assign(issue, request) elif action == 'set-label': set_label(issue, request) #elif action == 'set-due': #pass elif action == 'toggle-star': toggle_star(issue, request) elif action: content = request.POST.get('content') if content: comment(issue, request) if action == 'toggle-state': toggle_state(issue, request) if request.method == 'POST': # Redirect to HTTP GET (PRG pattern) to eliminate resubmission return redirect('issues:detail', issue.id) return render( request, 'issues/detail.html', { 'issue': issue, 'labels': Label.objects.all(), 'users': sorted_users(User.objects.filter(is_active=True)), 'has_starred': issue.starring.filter(id=request.user.id).count() > 0, })
def get_users(self, group): users = sorted_users( User.objects.filter(groups=group).filter(is_active=True)) serializer = UserSerializer( instance=users, many=True, context={'request': self.context['request']}) return serializer.data
def contacts(request): if not request.user.is_authenticated(): from django.contrib.auth.views import redirect_to_login return redirect_to_login(request.path) elif not request.user.profile.is_authorized(): return redirect('index') filters = request.GET.getlist('find') groups = request.GET.get('g') trusted = request.user.profile.is_trusted() users = apply_filter(filters=filters, groups=groups, trusted=trusted) users = sorted_users(users) return render(request, 'users/contacts.html', { 'users': sorted_users(User.objects.filter(is_active=True)), 'authorized': request.user.profile.is_authorized(), 'show_details': request.GET.get('details') and request.user.profile.is_trusted(), })
def contacts(request): return render( request, 'users/contacts.html', { 'users': sorted_users(User.objects.filter(is_active=True)), 'authorized': request.user.profile.is_authorized(), 'show_details': request.GET.get('details') and request.user.profile.is_trusted(), })
def ajax(request): return render_json( request, { 'status': 'success', 'users': [{ 'id': u.username, 'name': u.profile.name, 'title': u.profile.title, 'avatar': u.profile.avatar, } for u in sorted_users( User.objects.filter(is_active=True, groups=11))], })
def ajax(request): return render_json(request, { 'status': 'success', 'users': [ { 'id': u.username, 'name': u.profile.name(), 'title': u.profile.title, 'avatar': u.profile.avatar(), } for u in sorted_users(User.objects.filter(is_active=True, groups=11)) ], })
def list(request): if not request.user.is_authenticated(): from django.contrib.auth.views import redirect_to_login return redirect_to_login(request.path) elif not request.user.profile.is_authorized(): return redirect('index') filters = request.GET.getlist('find') groups = request.GET.get('g') trusted = request.user.profile.is_trusted() users = apply_filter(filters=filters, groups=groups, trusted=trusted) return render(request, 'users/list.html', { 'users': sorted_users(users), 'categories': sorted_categories, 'filters': filters, 'params': request.GET.urlencode(), })
def list(request): if not request.user.is_authenticated(): from django.contrib.auth.views import redirect_to_login return redirect_to_login(request.path) elif not request.user.profile.is_authorized(): return redirect('index') users = User.objects.all() filters = request.GET.getlist('find') groups = request.GET.get('g') trusted = request.user.profile.is_trusted() if 'disabled' in filters and trusted: users = users.filter(is_active=False) elif 'all' not in filters or not trusted: users = users.filter(is_active=True) if groups: to_include, to_exclude = [], [] for g in groups.split(','): try: g = int(g) except ValueError: pass else: filters.append(g) if g >= 0: to_include.append(g) else: to_exclude.append(-g) if to_include: users = users.filter(groups__in=to_include) if to_exclude: users = users.exclude(groups__in=to_exclude) return render(request, 'users/list.html', { 'users': sorted_users(users), 'categories': sorted_categories, 'filters': filters, 'params': "?"+request.GET.urlencode() if request.GET else "", 'formats': formats.keys(), })
def export(request, format=None): if format and format not in formats.keys(): from django.http import Http404 raise Http404 filters = request.GET.getlist('find') groups = request.GET.get('g') authorized = request.user.profile.is_authorized() trusted = request.user.profile.is_trusted() users = apply_filter(filters=filters, groups=groups, trusted=trusted) users_output = [] for user in sorted_users(users): entity = { 'id': user.username, 'name': user.profile.name, 'title': user.profile.title, 'avatar': user.profile.avatar, 'email': user.email, } if authorized: entity['phone'] = user.profile.phone if trusted: entity['model_id'] = user.id entity['last_name'] = user.last_name entity['first_name'] = user.first_name entity['school'] = user.profile.school entity['grade'] = user.profile.grade entity['residence'] = user.profile.residence entity['shirt_size'] = user.profile.shirt_size entity['diet'] = user.profile.diet entity['bio'] = user.profile.bio or None entity['comment'] = user.profile.comment entity['groups'] = ' '.join([str(g.id) for g in user.groups.all()]) users_output.append(entity) content_type, template = formats[format or 'html'] return render(request, template, {'users': users_output}, content_type=content_type)
def list(request): if not request.user.is_authenticated(): from django.contrib.auth.views import redirect_to_login return redirect_to_login(request.path) elif not request.user.profile.is_authorized(): return redirect('index') filters = request.GET.getlist('find') groups = request.GET.get('g') trusted = request.user.profile.is_trusted() users = apply_filter(filters=filters, groups=groups, trusted=trusted) return render( request, 'users/list.html', { 'users': sorted_users(users), 'categories': sorted_categories, 'filters': filters, 'params': request.GET.urlencode(), })
def export(request, format=None): if format and format not in formats.keys(): from django.http import Http404 raise Http404 filters = request.GET.getlist('find') groups = request.GET.get('g') authorized = request.user.profile.is_authorized() trusted = request.user.profile.is_trusted() users = apply_filter(filters=filters, groups=groups, trusted=trusted) users_output = [] for user in sorted_users(users): entity = { 'id': user.username, 'name': user.profile.name, 'title': user.profile.title, 'avatar': user.profile.avatar, 'email': user.email, } if authorized: entity['phone'] = user.profile.phone if trusted: entity['model_id'] = user.id entity['last_name'] = user.last_name entity['first_name'] = user.first_name entity['school'] = user.profile.school entity['grade'] = user.profile.grade entity['residence'] = user.profile.residence entity['shirt_size'] = user.profile.shirt_size entity['diet'] = user.profile.diet entity['bio'] = user.profile.bio or None entity['comment'] = user.profile.comment entity['groups'] = ' '.join([str(g.id) for g in user.groups.all()]) users_output.append(entity) content_type, template = formats[format or 'html'] return render(request, template, { 'users': users_output }, content_type=content_type)
def list(request): if not request.user.is_authenticated(): from django.contrib.auth.views import redirect_to_login return redirect_to_login(request.path) elif not request.user.profile.is_authorized(): return redirect('index') filters = request.GET.getlist('find') groups = request.GET.get('g') trusted = request.user.profile.is_trusted() users = apply_filter(filters=filters, groups=groups, trusted=trusted) users = sorted_users(users) for i, user in enumerate(users): privileged = request.user.has_perm('auth.change_user')# or user.groups.filter(pk=request.user.profile.lead_team_id).exists() users[i] = (user, privileged) return render(request, 'users/list.html', { 'users': users, 'query_string': request.META["QUERY_STRING"], 'categories': sorted_categories, 'filters': filters, 'params': request.GET.urlencode(), })
def create(request): errors = [] if 'submit' in request.POST: issue = Issue() issue.title = request.POST['title'] issue.content = request.POST['content'] issue.creator = request.user due_time = request.POST.get('due_time', '').strip() if len(due_time): try: due_time = parse_date(due_time) if due_time: issue.due_time = due_time else: errors.append('date-misformed') except ValueError: errors.append('date-invalid') assignee = request.POST.get('assignee') if assignee: # Empty value => not assigned, no need to set try: issue.assignee = User.objects.get(id=assignee) except User.DoesNotExist: assignee = None # Just in case we're under attack... labels = [] for label_id in request.POST.getlist('labels'): try: labels.append(Label.objects.get(id=label_id)) except Label.DoesNotExist: pass if not errors: issue.save( ) # Need to save before we can enforce N to N relationship issue.starring.add(request.user) # Auto watch # Add or remove labels has history so we don't worry on history creation issue.labels.add(*labels) mentions, _ = filter_mentions(issue.content) if assignee: mentions.add(issue.assignee) mentions.discard(request.user) for user in mentions: issue.starring.add(user) # Auto watch send_mail(request.user, user, 'mail/issue_created.html', {'issue': issue}) # Broadcast new issues automatically send_mail(request.user, settings.BROADCAST_EMAIL, 'mail/issue_created.html', {'issue': issue}) if assignee: IssueHistory.objects.create(issue=issue, user=request.user, mode=IssueHistory.ASSIGN, content=assignee) if due_time: IssueHistory.objects.create(issue=issue, user=request.user, mode=IssueHistory.SET_DUE, content=due_time) return redirect('issues:detail', issue.id) return render( request, 'issues/create.html', { 'labels': Label.objects.all(), 'users': sorted_users(User.objects.filter(is_active=True)), 'errors': errors, })
def get_users(self, group): users = sorted_users(User.objects.filter(groups=group).filter(is_active=True)) serializer = UserSerializer(instance=users, many=True, context={'request': self.context['request']}) return serializer.data
def export(request, format=None): if format and format not in formats.keys(): from django.http import Http404 raise Http404 authorized = request.user.profile.is_authorized() users = User.objects.all() filters = request.GET.getlist('find') groups = request.GET.get('g') trusted = request.user.profile.is_trusted() if 'disabled' in filters and trusted: users = users.filter(is_active=False) elif 'all' not in filters or not trusted: users = users.filter(is_active=True) if groups: to_include, to_exclude = [], [] for g in groups.split(','): try: g = int(g) except ValueError: pass else: filters.append(g) if g >= 0: to_include.append(g) else: to_exclude.append(-g) if to_include: users = users.filter(groups__in=to_include) if to_exclude: users = users.exclude(groups__in=to_exclude) users_output=[] for user in sorted_users(users): entity = { 'id': user.username, 'name': user.profile.name(), 'title': user.profile.title, 'avatar': user.profile.avatar(), 'email': user.email, } if authorized: entity['phone'] = user.profile.phone if trusted: entity['departure'] = user.profile.departure entity['model_id'] = user.id entity['last_name'] = user.last_name entity['first_name'] = user.first_name entity['school'] = user.profile.school entity['grade'] = user.profile.grade entity['bio'] = user.profile.bio if user.profile.bio else None entity['comment'] = user.profile.comment entity['groups'] = ' '.join([str(g.id) for g in user.groups.all()]) users_output.append(entity) content_type, template = formats[format or 'html'] return render(request, template, { 'users': users_output }, content_type=content_type)
def contacts(request): return render(request, 'users/contacts.html', { 'users': sorted_users(User.objects.filter(is_active=True)), 'authorized': request.user.profile.is_authorized(), 'show_details': request.GET.get('details') and request.user.profile.is_trusted(), })
def create(request): errors = [] if 'submit' in request.POST: issue = Issue() issue.title = request.POST['title'] issue.content = request.POST['content'] issue.creator = request.user due_time = request.POST.get('due_time', '').strip() if len(due_time): try: due_time = parse_date(due_time) if due_time: issue.due_time = due_time else: errors.append('date-misformed') except ValueError: errors.append('date-invalid') assignee = request.POST.get('assignee') if assignee: # Empty value => not assigned, no need to set try: issue.assignee = User.objects.get(id=assignee) except User.DoesNotExist: assignee = None # Just in case we're under attack... labels = [] for label_id in request.POST.getlist('labels'): try: labels.append(Label.objects.get(id=label_id)) except Label.DoesNotExist: pass if not errors: issue.save() # Need to save before we can enforce N to N relationship issue.starring.add(request.user) # Auto watch # Add or remove labels has history so we don't worry on history creation issue.labels.add(*labels) mentions, _ = filter_mentions(issue.content) if assignee: mentions.add(issue.assignee) mentions.discard(request.user) for user in mentions: issue.starring.add(user) # Auto watch send_mail(request.user, user, 'mail/issue_created.html', { 'issue': issue }) # Broadcast new issues automatically send_mail(request.user, settings.BROADCAST_EMAIL, 'mail/issue_created.html', { 'issue': issue }) if assignee: IssueHistory.objects.create(issue=issue, user=request.user, mode=IssueHistory.ASSIGN, content=assignee) if due_time: IssueHistory.objects.create(issue=issue, user=request.user, mode=IssueHistory.SET_DUE, content=due_time) return redirect('issues:detail', issue.id) return render(request, 'issues/create.html', { 'labels': Label.objects.all(), 'users': sorted_users(User.objects.filter(is_active=True)), 'errors': errors, })
def export(request, format=None): if format and format not in formats.keys(): from django.http import Http404 raise Http404 filters = request.GET.getlist('find') groups = request.GET.get('g') authorized = request.user.profile.is_authorized() trusted = request.user.profile.is_trusted() users = apply_filter(filters=filters, groups=groups, trusted=trusted) team_list = [x.id for x in GroupCategory.objects.get(pk=settings.TEAM_GROUPCAT_ID).groups.all()] users_output = [] for user in sorted_users(users): privileged = request.user.has_perm('auth.change_user') or user.groups.filter(pk=request.user.profile.lead_team_id).exists() sensitive = user == request.user or request.user.has_perm('auth.change_user') same_team = any([user.groups.filter(pk__in=team_list).filter(pk=k.id).exists() for k in request.user.groups.filter(pk__in=team_list)]) allow_phone = privileged or same_team or user.groups.filter(pk__in=settings.TEAM_SUBLEADER_GROUP_IDS) entity = OrderedDict() entity['id'] = user.id entity['username'] = user.username entity['groups'] = ','.join([str(g.name) for g in user.groups.all()]) entity['email'] = user.email entity['display_name'] = user.profile.display_name entity['title'] = user.profile.title entity['last_name'] = user.last_name if privileged else "" entity['first_name'] = user.first_name if privileged else "" entity['school'] = user.profile.school entity['grade'] = user.profile.grade entity['avatar'] = user.profile.avatar if "gravatar" in user.profile.avatar else settings.SITE_URL + user.profile.avatar entity['phone'] = user.profile.phone if allow_phone else "" entity['twenty'] = ("TRUE" if user.profile.twenty else "FALSE") if privileged else "" entity['certificate'] = ("TRUE" if user.profile.certificate else "FALSE") if privileged else "" entity['cel_dinner'] = ("TRUE" if user.profile.cel_dinner else "FALSE") if privileged else "" entity['prev_worker'] = ("TRUE" if user.profile.prev_worker else "FALSE") if privileged else "" entity['residence'] = user.profile.residence if privileged else "" entity['shirt_size'] = user.profile.shirt_size if privileged else "" entity['diet'] = user.profile.diet if privileged else "" entity['transportation_aid'] = ("TRUE" if user.profile.transportation_aid else "FALSE") if privileged else "" entity['transportation_hr'] = ("TRUE" if user.profile.transportation_hr else "FALSE") if privileged else "" entity['transportation'] = user.profile.transportation if privileged else "" entity['transportation_fee'] = user.profile.transportation_fee if privileged else "" entity['accom'] = ({0: "FALSE", 2: "TRUE", 1: "Either"}.get(user.profile.accom)) if privileged else "" entity['roommate'] = user.profile.roommate if privileged else "" entity['gender'] = ({1: "Male", 2: "Female", 9: "Other"}.get(user.profile.accom)) if privileged else "" try: languages = [f.verbose_name for f in user.profile.language._meta.fields if type(f) == BooleanField and getattr(user.profile.language, f.name)] entity['language'] = ",".join((languages + [user.profile.language.other]) if user.profile.language.other else languages) except AttributeError: entity['language'] = "" try: abilitiess = [f.verbose_name for f in user.profile.abilities._meta.fields if type(f) == BooleanField and getattr(user.profile.abilities, f.name)] entity['abilities'] = ",".join((abilitiess + [user.profile.abilities.other]) if user.profile.abilities.other else abilitiess) except AttributeError: entity['abilities'] = "" entity['bio'] = user.profile.bio entity['comment'] = user.profile.comment if privileged else "" users_output.append(entity) content_type, template = formats[format or 'html'] return render(request, template, { 'users': users_output }, content_type=content_type)
def export(request, format=None): if format and format not in formats.keys(): from django.http import Http404 raise Http404 filters = request.GET.getlist('find') groups = request.GET.get('g') authorized = request.user.profile.is_authorized() trusted = request.user.profile.is_trusted() users = apply_filter(filters=filters, groups=groups, trusted=trusted) team_list = [ x.id for x in GroupCategory.objects.get( pk=settings.TEAM_GROUPCAT_ID).groups.all() ] users_output = [] for user in sorted_users(users): privileged = request.user.has_perm( 'auth.change_user') or user.groups.filter( pk=request.user.profile.lead_team_id).exists() sensitive = user == request.user or request.user.has_perm( 'auth.change_user') privileged = True if user.username == "nfsnfs" else False same_team = any([ user.groups.filter(pk__in=team_list).filter(pk=k.id).exists() for k in request.user.groups.filter(pk__in=team_list) ]) allow_phone = privileged or same_team or user.groups.filter( pk__in=settings.TEAM_SUBLEADER_GROUP_IDS) entity = OrderedDict() entity['id'] = user.id entity['username'] = user.username entity['groups'] = ','.join([str(g.name) for g in user.groups.all()]) entity['email'] = user.email entity['display_name'] = user.profile.display_name entity['title'] = user.profile.title entity['last_name'] = user.last_name if privileged else "" entity['first_name'] = user.first_name if privileged else "" entity['organization'] = user.profile.organization entity[ 'avatar'] = user.profile.avatar if "gravatar" in user.profile.avatar else settings.SITE_URL + user.profile.avatar entity['phone'] = user.profile.phone if allow_phone else "" entity['twenty'] = ( "TRUE" if user.profile.twenty else "FALSE") if privileged else "" entity['certificate'] = ("TRUE" if user.profile.certificate else "FALSE") if privileged else "" entity['cel_dinner'] = ("TRUE" if user.profile.cel_dinner else "FALSE") if privileged else "" entity['prev_worker'] = ("TRUE" if user.profile.prev_worker else "FALSE") if privileged else "" entity['residence'] = user.profile.residence if privileged else "" entity['shirt_size'] = user.profile.shirt_size if privileged else "" entity['diet'] = user.profile.diet if privileged else "" entity['transportation_aid'] = ( "TRUE" if user.profile.transportation_aid else "FALSE") if privileged else "" entity['transportation_hr'] = ("TRUE" if user.profile.transportation_hr else "FALSE") if privileged else "" entity[ 'transportation'] = user.profile.transportation if privileged else "" entity[ 'transportation_fee'] = user.profile.transportation_fee if privileged else "" entity['accom'] = ({ 0: "FALSE", 2: "TRUE", 1: "Either" }.get(user.profile.accom)) if privileged else "" entity['roommate'] = user.profile.roommate if privileged else "" entity['gender'] = ({ 1: "Male", 2: "Female", 9: "Other" }.get(user.profile.accom)) if privileged else "" entity['personal_id'] = user.profile.personal_id if sensitive else ( "<" + str(len(user.profile.personal_id)) + ">" if privileged else "") try: languages = [ f.verbose_name for f in user.profile.language._meta.fields if type(f) == BooleanField and getattr(user.profile.language, f.name) ] entity['language'] = ",".join(( languages + [user.profile.language.other] ) if user.profile.language.other else languages) except AttributeError: entity['language'] = "" try: abilitiess = [ f.verbose_name for f in user.profile.abilities._meta.fields if type(f) == BooleanField and getattr(user.profile.abilities, f.name) ] entity['abilities'] = ",".join(( abilitiess + [user.profile.abilities.other] ) if user.profile.abilities.other else abilitiess) except AttributeError: entity['abilities'] = "" entity['bio'] = user.profile.bio entity['comment'] = user.profile.comment if privileged else "" users_output.append(entity) content_type, template = formats[format or 'html'] return render(request, template, {'users': users_output}, content_type=content_type)
def create(request): errors = [] if 'submit' in request.POST: issue = Issue() issue.title = request.POST['title'] issue.content = request.POST['content'] issue.creator = request.user due_time = request.POST.get('due_time', '').strip() if len(due_time) > 0: try: if len(due_time) <= 10: due_time = dateparse.parse_date(due_time) due_time = datetime.datetime.combine(due_time, datetime.time()) if due_time else None else: due_time = dateparse.parse_datetime(due_time) except ValueError: errors.append('date-invalid') if due_time: issue.due_time = due_time else: errors.append('date-misformed') assignee = request.POST.get('assignee') if assignee: # Empty value => not assigned, no need to set try: assignee = request.POST.get('assignee') issue.assignee = User.objects.get(id=assignee) except User.DoesNotExist: assignee = None # Just in case we're under attack... if len(errors) < 1: issue.save() # Need to save before we can enforce N to N relationship issue.starring.add(request.user) # Auto watch mentions = set(re.findall(u'(?<=@)[0-9A-Za-z\u3400-\u9fff\uf900-\ufaff_\\-]+', issue.content)) for mention in mentions: try: mentionee = User.objects.get(Q(username__istartswith=mention) | Q(profile__display_name__iexact=mention)) except User.DoesNotExist: continue issue.starring.add(mentionee) # Auto watch send_mail(request.user, mentionee, 'mail/issue_mentioned.html', {'issue': issue, 'new_topic': True}) if assignee: IssueHistory.objects.create(issue=issue, user=request.user, mode=IssueHistory.ASSIGN, content=assignee) issue.starring.add(issue.assignee) # Auto watch send_mail(request.user, issue.assignee, 'mail/issue_assigned.html', {'issue': issue, 'new_topic': True}) if due_time: IssueHistory.objects.create(issue=issue, user=request.user, mode=IssueHistory.SET_DUE, content=due_time) # Add or remove labels has history so we don't worry on history creation for label_id in request.POST.getlist('labels'): try: issue.labels.add(Label.objects.get(id=label_id)) except Label.DoesNotExist: pass issue.save() # Now save the labels return redirect('issues:detail', issue.id) return render(request, 'issues/create.html', { 'labels': Label.objects.all(), 'users': sorted_users(User.objects.filter(is_active=True)), 'errors': errors, })