def test_redirect_login_after_logout(self):
        user, _ = create_user(self.client, with_game=False)

        resp = self.client.get(r('logout'), follow=True)
        self.assertEquals(302, resp.redirect_chain[0][1])

        self.assertTrue(r('login') in resp.redirect_chain[-1][0])
Esempio n. 2
0
 def setUp(self):
     self.tour = mommy.make_recipe('core.city_tour_bh')
     self.tour_unpub = mommy.make_recipe('core.city_tour_bh_despublicado')
     self.tour_unfeat = mommy.make_recipe('core.city_tour_bh_sem_destaque')
     self.resp = self.client.get(r('core:homepage'))
     self.detail_page = self.client.get(
         r("core:detalhes", args=[self.tour.slug]))
Esempio n. 3
0
def login(request):
    """ View for processing user login """
    if request.user.is_authenticated():
        return redirect(r('core:home'))

    if request.method == 'GET':
        context = {}
        if 'signup_username' in request.session:
            context['signup_username'] = request.session.pop('signup_username')
        return render(request, 'login.html', context)

    try:
        user = User.objects.get(Q(username=request.POST['username']) |
                                Q(email=request.POST['username']))
    except User.DoesNotExist:
        return render(request, 'login.html', {'result': 'loginerror'})

    if user.check_password(request.POST['password']):
        user.backend = 'django.contrib.auth.backends.ModelBackend'
        _login(request, user)

        session_time = 60 * 60 * 1  # 1 hour timeout
        # if user marks remember me checkbox, add a lot of hours to its session
        if request.POST.get('remember-me') == 'on':
            session_time *= 10000000
        request.session.set_expiry(session_time)
        return redirect(request.GET.get('next', r('core:home')))
    else:
        return render(request, 'login.html', {'result': 'loginerror'})
Esempio n. 4
0
    def test_salvar_model(self):
        # salvar Loja
        resp = self.client.post(r('api:criar', args=('loja',)), {'nome': 'test'})
        self.assertEqual(201, resp.status_code)
        self.assertEqual(Loja.objects.get(pk=1).dono, self.user)

        # salvar Produto
        resp = self.client.post(r('api:criar', args=('produto',)), {
            'nome': 'test',
            'codigo': 123,
            'preco': 10.7,
            'loja': 1
        })
        self.assertEqual(201, resp.status_code)
        self.assertTrue(Produto.objects.exists())

        #salvar Url
        resp = self.client.post(r('api:criar', args=('url',)), {
            'endereco': '/a/b',
            'disponibilidade': False,
            'preco': 14.3,
            'loja': 1,
            'produto': 1
        })
        self.assertEqual(201, resp.status_code)
        self.assertTrue(Url.objects.exists())
    def test_response_is_404_if_logged_user_doesnt_own_game(self):
        game2 = mommy.make(Game)

        resp1 = self.client.get(r('update', kwargs={'pk': game2.pk}))
        self.assertEquals(404, resp1.status_code)

        resp2 = self.client.post(r('update', kwargs={'pk': game2.pk}), {'title': 'a', 'publisher': 'b', 'completed': True})
        self.assertEquals(404, resp2.status_code)
Esempio n. 6
0
    def test_organization_detail(self):
        response1 = self.client.get(r('organization_detail', args=[1]))
        response2 = self.client.get(r('organization_detail', args=[2]))

        self.assertEquals(200, response1.status_code)
        self.assertTrue('Funding Org X' in response1.content)
        self.assertEquals(200, response2.status_code)
        self.assertTrue('Recp Org X' in response2.content)
Esempio n. 7
0
    def test_project_detail(self):
        response1 = self.client.get(r('project_detail', args=[1]))
        response2 = self.client.get(r('project_detail', args=[2]))

        self.assertEquals(200, response1.status_code)
        self.assertTrue('Fund Project X' in response1.content)
        self.assertEquals(200, response2.status_code)
        self.assertTrue('Recp Project Y' in response2.content)
