def forwards(self, orm): def category_from_str(str): import re from ummeli.opportunities.models import CATEGORY_CHOICES for key, value in CATEGORY_CHOICES: if re.sub('[\s-]', '', value.lower()) == re.sub('[\s-]', '', str.lower()): return key return 0 from ummeli.opportunities.models import Province, JobTemp from ummeli.base.models import Province as BaseProvince BaseProvince.objects.filter(name='KZN').update(name='KwaZulu Natal') BaseProvince.objects.filter(name='All').update(name='All Provinces') from django.contrib.sites.models import Site current_site = Site.objects.get_current() from ummeli.base.models import Article for job in Article.objects.all(): j = JobTemp.objects.create(title=job.text[:80], description=job.text, category=category_from_str(job.category_set.all()[0].title), state='published', created=job.date, publish_on=job.date, hash_key=job.hash_key) j.sites.add(current_site) j.province = [Province.from_str(job.category_set.all()[0].province.name)] j.save()
def forwards(self, orm): raise RuntimeError("You cannot continue with migrations. Please switch to v4.1 to continue. (`git checkout v4.1`)") from ummeli.opportunities.models import Province from ummeli.base.models import UserSubmittedJobArticle from django.contrib.sites.models import Site for old_article in UserSubmittedJobArticle.objects.iterator(): job = self.convert_community_job_to_opportunity(old_article) job.is_community = True job.save() job.province.add(Province.from_str(old_article.province)) job.sites.add(Site.objects.get_current())
def create_task(campaign, r): t = TomTomMicroTask(poi_id=r['POI_ID']) loc = Location() # srid is the ID for the coordinate system, 4326 # specifies longitude/latitude coordinates loc.coordinates = fromstr("POINT (%s %s)" % (r['X'], r['Y']), srid=4326) city = get_city(position=loc.coordinates) if not city: logger.error('Unable to create task: %s - %s. Could not obtain city from coordinates. (%s, %s)', r['NAME'], r['POI_ID'], r['Y'], r['X']) return loc.city = city loc.country = city.country loc.save() t.title = r['NAME'] t.description = '%s %s' % (r['NAME_ALT'], r['ADDRESS']) t.category = r['CAT_NAME'] t.location = loc t.tel_1 = r['TEL_NR'] t.tel_2 = r['TEL_NR2'] t.fax = r['FAX_NR'] t.email = r['E_MAIL'] t.website = r['WEBSITE'] t.city = r['CITY'] t.suburb = r['SUBURB'] t.owner = campaign.owner t.campaign = campaign t.save() t.province.add(Province.from_str(r['PROVINCE'])) t.sites.add(Site.objects.get_current()) t.publish()
def process_jobs(category_tuple, jobs_parser, province): current_site = Site.objects.get_current() url, category = category_tuple articles = jobs_parser(url=url).parse() for date, source, text in articles: hash_key = md5_constructor( ':'.join([date, source, text])).hexdigest() date_with_year = ('%s-%s' % (date, datetime.now().strftime('%Y'))) date = datetime.strptime(date_with_year, '%d-%m-%Y') job, created = Job.objects.get_or_create(hash_key=hash_key) if created: job.title = text[:80] job.description = '%s -- %s' % (text, source) job.category = category_from_str(category) job.state = 'published' job.created = date job.publish_on = date job.province = [Province.from_str(province)] job.sites.add(current_site) job.save()