Exemplo n.º 1
0
    def test_required(self):
        form  = AuthorForm(data={}, user=self.author.user)

        self.assertFieldsConfigured(form)
        self.assertEqual(self.author.user, form.user)

        self.assertFalse(form.is_valid())
        self.assertDictEqual({'name': ['This field is required.']}, form.errors)
Exemplo n.º 2
0
def store(request):
    if request.method == "POST":
        form = AuthorForm(request.POST)
        if form.is_valid():
            try:
                form.save()
            except Exception as e:
                pass
    return redirect('/authors')
Exemplo n.º 3
0
def authornew(request):
    form = AuthorForm(request.POST or None)

    if form.is_valid():
        form.save()
        return redirect('author:list')

    return render_to_response("authors/authornew.html", {
        'form': form
    }, context_instance=RequestContext(request))
Exemplo n.º 4
0
	def post(self, *args, **kwargs):
		data = {}
		form_author = AuthorForm(self.request.POST)
		if form_author.is_valid():
			author_obj = form_author.save(commit=True)
			data['message'] = 'success'
			data['object created'] = serialize('json', [author_obj])
		else:
			data['message'] = 'failure'
		return JsonResponse(data, safe=False)
Exemplo n.º 5
0
def authoredit(request, pk):
    author = get_object_or_404(Author, pk=pk)
    form = AuthorForm(request.POST or None, instance=author)

    if form.is_valid():
        form.save()
        return redirect("author:detail", pk=author.id)
    return render_to_response("authors/authoredit.html", {
        'author': author,
        'form': form
    }, context_instance=RequestContext(request))
Exemplo n.º 6
0
def contest(request, slug):
    contest = Competition.objects.get(slug=slug)
    author = None
    author_form = AuthorForm(request.POST or None)

    if author_form.is_valid():
        author = author_form.save()
        return redirect('submit_entry', slug=contest.slug, email=author.email)

    return render(
        request, "contest/contest.html",
        dict(contest=contest, author_form=author_form))
Exemplo n.º 7
0
def edit_author_view(request, author_id):
    author_list = Author.objects.get(id=author_id)
    author_form = AuthorForm(instance=author_list)
    if request.POST:
        author_form = AuthorForm(request.POST, instance=author_list)
        if author_form.is_valid():
            author_form.save()
            return redirect("create_author")
    return render_to_response("edit_author.html", RequestContext(request, {
        "author_list": author_list,
        "author_form": author_form,
        }))
Exemplo n.º 8
0
def create_author_view(request):
    author_list = Author.objects.all()
    author_form = AuthorForm()
    if request.POST:
        author_form = AuthorForm(request.POST)
        if author_form.is_valid():
            author_form.save()
            return redirect("create_author")
    return render_to_response("create_author.html", RequestContext(request, {
        "author_list": author_list,
        "author_form": author_form,
        }))
Exemplo n.º 9
0
	def put(self, *args, **kwargs):
		data = {}
		author_obj = get_object(self.kwargs.get('pk'))
		passed_data = json.loads(self.request.body)
		if author_obj:
			form_author = AuthorForm(passed_data, instance=author_obj)
			if form_author.is_valid():
				form_author.save()
				data['message'] = 'success'
				data['object created'] = serialize('json', [author_obj])
				return JsonResponse(data, safe=False, status=200)
			else:
				data['message'] = form_author.errors
				return JsonResponse(data, safe=False, status=206)
		else:
			data['message'] = 'Object doesn\'t exists.'
			return JsonResponse(data, safe=False, status=404)
Exemplo n.º 10
0
    def test_create(self):

        # First test a blank form
        form = AuthorForm(user=self.author.user)
        self.assertFieldsConfigured(form)
        self.assertEqual(self.author.user, form.user)

        form = AuthorForm(data={
            "name": "BobbaFet",
            "bio_text": "My **Bio**",
        }, user=self.author.user)

        self.assertFieldsConfigured(form)
        self.assertEqual(self.author.user, form.user)

        saved = form.save()
        self.assertDictEqual({}, form.errors)
        self.assertIsNotNone(saved.id)
        self.assertEqual(saved.user, self.author.user)