Esempio n. 8
0
 def test_actually_logs_an_user_in(self, client, admin_user):
     """Make sure the user can be logged in
     """
     resp = client.post(
         r('auth:login'),
         data={'username': '******', 'password': '******'},
         follow=True)
     assert resp.redirect_chain == [(r('home'), 302), (r('log:log'), 302)]
Esempio n. 9
0
def product_refresh(request, code):
    try:
        product = Product.objects.get(code=code)
        crawler = Bloodhound()
        crawler.howl(product)
        return redirect(r('product', args=(code,)))
    except Product.DoesNotExist:
        messages.error(request, u'Product with code {0} was not found.'.format(code))
        return redirect(r('home'))
Esempio n. 10
0
 def test_links_sidebar(self):
     """Verificando se existem todos os links necessários no menu lateral"""
     self.assertContains(self.resp, 'href="{0}">Como apoiar o IFIC</a>'.format(r('core:como-apoiar')))
     self.assertContains(self.resp, 'href="{0}">Seja um doador de órgãos</a>'.format(r('core:seja-um-doador')))
     self.assertContains(self.resp, 'href="{0}">Galeria</a>'.format(r('core:galeria')))
     self.assertContains(self.resp, 'href="{0}">Equipe</a>'.format(r('core:equipe')))
     self.assertContains(self.resp, 'href="{0}">Notícias</a>'.format(r('core:noticias')))
     self.assertContains(self.resp, 'href="{0}">Fale conosco</a>'.format(r('core:fale-conosco')))
     self.assertContains(self.resp, 'href="{0}">Publicações Científicas</a>'.format(r('core:publicacao-cientifica')))
Esempio n. 11
0
    def test_retorna_status_200(self):
        resp = self.client.get(r('core:model-remover', kwargs={'tipo': 'loja', 'pk': self.loja.pk,}))
        self.assertEqual(200, resp.status_code)

        resp = self.client.get(r('core:model-remover', kwargs={'tipo': 'produto', 'pk': self.produto.pk,}))
        self.assertEqual(200, resp.status_code)

        resp = self.client.get(r('core:model-remover', kwargs={'tipo': 'url', 'pk': self.url.pk,}))
        self.assertEqual(200, resp.status_code)
Esempio n. 12
0
    def test_remocao_model(self):
        self.resp = self.client.post(r('core:model-remover', kwargs={'tipo': 'loja', 'pk': self.loja.pk,}))
        self.assertRaises(Loja.objects.get, pk=self.loja.pk)

        self.resp = self.client.post(r('core:model-remover', kwargs={'tipo': 'produto', 'pk': self.produto.pk,}))
        self.assertRaises(Produto.objects.get, pk=self.produto.pk)

        self.resp = self.client.post(r('core:model-remover', kwargs={'tipo': 'url', 'pk': self.url.pk,}))
        self.assertRaises(Url.objects.get, pk=self.url.pk)
Esempio n. 13
0
    def test_retorna_status_404_quando_model_nao_eh_encontrado(self):
        resp = self.client.get(r('core:model-remover', kwargs={'tipo': 'loja', 'pk': 97,}))
        self.assertEqual(404, resp.status_code)

        resp = self.client.get(r('core:model-remover', kwargs={'tipo': 'produto', 'pk': 97,}))
        self.assertEqual(404, resp.status_code)

        resp = self.client.get(r('core:model-remover', kwargs={'tipo': 'url', 'pk': 97,}))
        self.assertEqual(404, resp.status_code)
Esempio n. 14
0
    def test_retorna_status_200(self):

        resp_loja = self.client.get(r('core:model-atualizar', kwargs={'tipo': 'loja', 'pk': self.loja.pk,}))
        resp_produto = self.client.get(r('core:model-atualizar', kwargs={'tipo': 'produto', 'pk': self.produto.pk,}))
        resp_url = self.client.get(r('core:model-atualizar', kwargs={'tipo': 'url', 'pk': self.url.pk,}))

        self.assertEqual(200, resp_loja.status_code)
        self.assertEqual(200, resp_produto.status_code)
        self.assertEqual(200, resp_url.status_code)
    def test_response_is_404_if_logged_user_doesnt_own_game(self):
        user2 = User.objects.create_user(username='******', password='******')
        game2 = mommy.make(Game, owner=user2)

        resp1 = self.client.get(r('delete', kwargs={'pk': game2.pk}))
        self.assertEquals(404, resp1.status_code)

        resp2 = self.client.post(r('delete', kwargs={'pk': game2.pk}))
        self.assertEquals(404, resp2.status_code)
