def save(self, **kwargs): if self.place_type is None: if self.place_id != '' and self.place_id is not None: raise ValidationError( ('Place ID cannot be saved without place type'), code='invalid') if self.place_id is None or self.place_id == '': if self.place_type is not None: raise ValidationError( ('Place type cannot be saved without place id'), code='invalid') fullname = self.get_full_name() if fullname == '': fullname = 'default' self.slug = slugify(fullname) isSaved = False ctr = 1 while not isSaved: try: super(UserProfile, self).save(**kwargs) isSaved = True except IntegrityError: # Duplicate slug self.slug = self.slug + str(ctr) ctr = ctr + 1
def set_place(self, value): value = value.strip() junkdata = '' if(value): if('/' in value): # Multiple cities separated by '/'. We take the first one. (value, junkdata) = value.split('/', 1) value = value.strip() cities = City.objects.filter(name__iexact=value) if(cities): self.place_id = cities[0].id self.place_type = CITY else: states = State.objects.filter(name__iexact=value) if(states): self.place_id = states[0].id self.place_type = STATE else: countries = Country.objects.filter(name__iexact=value) if(countries): self.place_id = countries[0].id self.place_type = COUNTRY else: synonyms = Synonym.objects.filter(Q(value__iexact=value), Q(resourcetype=RT_CITY) | Q(resourcetype=RT_STATE) | Q( resourcetype=RT_COUNTRY), Q(aliastype=SYNONYM)) if(synonyms): if(synonyms[0].resourcetype == RT_CITY): self.place_type = CITY self.place_id = synonyms[0].parent_id elif(synonyms[0].resourcetype == RT_STATE): self.place_type = STATE self.place_id = synonyms[0].parent_id elif(synonyms[0].resourcetype == RT_COUNTRY): self.place_type = COUNTRY self.place_id = synonyms[0].parent_id else: slug = slugify(value) try: city = City.objects.get(slug=slug) self.place_type = CITY self.place_id = city.id except ObjectDoesNotExist: # Creating a new city be default. Admins will then change this # data. newcity = City(name=value) newcity.save() else: # Creating a new city be default. Admins will then change this data. newcity = City(name=value) newcity.save() log.debug("IMPORTANT: New city added: [" + value + "]") if junkdata != '': junkdata = ProfileJunkData(userprofile=self, key='place', value=junkdata) junkdata.save() return self
def save(self, **kwargs): self.slug = slugify(self.name) isSaved = False ctr = 1 while not isSaved: try: super(Course, self).save(**kwargs) isSaved = True except IntegrityError: #Duplicate slug self.slug = self.slug + str(ctr) ctr = ctr + 1
def save(self, **kwargs): self.slug = slugify(self.get_name() + ' ' + self.get_course()) isSaved = False ctr = 1 while not isSaved: try: super(Branch, self).save(**kwargs) isSaved = True except IntegrityError: #Duplicate slug self.slug = self.slug + str(ctr) ctr = ctr + 1
def get_unique_slug(self): name = self.get_full_name() if name == '': name = 'default' slug = slugify(name) ctr = 0 while True: userprofiles = UserProfile.objects.filter(slug=slug) if not userprofiles: return slug else: if userprofiles[0] == self: return slug ctr = ctr + 1 slug = slug + '-' + str(ctr) return slug
def save(self, **kwargs): self.slug = slugify(self.name) super(Department, self).save(**kwargs)
def save(self, **kwargs): self.slug = slugify(self.name) super(FacultyDesignation, self).save(**kwargs)
def save(self, **kwargs): self.slug = slugify(self.name) super(Degree, self).save(**kwargs)
def save(self, **kwargs): self.slug = slugify(self.name) super(HigherEducationBranch, self).save(**kwargs)
def save(self, **kwargs): self.slug = slugify(self.name) super(JobDomain, self).save(**kwargs)
def save(self, **kwargs): self.slug = slugify(self.name) super(College, self).save(**kwargs)
def save(self, **kwargs): self.slug = slugify(self.name) super(Employer, self).save(**kwargs)
def set_place(self, value): value = value.strip() junkdata = '' if (value): if ('/' in value ): # Multiple cities separated by '/'. We take the first one. (value, junkdata) = value.split('/', 1) value = value.strip() cities = City.objects.filter(name__iexact=value) if (cities): self.place_id = cities[0].id self.place_type = CITY else: states = State.objects.filter(name__iexact=value) if (states): self.place_id = states[0].id self.place_type = STATE else: countries = Country.objects.filter(name__iexact=value) if (countries): self.place_id = countries[0].id self.place_type = COUNTRY else: synonyms = Synonym.objects.filter( Q(value__iexact=value), Q(resourcetype=RT_CITY) | Q(resourcetype=RT_STATE) | Q(resourcetype=RT_COUNTRY), Q(aliastype=SYNONYM)) if (synonyms): if (synonyms[0].resourcetype == RT_CITY): self.place_type = CITY self.place_id = synonyms[0].parent_id elif (synonyms[0].resourcetype == RT_STATE): self.place_type = STATE self.place_id = synonyms[0].parent_id elif (synonyms[0].resourcetype == RT_COUNTRY): self.place_type = COUNTRY self.place_id = synonyms[0].parent_id else: slug = slugify(value) try: city = City.objects.get(slug=slug) self.place_type = CITY self.place_id = city.id except ObjectDoesNotExist: # Creating a new city be default. Admins will then change this # data. newcity = City(name=value) newcity.save() else: # Creating a new city be default. Admins will then change this data. newcity = City(name=value) newcity.save() log.debug("IMPORTANT: New city added: [" + value + "]") if junkdata != '': junkdata = ProfileJunkData(userprofile=self, key='place', value=junkdata) junkdata.save() return self
def save(self, **kwargs): self.slug = slugify(self.name + " " + self.get_country()) super(State, self).save(**kwargs)