Exemplo n.º 1
0
    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
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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))
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
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))
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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))
Exemplo n.º 9
0
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
Exemplo n.º 10
0
 def save(self, *args, **kwargs):
     if not self.key:
         self.key = get_random_hash(self.email)
     return super(Schedule, self).save(*args, **kwargs)
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
 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