Esempio n. 16
0
    def test_remover_models(self):
        # remover Loja
        resp = self.client.delete(r('api:remover', args=('loja', self.loja.pk,)))
        self.assertEqual(200, resp.status_code)
        self.assertRaises(Loja.objects.get, pk=self.loja.pk)

        # remover Produto
        resp = self.client.delete(r('api:remover', args=('produto', self.produto.pk,)))
        self.assertEqual(200, resp.status_code)
        self.assertRaises(Produto.objects.get, pk=self.produto.pk)
Esempio n. 17
0
def serie_step2(request, id_serie, dia_atual):
    '''
      @series_novo: Metodo de criação de uma nova serie - Passo 2
    '''
    # Procurando a serie na base de dados
    serie = Serie.objects.get(pk=id_serie)
    
    # Montando o dicicionario de dados para o Dia Atual
    if int(dia_atual) == 1:
        dia_atual_letra = 'A'
    elif int(dia_atual) == 2:
        dia_atual_letra = 'B'        
    elif int(dia_atual) == 3:
        dia_atual_letra = 'C'        
    elif int(dia_atual) == 4:
        dia_atual_letra = 'D'            
    elif int(dia_atual) == 5:
        dia_atual_letra = 'E'            
    elif int(dia_atual) == 6:
        dia_atual_letra = 'F'            
    elif int(dia_atual) == 7:
        dia_atual_letra = 'G'
        
    
    # Verificando se a dia atual é maior que o dia final   
    if int(dia_atual) <= int(serie.dias):             
        if request.method == 'POST':
            formSerie = Step2Form(request.POST)
            if formSerie.is_valid():
                
                # Salvando as informações no banco
                dia_serie       = formSerie.save(commit=False)
                dia_serie.serie = serie
                dia_serie.dia   = dia_atual
        
                # Salvando a serie
                dia_serie.save()
                formSerie.save_m2m()  
                                
                return HttpResponseRedirect( r('series:serie_step3', args=[dia_serie.id, dia_atual] ) )
            else:
                return render(request, 'serie_step2.html',{'form': formSerie,'dia_atual':dia_atual_letra,'id_serie':id_serie})                
        else:                            
            return render(request, 'serie_step2.html',{'form': Step2Form(),'dia_atual':dia_atual_letra,'id_serie':id_serie})
    else:
        # Salvando a Serie em uma tabela de Historico para gerar a performance do aluno posteriormente
        historico               = HistoricoSerie()
        historico.serie         = serie
        historico.aluno         = serie.aluno
        historico.professor     = serie.professor
        historico.datacriacao   = serie.datacriacao
        
        historico.save()
                
        return HttpResponseRedirect( r('series:serie_lista') )     
Esempio n. 18
0
    def test_delete_nonexistent(self):
        """ Deleting an expense already deleted should return status code 404 \
            not found """

        resp = self.client.delete(r('core:expense_detail',
                                    kwargs={'pk': self.expense1.id}),
                                  **self.auth_headers)
        resp = self.client.delete(r('core:expense_detail',
                                    kwargs={'pk': self.expense1.id}),
                                  **self.auth_headers)
        self.assertEquals(404, resp.status_code)
