def save_attribute(project, nominator, form_data, summary_list, attribute_name, valvar): """Stores attribute/value for given url in database. Separated out of add_other_attribute to handle attributes where a list of values was submitted. """ try: #Check if URL attribute and value already exist added_url = URL.objects.get(url_nominator = nominator, url_project = project, entity__iexact = form_data['url_value'], value__iexact = valvar, attribute__iexact = attribute_name, ) except: try: added_url = URL(entity = form_data['url_value'], value = valvar, attribute = attribute_name, url_project = project, url_nominator = nominator, ) added_url.save() except: raise http.Http404 else: summary_list.append('You have successfully added the ' + \ attribute_name + ' \"' + valvar + '\" for ' + form_data['url_value']) else: summary_list.append('You have already added the ' + \ attribute_name + ' \"' + valvar + '\" for ' + form_data['url_value']) return summary_list
def create_url_entry(project, nominator, url_entity, url_attribute, url_value): #Create a new url entry if it doesn't already exist try: if url_attribute == 'surt': existing_url = URL.objects.get(url_project=project, entity__iexact=url_entity, attribute__iexact=url_attribute, value__iexact=url_value ) else: existing_url = URL.objects.get(url_project=project, url_nominator=nominator, entity__iexact=url_entity, attribute__iexact=url_attribute, value__iexact=url_value ) except: try: new_url = URL(url_project = project, url_nominator = nominator, entity = url_entity, attribute = url_attribute, value = url_value, ) new_url.save() except: print "Failed to create a new entry for url: %s attribute: %s value: %s" % (url_entity, url_attribute, url_value) return False else: return False return True
def surt_exists(project, system_nominator, url_entity): #Create a SURT if the url doesn't already have one try: surt_url = URL.objects.get(url_project=project, entity__iexact=url_entity, attribute__iexact='surt') except: try: new_surt = URL(entity = url_entity, value = surtize(url_entity), attribute = 'surt', url_project = project, url_nominator = system_nominator, ) new_surt.save() except: raise http.Http404 return True
def nominate_url(project, nominator, form_data, scope_value): summary_list = [] #Nominate URL try: #Check if user has already nominated the URL nomination_url = URL.objects.get(url_nominator__id__iexact = nominator.id, url_project = project, entity__iexact = form_data['url_value'], attribute__iexact = 'nomination', ) except: try: #Nominate URL nomination_url = URL(entity = form_data['url_value'], value = scope_value, attribute = 'nomination', url_project = project, url_nominator = nominator, ) nomination_url.save() except: raise http.Http404 else: summary_list.append('You have successfully nominated ' + form_data['url_value']) else: if nomination_url.value == scope_value: if scope_value == '1': summary_list.append('You have already declared ' + form_data['url_value'] + ' as \"In Scope\"') else: summary_list.append('You have already declared ' + form_data['url_value'] + ' as \"Out of Scope\"') else: nomination_url.value = scope_value nomination_url.save() if scope_value == '1': summary_list.append('You have successfully declared ' + form_data['url_value'] + ' as \"In Scope\"') else: summary_list.append('You have successfully declared ' + form_data['url_value'] + ' as \"Out of Scope\"') return summary_list