def big_feed(request): ''' Look at the big board! They're gettin' ready to clobber us! ''' user_privileges = get_privileges_for_user(request.user) tasks = Task.objects.filter( access_requirements__prototype__privilege__in=user_privileges, resolutions__isnull=True).order_by('-created')[:10] ownerships = list( TaskOwnership.objects.filter( task__resolutions__isnull=True).order_by('-created')[:10]) task_messages = list(TopLevelMessage.objects.filter(content_type=T)) task_resolutions = list(TaskResolution.objects.order_by('-created')[:10]) sessions = list(SessionInfo.objects.order_by('-created')[:10]) task_activity = task_messages + task_resolutions + ownerships + sessions sorted_task_activity = sorted(task_activity, key=lambda item: item.created, reverse=True)[:10] activity_list = [] for item in sorted_task_activity: activity_list.append((item, str(item._meta).split('.')[1])) return render(request, 'do/do_news_feed.html', locals())
def create_task(request): ''' This is one of the worst views I have ever written. -Justin ''' user_can_make_new_prototypes = True #TODO: Turn this into an actual privilege assessment task_prototype_name_form = TaskPrototypeNameForm() task_prototype_name_form.fields['name'].widget.attrs['class'] = "topLevel" #So that we can recognize it later via autocomplete. TODO: DO this in the form object. rest_of_the_task_prototype_form = RestOfTheTaskPrototypeForm() #TODO: Can we please. please. please make this one object. #Wet and silly. TODO: Fix class SimpleChildForm(forms.Form): child = AutoCompleteField(models = (TaskPrototype,), name_visible_field=True) class SimpleParentForm(forms.Form): parent = AutoCompleteField(models = (TaskPrototype,), name_visible_field=True) task_prototype_form = TaskPrototypeForm() task_prototype_parent_form = SimpleParentForm() task_prototype_child_form = SimpleChildForm() user_privileges = get_privileges_for_user(request.user) try: #WHAT ON GODS GREEN F*****G SERVER IS HAPPENING HERE task_prototype_form.fields['name'].initial = request.GET['name'] except: pass return render(request, 'do/create_task_prototype.html', locals())
def create_task(request): ''' This is one of the worst views I have ever written. -Justin ''' user_can_make_new_prototypes = True #TODO: Turn this into an actual privilege assessment task_prototype_name_form = TaskPrototypeNameForm() task_prototype_name_form.fields['name'].widget.attrs[ 'class'] = "topLevel" #So that we can recognize it later via autocomplete. TODO: DO this in the form object. rest_of_the_task_prototype_form = RestOfTheTaskPrototypeForm( ) #TODO: Can we please. please. please make this one object. #Wet and silly. TODO: Fix class SimpleChildForm(forms.Form): child = AutoCompleteField(models=(TaskPrototype, ), name_visible_field=True) class SimpleParentForm(forms.Form): parent = AutoCompleteField(models=(TaskPrototype, ), name_visible_field=True) task_prototype_form = TaskPrototypeForm() task_prototype_parent_form = SimpleParentForm() task_prototype_child_form = SimpleChildForm() user_privileges = get_privileges_for_user(request.user) try: #WHAT ON GODS GREEN F*****G SERVER IS HAPPENING HERE task_prototype_form.fields['name'].initial = request.GET['name'] except: pass return render(request, 'do/create_task_prototype.html', locals())
def big_feed(request): ''' Look at the big board! They're gettin' ready to clobber us! ''' user_privileges = get_privileges_for_user(request.user) tasks = Task.objects.filter(access_requirements__prototype__privilege__in = user_privileges, resolutions__isnull = True).order_by('-created')[:10] ownerships = list(TaskOwnership.objects.filter(task__resolutions__isnull=True).order_by('-created')[:10]) task_messages = list(TopLevelMessage.objects.filter(content_type = T)) task_resolutions = list(TaskResolution.objects.order_by('-created')[:10]) sessions = list(SessionInfo.objects.order_by('-created')[:10]) task_activity = task_messages + task_resolutions + ownerships + sessions sorted_task_activity = sorted(task_activity, key=lambda item: item.created, reverse=True)[:10] activity_list = [] for item in sorted_task_activity: activity_list.append((item, str(item._meta).split('.')[1])) return render(request, 'do/do_news_feed.html', locals() )
def order_verbs_by_number_of_tasks_user_can_see(self, user, *args, **kwargs): user_privileges = get_privileges_for_user(user) verbs_with_at_least_one_task_for_user = super( VerbManager, self ).filter( prototypes__instances__access_requirements__prototype__privilege__in =user_privileges).distinct() verbs_with_no_tasks_for_user = super(VerbManager, self).exclude( prototypes__instances__access_requirements__prototype__privilege__in =user_privileges) verb_list = [] for verb in verbs_with_at_least_one_task_for_user: verb_list.append( (verb, verb.count_tasks_for_user(user)) ) #Append a tuple with the verb and the number of tasks this user can see. sorted_verb_list_tuples = sorted( verb_list, key=lambda verb_info: verb_info[1], reverse=True ) # Sort by the second entry for each tuple in the list (which, after all, is the number of tasks that this user can see). for verb in verbs_with_no_tasks_for_user: sorted_verb_list_tuples.append( (verb, 0) ) #Safely append to the sorted list because these will each be zero. sorted_verb_list = [] for verb in sorted_verb_list_tuples: sorted_verb_list.append(verb[0]) return sorted_verb_list
def filter_verbs_with_tasks_user_can_see(self, user, *args, **kwargs): ''' Takes a user and returns a list of verbs that contain tasks which the user can see. ''' user_privileges = get_privileges_for_user(user) verbs = super(VerbManager, self).filter(prototypes__instances__access_requirements__privilege__in=user_privileges) #TODO: This appears to only check that they have one of the privilege; there may be more than one. return verbs
def get_tasks_for_user(self, user, level=5, show_completed=False): #level is hardcoded for now ''' Based on a user's privileges, figure out which Tasks they can see. ''' user_privileges = get_privileges_for_user(user) tasks = Task.objects.filter(access_requirements__prototype__privilege__in=user_privileges, prototype__type=self, resolutions__isnull=True).distinct() #TODO: Account for re-opened tasks. return tasks
def task_profile(request, task_id): task = get_object_or_404(Task, id = task_id) #It wasn't bad enough that the actual create form was wet and silly. Now this too. TODO: FIX THIS F****R. user_can_make_new_prototypes = True #TODO: Turn this into an actual privilege assessment task_prototype_name_form = TaskPrototypeNameForm() task_prototype_name_form.fields['name'].widget.attrs['class'] = "topLevel" #So that we can recognize it later via autocomplete. rest_of_the_task_prototype_form = RestOfTheTaskPrototypeForm() user_privileges = get_privileges_for_user(request.user) #Wet and silly. TODO: Fix class SimpleChildForm(forms.Form): child = AutoCompleteField(models = (TaskPrototype,), name_visible_field=True) class SimpleParentForm(forms.Form): parent = AutoCompleteField(models = (TaskPrototype,), name_visible_field=True) task_prototype_form = TaskPrototypeForm() task_prototype_parent_form = SimpleParentForm() task_prototype_child_form = SimpleChildForm() draw_attention_ajax_form = DrawAttentionAjaxForm() if task.prototype.id == 251 or task.prototype.id == 7: has_outgoing_call = True disable_incoming_calls = True account_sid = "AC260e405c96ce1eddffbddeee43a13004" auth_token = "fd219130e257e25e78613adc6c003d1a" capability = TwilioCapability(account_sid, auth_token) capability.allow_client_outgoing("APd13a42e60c91095f3b8683a77ee2dd05") #The text of the call recipient will be the name of the person in the case of a tech job. It will be the output of the unicode method of the PhoneNumber in the case of a PhoneCall resolution. if task.prototype.id == 251: call_to_name = task.related_objects.all()[0].object.get_full_name() related_user = task.related_objects.all()[0].object phone_numbers = task.related_objects.all()[0].object.userprofile.contact_info.phone_numbers.all() if task.prototype.id == 7: phone_numbers = [task.related_objects.all()[0].object.from_number] if task.related_objects.all()[0].object.from_number.owner: call_to_name = task.related_objects.all()[0].object.from_number.owner else: call_to_name = "Phone Number #%s" % (str(task.related_objects.all()[0].object.id)) return render(request, 'do/task_profile.html', locals() )
def task_profile(request, task_id): task = get_object_or_404(Task, id=task_id) #It wasn't bad enough that the actual create form was wet and silly. Now this too. TODO: FIX THIS F****R. user_can_make_new_prototypes = True #TODO: Turn this into an actual privilege assessment task_prototype_name_form = TaskPrototypeNameForm() task_prototype_name_form.fields['name'].widget.attrs[ 'class'] = "topLevel" #So that we can recognize it later via autocomplete. rest_of_the_task_prototype_form = RestOfTheTaskPrototypeForm() user_privileges = get_privileges_for_user(request.user) #Wet and silly. TODO: Fix class SimpleChildForm(forms.Form): child = AutoCompleteField(models=(TaskPrototype, ), name_visible_field=True) class SimpleParentForm(forms.Form): parent = AutoCompleteField(models=(TaskPrototype, ), name_visible_field=True) task_prototype_form = TaskPrototypeForm() task_prototype_parent_form = SimpleParentForm() task_prototype_child_form = SimpleChildForm() draw_attention_ajax_form = DrawAttentionAjaxForm() if task.prototype.id == 251 or task.prototype.id == 7: has_outgoing_call = True disable_incoming_calls = True account_sid = "AC260e405c96ce1eddffbddeee43a13004" auth_token = "fd219130e257e25e78613adc6c003d1a" capability = TwilioCapability(account_sid, auth_token) capability.allow_client_outgoing("APd13a42e60c91095f3b8683a77ee2dd05") #The text of the call recipient will be the name of the person in the case of a tech job. It will be the output of the unicode method of the PhoneNumber in the case of a PhoneCall resolution. if task.prototype.id == 251: call_to_name = task.related_objects.all()[0].object.get_full_name() related_user = task.related_objects.all()[0].object phone_numbers = task.related_objects.all( )[0].object.userprofile.contact_info.phone_numbers.all() if task.prototype.id == 7: phone_numbers = [task.related_objects.all()[0].object.from_number] if task.related_objects.all()[0].object.from_number.owner: call_to_name = task.related_objects.all( )[0].object.from_number.owner else: call_to_name = "Phone Number #%s" % (str( task.related_objects.all()[0].object.id)) return render(request, 'do/task_profile.html', locals())
def can_be_seen_by_user(self, user, *args, **kwargs): ''' Filters tasks that can be seen by a particular user. TODO: See if this can be optimized. ''' user_privileges = get_privileges_for_user(user) queryset = super(TaskManager, self).filter(access_requirements__prototype__privilege__in=user_privileges) return queryset
def filter_verbs_with_tasks_user_can_see(self, user, *args, **kwargs): ''' Takes a user and returns a list of verbs that contain tasks which the user can see. ''' user_privileges = get_privileges_for_user(user) verbs = super(VerbManager, self).filter( prototypes__instances__access_requirements__privilege__in= user_privileges ) #TODO: This appears to only check that they have one of the privilege; there may be more than one. return verbs
def can_be_seen_by_user(self, user, *args, **kwargs): ''' Filters tasks that can be seen by a particular user. TODO: See if this can be optimized. ''' user_privileges = get_privileges_for_user(user) queryset = super(TaskManager, self).filter( access_requirements__prototype__privilege__in=user_privileges) return queryset
def get_tasks_for_user(self, user, level=5, show_completed=False): #level is hardcoded for now ''' Based on a user's privileges, figure out which Tasks they can see. ''' user_privileges = get_privileges_for_user(user) tasks = Task.objects.filter( access_requirements__prototype__privilege__in=user_privileges, prototype__type=self, resolutions__isnull=True).distinct( ) #TODO: Account for re-opened tasks. return tasks
def order_verbs_by_number_of_tasks_user_can_see(self, user, *args, **kwargs): user_privileges = get_privileges_for_user(user) verbs_with_at_least_one_task_for_user = super(VerbManager, self).filter(prototypes__instances__access_requirements__prototype__privilege__in=user_privileges).distinct() verbs_with_no_tasks_for_user = super(VerbManager, self).exclude(prototypes__instances__access_requirements__prototype__privilege__in=user_privileges) verb_list = [] for verb in verbs_with_at_least_one_task_for_user: verb_list.append((verb, verb.count_tasks_for_user(user))) #Append a tuple with the verb and the number of tasks this user can see. sorted_verb_list_tuples = sorted(verb_list, key=lambda verb_info: verb_info[1], reverse=True) # Sort by the second entry for each tuple in the list (which, after all, is the number of tasks that this user can see). for verb in verbs_with_no_tasks_for_user: sorted_verb_list_tuples.append((verb, 0)) #Safely append to the sorted list because these will each be zero. sorted_verb_list = [] for verb in sorted_verb_list_tuples: sorted_verb_list.append(verb[0]) return sorted_verb_list