Esempio n. 19
0
    def get(self, request, **response_kwargs):
        objs = []
        for destino in Destino.objects.all():
            url = r("core:destino", args=[destino.slug])
            datum = {
                "value": destino.titulo,
                "url": url,
                "destino": True,
            }
            objs.append(datum)

        for estado in Estado.objects.all():
            url = r("core:estado", args=[estado.slug])
            datum = {
                "value": estado.titulo,
                "url": url,
                "estado": True,
            }
            objs.append(datum)

        for regiao in Regiao.objects.all():
            url = r("core:regiao", args=[regiao.slug])
            datum = {
                "value": regiao.titulo,
                "url": url,
                "regiao": True,
            }
            objs.append(datum)

        for pais in Pais.objects.all():
            url = r("core:pais", args=[pais.slug])
            datum = {
                "value": pais.titulo,
                "url": url,
                "pais": True,
            }
            objs.append(datum)

        queryset = Pacote.objects.filter(publicado=True)
        for pacote in queryset:
            url = r("core:detalhes", args=[pacote.slug])
            tokens = pacote.titulo.split()
            tokens += pacote.destino.titulo.split()
            tokens = list(set(tokens))
            datum = {
                "value": pacote.titulo,
                "url": url,
                "tokens": tokens
            }
            objs.append(datum)
        response = json.dumps(objs)
        return self.response_class(response, **response_kwargs)
Esempio n. 20
0
def funcionarios(request):
    '''
        @funcionarios_escola: View para renderizar a listagem de funcionarios
    '''
    if request.user.groups.all()[0].name == 'Diretor':
        unidade  = request.user.escolas.all()[0]

        if unidade.quantidade_alunos == 0:
            return HttpResponseRedirect(r('escola:quantidade_alunos',kwargs={'escola':unidade.id}))
        else: 
            return HttpResponseRedirect(r('recadastramento:funcionarios_escola',kwargs={'unidade_id':unidade.id}))
    else:
        return HttpResponseRedirect(r('recadastramento:selecionar_unidade'))
Esempio n. 21
0
    def test_no_album_or_no_picture(self):
        """ Return empty list if there is no album or no picture """

        # no album test
        resp = self.client.get(r('magicalbum:api'))
        resp = json.loads(resp.content)
        self.assertEqual([], resp)

        # no picture test
        album = Album()
        album.save()
        resp = self.client.get(r('magicalbum:api'))
        resp = json.loads(resp.content)
        self.assertEqual([], resp)
Esempio n. 22
0
def login_home(request):
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            return HttpResponseRedirect( r('core:home_site'))
        else:
            # Return a 'disabled account' error message
            return HttpResponseRedirect( r('core:home_site'))
    else:
        # Return an 'invalid login' error message.
        return HttpResponseRedirect( r('core:home_site'))
Esempio n. 23
0
	def test_not_found(self):
		url = r('core:speaker_detail', kwargs={'slug': 'john-doe'})
		response = self.client.get(url)
		self.assertEqual(404, response.status_code)


		
Esempio n. 24
0
def delete_documents(request):
    select_all_pages = request.POST.get('select-all-pages')
    document_ids = request.POST.getlist('document')
    folder_id = request.POST.get('active-folder-id')

    if folder_id:
        folder = Folder.objects.get(pk=folder_id)
        if select_all_pages == 'all':
            documents = folder.documents.all()
        else:
            documents = folder.documents.filter(id__in=document_ids)
    else:
        if select_all_pages == 'all':
            documents = Document.objects.filter(user=request.user)
        else:
            documents = Document.objects.filter(user=request.user, id__in=document_ids)

    querystring = request.POST.get('querystring', '')
    documents = get_filtered_documents(documents, querystring)
        
    documents_size = documents.count()
    documents.delete()
    messages.success(request, u'{0} {1} successfully deleted!'.format(
            documents_size, 
            get_document_verbose_name(documents_size))
        )
    redirect_to = request.POST.get('redirect', r('library:index'))
    return redirect(redirect_to)
Esempio n. 25
0
 def test_status_404_se_usuario_nao_eh_dono_da_loja(self):
     dummy_user = User.objects.create_user(username='******', password='******')
     loja = mommy.make(Loja, dono=dummy_user)
     loja_props = model_to_dict(loja)
     loja_props.update({'nome': 'Aaa'})
     resp = self.client.post(r('core:model-atualizar', kwargs={'tipo': 'loja', 'pk': loja.pk,}), loja_props)
     self.assertEqual(404, resp.status_code)
