def test_unique_slugify(self): self.assertEqual(unique_slugify('This % is a test ---'), 'This-is-a-test') self.assertEqual(unique_slugify('- - -This -- is a ## test ---'), 'This-is-a-test-1') self.assertEqual(unique_slugify('_this_is_a__test___'), 'this-is-a-test')
def save(self, *args, **kwargs): unique_slugify(self, self.title) # Markdown part from http://www.yaconiello.com/blog/part-1-creating-blog-system-using-django-markdown self.content_markup = markdown(self.content) self.ingredients_markup = markdown(self.ingredients) super(Recipe, self).save(*args, **kwargs)
def generate(dsn): """ Generate taskjuggler files from trac """ now = datetime.now() prj_start = now - timedelta(minutes=now.minute) + timedelta(hours=1) min_mst_due = prj_start + timedelta(days=1) min_mst_due = datetime.strftime(min_mst_due, "%Y-%m-%d") getBlockingTickets(dsn) records = selectWithSQLRequest(dsn, query, TRACE=TRACE) #verbose("Records number: %d" % len(records)) print >> sys.stderr, "# Records number: %d<br />" % len(records) #("URBAN - DEV - Permis d'environnement classe 1", '2012-12-31', 5340, 'Ajouter le champ "Secteur d\'activit\xc3\xa9"', #'NOUVEAU', 'sdelcourt', 'Urbanisme communes (URBAN)', Decimal('0.0'), Decimal('0'), "data grid avec au moins ") tickets_nb = 0 for rec in records: (mst, mst_due, id, summary, status, owner, prj, estimated, hours, description) = rec estimated = float(estimated) hours = float(hours) try: mst_list = mst.split(' - ') (mst_prj, mst_wrk) = (mst_list[0], mst_list[1]) if mst_prj not in PROJECTS: herror("Project '%s' not well extracted from '%s' (%s, %s)" % (mst_prj, mst, owner, a_link(TICKET_URL, id))) except: herror("Project cannot be extracted from '%s' (%s, %s)" % (mst, owner, a_link(TICKET_URL, id))) #due = datetime.strptime(mst_due, '%Y/%m/%d').date() # We skip unfollowed projects !! if mst_prj not in PROJECTS_TO_KEEP: continue tickets_nb += 1 if mst_prj not in msts_due: msts_due[mst_prj] = {} if mst_wrk not in msts_due[mst_prj]: msts_due[mst_prj][mst_wrk] = {} if mst_due not in msts_due[mst_prj][mst_wrk]: msts_due[mst_prj][mst_wrk][mst_due] = [] mst = mst.decode('utf8') if mst not in msts: mstid = unique_slugify(mst, separator='_', unique_id=True).encode('utf8') msts[mst] = { 'prj': mst_prj, 'due': (mst_due <= min_mst_due and min_mst_due or mst_due), 't': [], 'own': {}, 'wrk': mst_wrk, 'dep': [], 'id': mstid, 'prty': 1 } msts_due[mst_prj][mst_wrk][mst_due].append(mst) msts[mst]['t'].append(id) if id in tkts: herror("Ticket '%s' already found in dict %s (%s, %s)" % (id, tkts[id], owner, a_link(TICKET_URL, id))) continue if not owner: herror("Ticket '%s' has no owner (%s)" % (id, a_link(TICKET_URL, id))) tkts[id] = { 'sum': summary, 'status': status, 'owner': owner, 'prj': prj, 'estim': estimated, 'hours': hours, 'mst': mst } if owner not in msts[mst]['own']: msts[mst]['own'][owner] = {'effort': 0.0, 't': [], 'done': 0.0} msts[mst]['own'][owner]['t'].append(id) msts[mst]['own'][owner]['done'] += hours if owner not in resources: resources[owner] = {'res': 'cust', 'prj': []} if mst_prj not in resources[owner]['prj']: resources[owner]['prj'].append(mst_prj) if estimated == 0: herror("Estimated hour not set for ticket (%s, %s)" % (owner, a_link(TICKET_URL, id))) continue elif hours == 0: msts[mst]['own'][owner]['effort'] += estimated elif hours > estimated: msts[mst]['own'][owner]['effort'] += (estimated * EFFORT_EXCEED_FACTOR) else: msts[mst]['own'][owner]['effort'] += (estimated - hours) # calculate mst order: set the priority for prj in msts_due: for wrk in msts_due[prj]: p = 1000 for due in sorted(msts_due[prj][wrk]): # sorted by due date for mst in msts_due[prj][wrk][due]: if p > 1: msts[mst]['prty'] = p else: msts[mst]['prty'] = 1 p -= 50 # find blocking milestone from blocking tickets for mst in msts: for tkt in msts[mst]['t']: if tkt not in tkts_links: continue # no blocking for blck in tkts_links[tkt]: if not blck in tkts: herror( "Blocking ticket '%s' not found in due milestone tickets" % (a_link(TICKET_URL, blck))) continue blck_mst = msts[tkts[blck]['mst']]['id'] # skipping self milestone dependency if tkts[blck]['mst'] != mst and blck_mst not in msts[mst][ 'dep']: msts[mst]['dep'].append(blck_mst) # group resources resources_gp = {'dll': [], 'ext': [], 'cust': []} for usr in sorted(resources.keys()): res = resources[usr].pop('res') if res != 'dll' and not resources[usr]['prj']: continue resources_gp[res].append((usr, resources[usr])) verbose("Records number: %d, Tickets number: %d" % (len(records), tickets_nb)) print >> sys.stderr, "# Tickets number: %d<br />" % tickets_nb # generate trac.tjp file template = env.get_template('trac.tjp') rendered = template.render( prj_start=datetime.strftime(prj_start, "%Y-%m-%d-%H:%M")) write_to(outfiles, 'tjp', rendered.encode('utf8')) # generate resources.tji getLeaves(dsn) template = env.get_template('resources.tji') rendered = template.render(leaves=leaves, resources=resources_gp, prjs=msts_due) write_to(outfiles, 'resources', rendered.encode('utf8')) # generate reports.tji template = env.get_template('reports.tji') rendered = template.render(prjs=msts_due) write_to(outfiles, 'reports', rendered.encode('utf8')) # generate tasks.tji template = env.get_template('tasks.tji') rendered = template.render(prjs=msts_due, msts=msts) write_to(outfiles, 'tasks', rendered.encode('utf8')) close_outfiles(outfiles)
def save_slug(sender, instance, *args, **kwargs): instance.slug = unique_slugify(instance.name)
def save(self, **kwargs): unique_slugify(self, self.name) super(Category, self).save()
def save(self, **kwargs): unique_slugify(self, self.name) super(Source, self).save()