def save(self, user, commit=True): name = self.cleaned_data['name'] new_set = Tag(name=name, slug=utils.get_random_hash(name), sort_key=name.lower(), category='set', user=user) new_set.save() return new_set
def new_poem(request): user = request.user if request.user.is_authenticated() else None text = Poem.write() p = Poem(slug=get_random_hash(text), text=text, created_by=user) p.save() return render_to_response('lesmianator/poem.html', {"poem": p}, context_instance=RequestContext(request))
def get_set(user, name): """Returns a tag for use by the user. Creates it, if necessary.""" try: tag = Tag.objects.get(category='set', user=user, name=name) except Tag.DoesNotExist: tag = Tag.objects.create(category='set', user=user, name=name, slug=utils.get_random_hash(name), sort_key=name.lower()) return tag
def poem_from_book(request, slug): book = get_object_or_404(Book, slug=slug) user = request.user if request.user.is_authenticated() else None text = Poem.write(Continuations.get(book)) p = Poem(slug=get_random_hash(text), text=text, created_by=user) p.created_from = [book.id] p.save() return render_to_response('lesmianator/poem.html', {"poem": p, "books": [book], "book": book}, context_instance=RequestContext(request))
def poem_from_set(request, shelf): user = request.user if request.user.is_authenticated() else None tag = get_object_or_404(Tag, category='set', slug=shelf) text = Poem.write(Continuations.get(tag)) p = Poem(slug=get_random_hash(text), text=text, created_by=user) books = Book.tagged.with_any((tag,)) p.created_from = [b.id for b in books] p.save() book = books[0] if len(books) == 1 else None return render_to_response('lesmianator/poem.html', {"poem": p, "shelf": tag, "books": books, "book": book}, context_instance=RequestContext(request))
def get_set(user, name): """Returns a tag for use by the user. Creates it, if necessary.""" try: tag = Tag.objects.get(category='set', user=user, name=name) except Tag.DoesNotExist: tag = Tag.objects.create( category='set', user=user, name=name, slug=utils.get_random_hash(name), sort_key=name.lower()) except Tag.MultipleObjectsReturned: # fix duplicated noname shelf tags = list(Tag.objects.filter(category='set', user=user, name=name)) tag = tags[0] for other_tag in tags[1:]: for item in other_tag.items.all(): Tag.objects.remove_tag(item, other_tag) Tag.objects.add_tag(item, tag) other_tag.delete() return tag
def save(self, *args, **kwargs): if not self.key: self.key = get_random_hash(self.email) return super(Schedule, self).save(*args, **kwargs)
def save(self, *args, **kwargs): if self.email and not self.notify_key: self.notify_key = get_random_hash(self.email) ret = super(Funding, self).save(*args, **kwargs) self.offer.flush_includes() return ret