Esempio n. 26
0
 def setUp(self):
     Speaker.objects.create(name = u'Élysson MR',
         slug = 'elysson-mr',
         url = 'http://google.com',
         description = "Assassins Creed Player")
     url = r('core:speaker_detail', kwargs={'slug' : 'elysson-mr'})
     self.resp = self.client.get(url)
Esempio n. 27
0
def dispositivo_editar(request,id_dispositivo):
    '''
      @dispositivo_editar: Metodo de edição de um Dispositivo
    '''
    dispositivo = Dispositivo.objects.get(id=id_dispositivo)    
    if request.method == 'POST':
        form = DispositivoForm(request.POST,instance=dispositivo)
        if form.is_valid():
            obj = form.save(commit=False)            
            obj.save()

            # Editando token da lista de Push do Django PushNotification
            if obj.tipo_aparelho == 'apn':
                try:
                    push = APNSDevice.objects.get(registration_id=obj.token)
                    push.registration_id = obj.token
                    push.save()
                except:
                    push = APNSDevice.objects.create(registration_id=obj.token)
            else:
                try:
                    push = GCMDevice.objects.get(registration_id=obj.token)
                    push.registration_id = obj.token
                    push.save()
                except:
                    push = GCMDevice.objects.create(registration_id=obj.token)

            print push.registration_id
            return HttpResponseRedirect( r('dispositivo:dispositivos'))
        else:  
            return render(request,'dispositivo_form.html',{'form': form,'status':"Editar"})
    else:
        return render(request,'dispositivo_form.html',{'form': DispositivoForm(instance=dispositivo),'status':"Editar"})
    def setUp(self):
        # Needed for testing captcha
        os.environ['RECAPTCHA_TESTING'] = 'True'

        data = dict(name='', email='', url='', location='',
                    recaptcha_response_field='PASSED')
        self.resp = self.client.post(r('signatures:signup'), data)
Esempio n. 29
0
def dispositivo_novo(request):
    '''
      @dispositivo_novo: Metodo de criação de um novo Dispositivo
    '''
    if request.method == 'POST':
        form = DispositivoForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.save()

            if obj.tipo_aparelho == 'apn':
                try:
                    push = APNSDevice.objects.create(registration_id=obj.token)
                except:
                    pass
            else:
                try:
                    push = GCMDevice.objects.create(registration_id=obj.token)            
                except:
                    pass

            return HttpResponseRedirect( r('dispositivo:dispositivos'))
        else:  
            return render(request,'dispositivo_form.html',{'form': form,'status':"Novo"})
    else:
        return render(request,'dispositivo_form.html',{'form': DispositivoForm(),'status':"Novo"})
Esempio n. 30
0
def copy(request):
    redirect_to = request.POST.get('redirect', r('library:index'))

    copy_from_folder_id = request.POST.get('active-folder-id')
    copy_to_folder_id = request.POST.get('action-folder-id')

    try:
        copy_to_folder = Folder.objects.get(pk=copy_to_folder_id)
    except Folder.DoesNotExist:
        messages.error(u'The folder you are trying to copy does not exist.')
        return redirect(redirect_to)

    select_all_pages = request.POST.get('select-all-pages')
    document_ids = request.POST.getlist('document')

    if copy_from_folder_id:
        try:
            copy_from_folder = Folder.objects.get(pk=copy_from_folder_id)
            documents = copy_from_folder.documents.all()
        except Folder.DoesNotExist:
            messages.error(u'The folder you are trying to copy does not exist.')
            return redirect(redirect_to)
    else:
        documents = Document.objects.filter(user=request.user)

    if select_all_pages == 'all':
        querystring = request.POST.get('querystring', '')
        documents = get_filtered_documents(documents, querystring)
    else:
        documents = documents.filter(id__in=document_ids)

    copy_to_folder.documents.add(*documents)
    messages.success(request, u'Documents copied to folder {0} successfully!'.format(copy_to_folder.name))
    return redirect(redirect_to)
