def contactSendEmail(request): """ Receives the email data via ajax and sends an email /libs/agency/contact_me.js is the front end code talking to this function Returns a 404 or 200 """ name = request.GET.get('name', '') email = request.GET.get('email', '') message = request.GET.get('message', '') topic = request.GET.get('topic', '') if name and email and message: # then all data have been entered try: subject = "[www.liquidquotes.com] New mail from %s " % email final_message = """[This is a message sent using the contact form on www.liquidquotes.com] Sender: %s Email: %s Topic: %s --------------------------------- Message: %s """ % (name, email, topic, message) send_mail(subject, final_message, "*****@*****.**", ['*****@*****.**'], fail_silently=False) success = True except Exception, e: printdebug("contactSendEmail > ", str(e)) success = False pass
def create_koncepts(formset, user): """ """ snippets_out, d1 = [], None for form in formset: if form.cleaned_data['doimport']: # if the checkbox is True # reuse a document with exact same name, if available test = Document.objects.filter(title=form.cleaned_data['source'], created_by=user) if test: d1 = test[0] printdebug("Import > found existing Document ID %d (total docs matching title: %d)" % (d1.id, len(test))) else: d1 = Document(title=form.cleaned_data['source'], created_by=user) printdebug("Import > created new Document (title: <%s>)" % (form.cleaned_data['source'])) d1.save() # so to force the updated date # always create new fragment obj f1 = Fragment(text=form.cleaned_data['frag'], location=form.cleaned_data['location'], created_by=user) f1.source = d1 f1.save() snippets_out += [f1] # if a koncept is provided, create an interpretation too koncept_title = form.cleaned_data['name'] if koncept_title: # reuse a koncept with exact same name, if available try: k1 = Koncept.objects.get(name__iexact=koncept_title, created_by=user) k1.updated_at = datetime.today() except: #the prob is here: #maybe use searchdict['name_url'] = url_encode(koncept_name) ??? # print "here" + " " + str(koncept_title) k1 = Koncept(name=koncept_title, created_by=user) k1.save() # new interpretation defaultPrivate = user.userprofile.defaultPrivateKoncepts int1 = IntFrag(koncept=k1, fragment=f1, isprivate=defaultPrivate, created_by=user) int1.save() return [snippets_out, d1]
def delete_fragment(request): """ Delete a fragment attached to a koncept November 17, 2015: updated so that subjects are used instead of tags February 15, 2015: Updated and simplified. Fragments are deleted in isolation, without touching any other objects. Only tags are checked for cascade deletion. February 21, 2014: The related koncept is deleted only if the koncept is an orphan If the related source is an orphan, it gets deleted too. June 27, 2014 islinked : flag to differentiate from delete on fragments+intfrags from single fragments """ fragment_id = request.GET.get('fid', None) return_page = request.GET.get('page', None) # not implemented in front end yet document, old_document_id = None, None user = request.user fragment = get_object_or_404(Fragment, pk=int(fragment_id), created_by=user) if fragment.source: old_document_id = fragment.source.id old_subjects = list(fragment.subjects.all()) fragment.source = None fragment.subjects.clear() for intfrag in fragment.intfrag_set.all(): # remove associations to koncepts intfrag.delete() # finally: fragment.delete() printdebug("===Deleted=== fragment %s" % fragment_id) # clean up relations Subject.cleanUpUserSubjects(user, old_subjects) if old_document_id: document = Document.objects.get(pk=old_document_id) document.cleanOrdering() _message = "Delete operation successfull." messages.success(request, _message) if document: return HttpResponseRedirect(reverse('get_document' , args=(user.username, document.id))) # return HttpResponseRedirect('%s' % document.get_absolute_url()) else: return HttpResponseRedirect(reverse('search_user_quotes' , args=(user.username,)))
def handle(self, *args, **options): """ args - args options - configurable command line options """ # feedback: print "\n\n++ = ++ = ++ = ++ = ++ = ++ = ++ = ++\n%s\nSTARTING :" % strftime("%Y-%m-%d %H:%M:%S") print "MAYBE BEFORE RUNNING THIS YOU MIGHT WANT TO DISABLE SOME SAVING BEHAVIOURS YOU HAVE SET......eg FLORUITS" print "++ = ++ = ++ = ++ = ++ = ++ = ++ = ++\n" if args: for a in args: printdebug("Argument provided: ==%s==" % str(a)) # now do the actions: # 1) fixture description if '1' in args: # do something pass # 2) fixture description if '2' in args: # do something pass # 3) fixture description if '3' in args: # do something pass # 4) fixture description if '4' in args: # do something pass printdebug("************\nCOMPLETED\n************")
def _prePopulateEditDocumentForm(d1): """ Logic very similar to the one in 'new.py' Note: this is returned only if a user is looking at his own document. """ dict1 = {} dict1['sourcetitle'] = d1.title dict1['sourceurl'] = d1.url dict1['sourceauthor'] = d1.author dict1['sourcepubyear'] = d1.pubyear dict1['sourcedesc'] = d1.description form = NewDocumentForm(dict1) if form.is_valid(): printdebug(form.data['sourcedesc']) else: printdebug(form.errors) return form
def alreadyExistingFrag(frag, user): """ Checks if a fragment with same exact content already exists Returns the first related fragment/document found June 23, 2014: updated so that it checks for fragments directly, not Koncepts! """ try: # k1 = Koncept.objects.filter(intfrag__fragment__text__istartswith=frag[:100], created_by=user) # if k1: # return "WARNING: this snippet already exists! <br />See <a class='konceptcolor' href='%s' target='_blank'>%s</a>" % (k1[0].get_absolute_url(), k1[0].name.upper()) # else: # return "" duplicate = Fragment.objects.filter(created_by=user, text__istartswith=frag[:100]) if duplicate: return "Heads Up! Haven't you saved this fragment already? <br />Please check the source: <a class='text-danger' href='%s' target='_blank'>%s</a>" % (duplicate[0].source.get_absolute_url(), duplicate[0].source.title.upper()) else: return "" except: k1 = None printdebug("Error: import.py/alreadyExistingFrag raised an exception!") return ""
def edit_koncept_quotes_order(request, kon_id): """ Ajax action for modifying the ordeno of a fragment within a koncept IntFrag.orderno """ user = request.user ## in the future we'll have to handle username too results = [] # make sure the user owns the Koncept, or raise a permissions error try: k1 = Koncept.objects.get(pk=kon_id, created_by=user) except: return HttpResponseForbidden() ukeys = request.GET.getlist('o[]') if k1 and ukeys: for x in range(len(ukeys)): try: i = IntFrag.objects.get(koncept=k1, fragment__id=ukeys[x], created_by=user) # print i.fragment.id i.orderno = x+1 # because the iterator is zero-based i.save() except: printdebug("== Error updating collection-quote order for %s" % str(k1)) k1.cleanIntFragOrdering() results = { 'new_url': k1.get_absolute_url() } json = simplejson.dumps(results) return HttpResponse(json, mimetype='application/json') # if it fails return HttpResponse("")
def edit_source_quotes_order(request, doc_id): """ Ajax action for modifying the ordeno of a fragment within a source @todo: only stubbed on 2015-03-12 """ user = request.user ## in the future we'll have to handle username too results = [] # make sure the user owns the Document, or raise a permissions error try: d1 = Document.objects.get(pk=doc_id, created_by=user) except: return HttpResponseForbidden() ukeys = request.GET.getlist('o[]') if d1 and ukeys: for x in range(len(ukeys)): try: f = Fragment.objects.get(source=d1, id=ukeys[x], created_by=user) # print i.fragment.id f.orderno = x+1 # because the iterator is zero-based f.save() except: printdebug("== Error updating source-quote order for %s" % str(d1)) d1.cleanOrdering() results = { 'new_url': d1.get_absolute_url() } json = simplejson.dumps(results) return HttpResponse(json, mimetype='application/json') # if it fails return HttpResponse("")
def update_memory(request, ksearch_history, fsearch_history, record_history): path = request.path # KEYWORD SEARCH PAGE if path.find('/db/search') >= 0: query = request.GET.get('query', False) basic_search_type = request.GET.get('basic_search_type', False) if query and basic_search_type: newdict = {'query' : query, 'basic_search_type' : basic_search_type} if ksearch_history: if newdict not in ksearch_history: ksearch_history.insert(0, newdict) if len(ksearch_history) > 20: ksearch_history.pop() else: ksearch_history = [newdict] return [ksearch_history, fsearch_history, record_history] # FACETED SEARCH PAGE elif path.find('/db/faceted') >= 0: printdebug("Context Processor: ..... detected call to faceted page .... but handler still not implemented....") # AJAX calls don't come through here!!!!!!!!!! # the dict element 'fsearch_history' is left untouched.... return None # RECORD PAGE elif path.find('/db/record') >= 0: lista = path.split("/") try: # if True: number = int(lista[-2]) # even though the number seems in last position, it's the penultimate rectype = lista[-3] try: if rectype == 'document': name = Document.objects.filter(id=number).values('title')[0]['title'] elif rectype == 'event': name = Event.objects.filter(id=number).values('short_title')[0]['short_title'] elif rectype == 'person': name = nicename(Person.objects.get(id=number)) elif rectype == 'troupe': name = Troupe.objects.filter(id=number).values('name')[0]['name'] elif rectype == 'venue': name = Venue.objects.filter(id=number).values('name')[0]['name'] elif rectype == 'emlot-record': name = "" except: name = "[error retrieving name]" newdict = {'number' : number, 'type' : rectype, 'name' : name} if record_history: if newdict not in record_history: record_history.insert(0, newdict) if len(record_history) > 20: record_history.pop() else: record_history = [newdict] except: pass # printdebug("noise") # printdebug(record_history) return [ksearch_history, fsearch_history, record_history] else: return None
def changeQuoteKoncept(request): """ ajax call attaches a new Koncept to a Quote. If there was an old koncept, that is left as it is. However if the old koncept has no interpretations left, it is deleted. """ user = request.user k_old = None try: quoteid = int(request.GET.get('quoteid', False)) f1 = Fragment.objects.get(pk=int(quoteid), created_by=user) except: return HttpResponse("Fragment ID not matches users data") try: newname = request.GET.get(u'name', False) except: newname = "" if request.method == "GET": if newname.strip() and not(newname.isdigit()): # reuse a koncept with exact same name, if available try: k1 = Koncept.objects.get(name=newname, created_by=user) k1.updated_at = datetime.today() except: k1 = Koncept(name=newname, created_by=user) k1.save() intfrag = f1.get_interpretation() if intfrag: k_old = intfrag.koncept intfrag.koncept=k1 intfrag.fragment=f1 intfrag.updated_at = datetime.today() else: intfrag = IntFrag(koncept=k1, fragment=f1, created_by=user) intfrag.save() # if koncept is an orphan, delete it! if k_old: if k1.id != k_old.id: if k_old.intfrag_set.count(): k_old.cleanIntFragOrdering() else: printdebug("Deleting Koncept %s" % str(k_old)) k_old.delete() results = { 'saved_name': newname.capitalize(), 'new_url' : k1.get_absolute_url(), 'page_flag' : 'new', } json = simplejson.dumps(results) return HttpResponse(json, mimetype='application/json') # if it fails return HttpResponse("Some error occurred. Most probably name is not empty or contains only digits")
def handle(self, *args, **options): """ args - args options - configurable command line options """ # feedback: print "\n\n++ = ++ = ++ = ++ = ++ = ++ = ++ = ++\n%s\nSTARTING :" % strftime("%Y-%m-%d %H:%M:%S") print "MAYBE BEFORE RUNNING THIS YOU MIGHT WANT TO DISABLE SOME EXTRA-SAVING ACTIONS......" print "++ = ++ = ++ = ++ = ++ = ++ = ++ = ++\n" if args: for a in args: printdebug("Argument provided: ==%s==" % str(a)) # now do the actions: # 1) # .... if '1' in args: # mpasin = User.objects.get(username="******") print "\n......Showing Documents with same title\n" for x in Document.objects.all(): if Document.objects.exclude(id=x.id).filter(title=x.title, ): print x.id, x.title # NOTE: this must be run manually by setting the caller below # essentially cause I don't know how to pass more than one args to the python func def mergedocs(idkeep): """ gets doc ID; retrieves similar docs and merges into it """ dkeep = Document.objects.get(pk=idkeep) others = Document.objects.exclude(id=idkeep).filter(title=dkeep.title) for el in others: for frag in el.fragment_set.all(): frag.source = dkeep print "...transferring", frag.id, frag frag.save() print "deleting", el.id, el el.delete() # mergedocs(130) if '2' in args: # mpasin = User.objects.get(username="******") print "\n......Showing Documents with no interpretations attached\n" for x in Document.objects.filter(fragment__intfrag=None): print x.id, x.title if '21' in args: # mpasin = User.objects.get(username="******") print "\n......Deleting Documents with no interpretations attached\n" for x in Document.objects.filter(fragment__intfrag=None): print x.id, x.title try: x.fragment.delete() x.delete() except: x.delete() # March 21, 2014: fill in the orderno field for IntFrags # python manage.py dataclean 3 if '3' in args: for x in Koncept.objects.all(): x.cleanIntFragOrdering() # 2014-10-17: cascade privacy from intfrags to snippets # python manage.py dataclean 4 if '4' in args: for x in Fragment.objects.all(): intfrags = x.intfrag_set.all() if len(intfrags) < 1: print "Fragment %d is an orphan => setting it as private" % x.id privacy = True if len(intfrags) > 1: print "Fragment %d has more than one intepretation => taking the first one" % x.id privacy = intfrags[0].isprivate if len(intfrags) == 1: privacy = intfrags[0].isprivate x.isprivate = privacy x.save() # 2014-12-30: bootstrap titles and clean koncepts with <2 quotes # python manage.py dataclean 5 if '5' in args: for x in Fragment.objects.all(): k1 = x.get_koncept() if k1: x.title = k1.name print "Fragment %d is being saved => title=%s" % (x.id, x.title) x.save() if True: # delete koncept/intfrag if it has <2 quotes if k1.intfrag_set.count() < 2: for intfrag in k1.intfrag_set.all(): fragment, tags = intfrag.fragment, list(intfrag.tags.all()) print "Koncept %d is being deleted => title=%s" % (k1.id, k1.name) intfrag.delete() k1.delete() # remove orphan tags too for t in tags: if not t.intfrag_set.all(): printdebug("Cleaning tag %s" % t) t.delete() # 2015-02-13: bootstrap order field in sources # python manage.py dataclean 6 if '6' in args: for d in Document.objects.all(): counter = 0 for f in d.fragment_set.all().order_by('created_at'): counter += 1 f.orderno = counter f.save() print "==FRAG== : ", f.id, "-- order=", counter # 2015-02-14: check if any tags are reused across users and recreates them # python manage.py dataclean 7 if '7' in args: for i in IntFrag.objects.all(): if i.tags.all(): for x in i.tags.all(): if x.created_by != i.created_by: print x, "=== Owned by ===", x.created_by, "==== but infrag is ===", i.created_by new = Tag.objects.get_or_create(name=x.name, created_by=i.created_by)[0] i.tags.remove(x) i.tags.add(new) # 2015-02-14: remove tags from old location on intfrags # python manage.py dataclean 8 if '8' in args: for i in IntFrag.objects.all(): if i.tags.all(): print "=== Clearing intfrag ===", i.id i.tags.clear() # 2015-02-14: delete tags with no fragments # python manage.py dataclean 9 if '9' in args: for x in Tag.objects.all(): if not x.fragment_set.all(): print "=== Deleting tag ===", x x.delete() # 2015-05-04: remove collections with only 1 fragments # python manage.py dataclean 9 if '10' in args: for x in Fragment.objects.filter(created_by__id=1): k1 = x.get_koncept() if k1: # delete koncept/intfrag if it has <2 quotes if k1.intfrag_set.count() < 2: for intfrag in k1.intfrag_set.all(): fragment = intfrag.fragment print "Koncept %d is being deleted => title=%s" % (k1.id, k1.name) if x.title: if x.title[:(len(x.title)-3)] in x.text: x.title = k1.name print "Fragment %d is being saved => title=%s" % (x.id, x.title) x.save() intfrag.delete() k1.delete() # 2015-11-17: remove all tags (now in 'subject') # python manage.py dataclean 11 if '11' in args: for f in Fragment.objects.all(): if f.tags.all(): print "=== Cleaning subjects from fragment ===", f f.tags.clear() for x in Tag.objects.all(): print "=== Deleting tag ===", x x.delete() printdebug("\n************\nCOMPLETED\n************")
def handle(self, *args, **options): """ args - args options - configurable command line options """ # feedback: print "\n\n++ = ++ = ++ = ++ = ++ = ++ = ++ = ++\n%s\nSTARTING CREATING DB:" % strftime( "%Y-%m-%d %H:%M:%S") print "++ = ++ = ++ = ++ = ++ = ++ = ++ = ++\n" # now do the actions: if True: myFile = open("religion_data.csv", 'rU') reader = csv.reader(myFile) # ==> outputs lists # EG of data: # ['IDB Region', 'WorldFactbook region', 'Country', 'pop2000', 'pop2008', '', 'Country', 'Christian', 'Muslim', 'Hindu', 'Buddhist', 'Other/UnSpecified', 'Jewish', 'None', '', 'Main Religion', 'subgroups or other religions.', '', '', '', '', '', '', '', '', '', '', ''] # ['ASIA (EXCLUDING NEAR EAST) ', # 'Asia', # 'Afghanistan ', # '23898198', # '32738376', # '', [5] # 'Afghanistan', # '', # '99.0%', # '', # '', [10] # '1.0%', # '', # '', # '', # 'Muslim', [15] # 'Sunni Muslim 80%', ' Shia Muslim 19%', ' other 1%', '', '', '', '', '', '', '', '', ''] for row in reader: if row: # 1. extract the regions print "*" * 50, "\n", row, "\n", "*" * 50 regionname = row[1].strip() regionidbname = row[0].strip() if Region.objects.filter(name=regionname, idbname=regionidbname): region = Region.objects.get(name=regionname, idbname=regionidbname) print "++++++++++++++++++++++++++ found existing obj: %s" % ( region) else: region = Region(name=regionname, idbname=regionidbname) region.save() countryname = row[6].strip() if countryname: country = get_or_new(Country, countryname) if row[3].strip(): country.pop2000 = float(row[3].strip()) if row[4].strip(): country.pop2008 = float(row[4].strip()) country.inregion = region country.save() # 2. extract the religions for number in range(16, 28): try: religionfield = row[number].strip() except: religionfield = None printdebug("Row number not accepted! --%s--" % number) if religionfield: religionname = " ".join([ x for x in row[number].strip().split(" ") if not "%" in x ]) religionpercent = " ".join([ x for x in row[number].strip().split(" ") if "%" in x ]) numberstring = religionpercent.replace("%", "") try: number = float(numberstring) except: number = None printdebug( "Count'd extract number from --%s--" % numberstring) if religionname: religion = get_or_new(Religion, religionname) rr = ReligionInCountry(country=country, religion=religion, percentage=number) rr.save() print "\n" myFile.close() printdebug("************\nCOMPLETED\n************")
def handle(self, *args, **options): """ args - args options - configurable command line options """ # feedback: print "\n\n++ = ++ = ++ = ++ = ++ = ++ = ++ = ++\n%s\nSTARTING CREATING DB:" % strftime("%Y-%m-%d %H:%M:%S") print "++ = ++ = ++ = ++ = ++ = ++ = ++ = ++\n" # now do the actions: if True: myFile = open("religion_data.csv", 'rU') reader = csv.reader(myFile) # ==> outputs lists # EG of data: # ['IDB Region', 'WorldFactbook region', 'Country', 'pop2000', 'pop2008', '', 'Country', 'Christian', 'Muslim', 'Hindu', 'Buddhist', 'Other/UnSpecified', 'Jewish', 'None', '', 'Main Religion', 'subgroups or other religions.', '', '', '', '', '', '', '', '', '', '', ''] # ['ASIA (EXCLUDING NEAR EAST) ', # 'Asia', # 'Afghanistan ', # '23898198', # '32738376', # '', [5] # 'Afghanistan', # '', # '99.0%', # '', # '', [10] # '1.0%', # '', # '', # '', # 'Muslim', [15] # 'Sunni Muslim 80%', ' Shia Muslim 19%', ' other 1%', '', '', '', '', '', '', '', '', ''] for row in reader: if row: # 1. extract the regions print "*" * 50, "\n", row, "\n", "*" * 50 regionname = row[1].strip() regionidbname = row[0].strip() if Region.objects.filter(name= regionname, idbname = regionidbname): region = Region.objects.get(name= regionname, idbname = regionidbname) print "++++++++++++++++++++++++++ found existing obj: %s" % (region) else: region = Region(name= regionname, idbname = regionidbname) region.save() countryname = row[6].strip() if countryname: country = get_or_new(Country, countryname) if row[3].strip(): country.pop2000 = float(row[3].strip()) if row[4].strip(): country.pop2008 = float(row[4].strip()) country.inregion = region country.save() # 2. extract the religions for number in range(16, 28): try: religionfield = row[number].strip() except: religionfield = None printdebug("Row number not accepted! --%s--" % number) if religionfield: religionname = " ".join([x for x in row[number].strip().split(" ") if not "%" in x]) religionpercent = " ".join([x for x in row[number].strip().split(" ") if "%" in x]) numberstring = religionpercent.replace("%", "") try: number = float(numberstring) except: number = None printdebug("Count'd extract number from --%s--" % numberstring) if religionname: religion = get_or_new(Religion, religionname) rr = ReligionInCountry(country=country, religion=religion, percentage=number) rr.save() print "\n" myFile.close() printdebug("************\nCOMPLETED\n************")
def handle(self, *args, **options): """ args - args options - configurable command line options """ # feedback: print "\n\n++ = ++ = ++ = ++ = ++ = ++ = ++ = ++\n%s\nSTARTING :" % strftime("%Y-%m-%d %H:%M:%S") print "MAYBE BEFORE RUNNING THIS YOU MIGHT WANT TO DISABLE SOME EXTRA-SAVING ACTIONS......" print "++ = ++ = ++ = ++ = ++ = ++ = ++ = ++\n" if args: for a in args: printdebug("Argument provided: ==%s==" % str(a)) # now do the actions: # 1) # .... if '1' in args: mpasin = User.objects.get(username="******") # ITERATE ONE INTERPRETATION AT A TIME # for i in Interpretation.objects.all()[:100]: for i in Interpretation.objects.all(): # TERMS => KONCEPTS koncept, created = Koncept.objects.get_or_create(name=i.term1.name, created_by=mpasin, updated_by=mpasin,) koncept.save() # in order to apply the on-save method! print "*KONCEPT* : ", koncept, "-- created=", created print "===url==> ", koncept.name_url # SOURCES => DOCUMENTS if i.sourcefk: document, created = Document.objects.get_or_create(title=i.sourcefk.title, author=i.sourcefk.author, description=i.sourcefk.description, pubyear=i.sourcefk.pubyear, url=i.sourcefk.url, created_by=mpasin, updated_by=mpasin,) document.save() print "DOCUMENT :", document, "--", created print "===url==> ", document.name_url else: document = None print "===Document not available===" # CONTEXTS => TAGS tags_list = [] if i.context.all(): for c in i.context.all(): tag, created = Tag.objects.get_or_create(name=c.name, description=c.description, created_by=mpasin, updated_by=mpasin,) tag.save() print "#TAG: ", tag, "--", created print "===url==> ", tag.name_url tags_list += [tag] # INTERPRETATIONS ==> FRAGMENT + INTFRAG # SENSE => FRAGMENT if i.term1.language: language, created = Languages.objects.get_or_create(name=i.term1.language.name, created_by=mpasin, updated_by=mpasin,) else: language = None fragment, created = Fragment.objects.get_or_create(text=i.sense, source=document, ismine=i.ismine, isdictionary=i.isdictionary, language=language, created_by=mpasin, updated_by=mpasin,) print "FRAGMENT : ", fragment, "-- created=", created # INT => INTFRAG intfrag, created = IntFrag.objects.get_or_create(koncept=koncept, fragment=fragment, created_by=mpasin, updated_by=mpasin,) for t in tags_list: intfrag.tags.add(t) print "==INTFRAG== : ", intfrag, "-- created=", created # 2015-02-13: evolve tags model # python manage.py transfer 2 if '2' in args: for x in IntFrag.objects.all(): if x.tags.all() and x.fragment: x.fragment.tags.clear() for t in x.tags.all(): print "==FRAG== : ", x.fragment.id, "-- tag=", t x.fragment.tags.add(t) # 2015-08-11: bootstrap subject model # python manage.py transfer 3 if '3' in args: if False: Subject.objects.all().delete() for x in Koncept.objects.all(): print "reading koncept %d" % x.id try: s = Subject.objects.filter(name=x.name, created_by=x.created_by)[0] print "....found existing", x.name except: s = Subject() s.name = x.name s.name_url = x.name_url s.description = x.description s.created_by = x.created_by s.updated_by = x.updated_by s.created_at = x.updated_at s.updated_at = x.updated_at s.save() for frag in x.get_fragments(): frag.subjects.add(s) for x in Tag.objects.all(): print "reading tag %d" % x.id try: s = Subject.objects.filter(name=x.name, created_by=x.created_by)[0] print "....found existing", x.name except: s = Subject() s.name = x.name s.name_url = x.name_url s.description = x.description s.created_by = x.created_by s.updated_by = x.updated_by s.created_at = x.updated_at s.updated_at = x.updated_at s.save() for frag in x.fragment_set.all(): frag.subjects.add(s) printdebug("************\nCOMPLETED\n************")