Exemplo n.º 11
0
def create_author(request):
    form_author = AuthorForm()
    context = {'form_author': form_author}
    if request.method == 'POST':
        form_author = AuthorForm(request.POST)

        if form_author.is_valid():
            name = request.POST.get('name', )
            surname = request.POST.get('surname', )
            birthYear = request.POST.get('birthYear', )
            facePhoto = request.POST.get('facePhoto', )
            author_obj = Author(name=name,
                                surname=surname,
                                birthYear=birthYear,
                                facePhoto=facePhoto)
            author_obj.save()
            all_authors = Author.objects.all()
            context = {
                'all_authors': all_authors,
            }
        return render(request, 'authors/index.html', context)
    return render(request, 'authors/create_author.html', context)
Exemplo n.º 12
0
def edit_author_view(request, author_id):
    author_list = Author.objects.get(id=author_id)
    author_form = AuthorForm(instance=author_list)
    if request.POST:
        author_form = AuthorForm(request.POST, instance=author_list)
        if author_form.is_valid():
            author_form.save()
            return redirect("create_author")
    return render_to_response(
        "edit_author.html",
        RequestContext(request, {
            "author_list": author_list,
            "author_form": author_form,
        }))
Exemplo n.º 13
0
def create_author_view(request):
    author_list = Author.objects.all()
    author_form = AuthorForm()
    if request.POST:
        author_form = AuthorForm(request.POST)
        if author_form.is_valid():
            author_form.save()
            return redirect("create_author")
    return render_to_response(
        "create_author.html",
        RequestContext(request, {
            "author_list": author_list,
            "author_form": author_form,
        }))
Exemplo n.º 14
0
def create(request):
    form = AuthorForm()
    return render(request, 'authors/add.html', {'form': form})
Exemplo n.º 15
0
def get_author(request, author_guid = None):
    context = RequestContext( request )

    try:
        u = User.objects.get(username=author_guid)
        a = Author.objects.get(user=u)
    except User.DoesNotExist:
        a = Author.objects.get(guid=author_guid)
        u = a.user

    if request.method == "GET":
        loggedInUser = Author.objects.get(user = request.user)
        #in my profile I want to see posts that are private to me
        #posts that are from my friends that are shared as "friends of friends"
        #posts that are shared to me by local_friends

        #posts that are shared to me by global_friends
        #posts that are shared to me by friends of friends

        #friends of author
        friends = Friend.objects.filter( author = Author.objects.get(user=request.user) )

        #Get the posts where the author is the user signed in
        # and also where the author is in the list of friends
        friend_names = [ friend.friend_name for friend in friends ]
        friend_guids = [ friend.friend_guid for friend in friends ]

        users = User.objects.filter(username__in=friend_names)

        authors = Author.objects.filter(user__in=users)

        #If the post is private, we won't show it.
        #If the post is friends_of_friends we will show it
        #If the post is local then the user will be registered. Since we are only polling
        #users that are registered and finding the authors that way, we will only
        #have local friends atm.


        # IN HERE WE ONLY WANT TO SEE THE FRIEND POSTS AND MY POSTS
        # WE ONLY SHOW ALL PUBLIC POSTS IN THE INDEX PAGE
        #First get all the posts that are public
        
        friends_as_authors = []
        friends_as_authors = [ Author.objects.get(guid=fn) for fn in friend_guids ]

        posts = Post.objects.all()

        public_posts = Post.objects.all().filter(visibility="PUBLIC").filter(author__in = friends_as_authors )

        #Visible to friends
        friend_posts = posts.filter(visibility="FRIENDS").filter(author__in = friends_as_authors )

        private_posts = posts.filter(visibility="PRIVATE").filter(author = request.user.author )

        posts = public_posts | friend_posts | private_posts 

        print posts

        images = Image.objects.filter(author=a)
        friend_guids.append(Author.objects.get(user=request.user).guid)

        context_dict = {'author':a, 'user_posts': posts, 'our_friends': friend_guids, 'user_images': images, 'logged_in_user' : loggedInUser}


        return render_to_response('social/profile.html', context_dict, context )
    elif request.method == "POST":
        if u.username == request.user.username:
            form = AuthorForm(request.POST, instance=a)
            form.save()
        return HttpResponseRedirect("/authors/%s/" % author_guid)