Esempio n. 31
0
 def setUp(self):
     self.resp = self.client.get(r('phone_add'))
Esempio n. 32
0
 def test_not_found(self):
     url = r('core:speaker_detail', kwargs={'slug': 'Samuel'} )
     response = self.client.get(url)
     self.assertEqual(404, response.status_code)
Esempio n. 33
0
from django.shortcuts import render
from django.core.urlresolvers import reverse_lazy as r
from django.views.generic import CreateView, ListView, DetailView
from django.views.generic import UpdateView, DeleteView
from .mixins import NameSearchMixin
from .models import Person
from .forms import PersonForm


def home(request):
    return render(request, 'index.html')


class PersonList(NameSearchMixin, ListView):
    model = Person
    paginate_by = 5


person_detail = DetailView.as_view(model=Person)

person_create = CreateView.as_view(model=Person, form_class=PersonForm)

person_update = UpdateView.as_view(model=Person, form_class=PersonForm)

person_delete = DeleteView.as_view(model=Person,
                                   success_url=r('core:person_list'))
Esempio n. 34
0
File: tests.py Progetto: delete/wttd
 def setUp(self):
     self.response = self.client.get(r('core:homepage'))
Esempio n. 35
0
 def test_template_show_message_if_there_is_no_games(self):
     resp = self.client.get(r('home'))
     self.assertContains(resp, 'There are no games')
Esempio n. 36
0
 def setUp(self):
     self.resp = self.client.get(r('occupation_add'))
Esempio n. 37
0
 def setUp(self):
     t = Talk.objects.create(title='Talk', start_time='10:00')
     t.speakers.create(name='Regis da Silva', slug='regis-da-silva')
     self.resp = self.client.get(r('core:talk_detail', args=[1]))
Esempio n. 38
0
 def setUp(self):
     self.client.login(username=self.user.username, password='******')
     self.response = self.client.get(
         r('factors:edit_group', args=(self.group.pk, )))
Esempio n. 39
0
 def setUp(self):
     data = dict(name='Ivan Rocha',
                 cpf='12345678901',
                 email='*****@*****.**',
                 phone='8487598888')
     self.resp = self.client.post(r('subscriptions:subscribe'), data)
Esempio n. 40
0
 def setUp(self):
     t = Talk.objects.create(title='Talk', start_time='10:00')
     t.speakers.create(name='Henrique Bastos', slug='henrique-bastos')
     self.resp = self.client.get(r('core:talk_detail', args=[1]))
Esempio n. 41
0
 def setUp(self):
     self.response = self.client.get(
         r('snippets:details', args=('john', 'test404')))
Esempio n. 42
0
 def setUp(self):
     self.resp = self.client.get(r('address_add'))
Esempio n. 43
0
 def setUp(self):
     self.resp = self.client.get(r('person_add'))
 def setUp(self):
     self.resp = self.client.get(r('core:importar_arquivo_de_vendas'))
Esempio n. 45
0
def planning(request, username, review_name):
    return redirect(r('protocol', args=(username, review_name)))
Esempio n. 46
0
 def setUp(self):
     self.resp = client.get(r('core:login'))
Esempio n. 47
0
 def test_template_lists_games(self):
     mommy.make(Game, _quantity=5, owner=self.user)
     resp = self.client.get(r('home'))
     self.assertContains(resp, '<tr', 6)
Esempio n. 48
0
 def test_not_found(self):
     'Talk was not found.'
     resp = self.client.get(r('core:talk_detail', args=[0]))
     self.assertEqual(404, resp.status_code)
Esempio n. 49
0
 def setUp(self):
     t = Talk.objects.create(title='Talk', start_time='10:00')
     t.speakers.create(name='Fellipe Castro', slug='fellipe-castro')
     self.resp = self.client.get(r('core:talk_detail', args=[1]))
Esempio n. 50
0
 def setUp(self):
     self.resp = self.client.get(r('core:home'))
Esempio n. 51
0
 def setUp(self):
     self.resp = client.get(r('core:signup'))
 def setUp(self):
     self.resp = self.client.get(r('signatures:success'))
Esempio n. 53
0
    def test_template_has_non_field_errors(self):
        'Verifica se esta mostrando os non_field_errors no template'
        invalid_data = dict(name='Marcos Ribeiro', cpf='1245678901')
        response = self.client.post(r('subscriptions:subscribe'), invalid_data)

        self.assertContains(response, '<ul class="errorlist">')
Esempio n. 54
0
 def setUp(self):
     self.resp = self.client.get(r('subscriptions:subscribe'))
Esempio n. 55
0
    def get_redirect_url(self, token):
        # Authenticate user
        auth.authenticate(token=token)

        return r('accounts:signup')
Esempio n. 56
0
 def setUp(self):
     data = dict(name='Marcos Ribeiro',
                 cpf=' 000000000012',
                 email='*****@*****.**',
                 phone='2345678')
     self.resp = self.client.post(r('subscriptions:subscribe'), data)
Esempio n. 57
0
def add_author_to_review(request):
    emails = request.POST.getlist('users')
    review_id = request.POST.get('review-id')
    review = get_object_or_404(Review, pk=review_id)
    authors_added = []
    authors_invited = []

    inviter_name = request.user.profile.get_screen_name()

    for email in emails:
        try:
            user = User.objects.get(email__iexact=email)
            if user.id != review.author.id:
                authors_added.append(user.profile.get_screen_name())
                review.co_authors.add(user)
        except User.DoesNotExist:
            authors_invited.append(email)

            subject = u'{0} wants to add you as co-author on the systematic literature review {1}'.format(
                inviter_name, review.title)
            from_email = u'{0} via Parsifal <*****@*****.**>'.format(
                inviter_name)

            text_content = u'''Hi {0}, 
            {1} invited you to a Parsifal Systematic Literature Review called "{2}". 
            View the review at https://parsif.al/{3}/{4}/'''.format(
                email, inviter_name, review.title, request.user.username,
                review.name)

            html_content = u'''<p>Hi {0},</p>
            <p>{1} invited you to a Parsifal Systematic Literature Review called "{2}".</p>
            <p>View the review at https://parsif.al/{3}/{4}/</p>
            <p>Sincerely,</p>
            <p>The Parsifal Team</p>'''.format(email, inviter_name,
                                               review.title,
                                               request.user.username,
                                               review.name)

            msg = EmailMultiAlternatives(subject, text_content, from_email,
                                         [email])
            msg.attach_alternative(html_content, 'text/html')
            msg.send()

    review.save()

    if not authors_added and not authors_invited:
        messages.info(
            request,
            u'No author invited or added to the review. Nothing really changed.'
        )

    if authors_added:
        messages.success(
            request, u'The authors {0} were added successfully.'.format(
                u', '.join(authors_added)))

    if authors_invited:
        messages.success(
            request, u'{0} were invited successfully.'.format(
                u', '.join(authors_invited)))

    return redirect(r('review', args=(review.author.username, review.name)))
Esempio n. 58
0
 def setUp(self):
     t = Talk.objects.create(title='Talk', start_time='10:00')
     t.speakers.create(name='Artur Sousa',
                       slug='artur-sousa',
                       url='http://artursousa.com.br')
     self.resp = self.client.get(r('core:talk_detail', args=[1]))
Esempio n. 59
0
 def test_not_found(self):
     response = self.client.get(r('core:talk_detail', args=[0]))
     self.assertEqual(404, response.status_code)
Esempio n. 60
0
    def test_template_has_non_field_errors(self):
        'Check if non_field_errors are shown in template.'
        invalid_data = dict(name='Fellipe Castro', cpf='12345678901')
        response = self.client.post(r('subscriptions:subscribe'), invalid_data)

        self.assertContains(response, '<ul class="errorlist">')