Exemplo n.º 1
0
    def test_user_inbox(self):
        """Tests that only the user a message was sent has an inbox count non null"""
        msg = self.send_message(self.user1, self.user2)

        self.assertEquals(inbox_count_for(self.user1), 0)  # sender
        self.assertEquals(inbox_count_for(self.user2), 1)  # recipient
        self.assertEquals(inbox_count_for(self.user3), 0)  # random user
Exemplo n.º 2
0
def inbox_count(request):
    context = {}

    if request.user.is_authenticated():
        context['inbox_count'] = inbox_count_for(request.user)

    return context
Exemplo n.º 3
0
 def render(self, context):
     try:
         user = context['user']
         count = inbox_count_for(user)
     except (KeyError, AttributeError):
         count = ''
     if self.varname is not None:
         context[self.varname] = count
         return ""
     else:
         return "%s" % (count)        
Exemplo n.º 4
0
def messageInbox(request):
    """ get the message list for the user """
    message_list = Message.objects.inbox_for(request.user)

    # Get the number of unread message
    userName = request.user
    unreadMessage = inbox_count_for(userName)
    if unreadMessage == 0:
        unreadMessage = None

    return render(request, 'website/templates/message.html', locals())
Exemplo n.º 5
0
def legalize(request):
    """ Show the legalize page """
    user = request.user

    # Get the number of unread message
    if request.user.is_authenticated:
        userName = request.user
        unreadMessage = inbox_count_for(userName)
        if unreadMessage == 0:
            unreadMessage = None
    loginForm = loginUser()
    subscribeForm = createUser()
    return render(request, 'website/templates/legal.html', locals())
Exemplo n.º 6
0
def viewMessage(request, messageId):
    """ Return the message detail """
    user = request.user
    now = timezone.now()
    messageToView = get_object_or_404(Message, id=messageId)
    if (messageToView.sender != user) and (messageToView.recipient != user):
        raise Http404
    if messageToView.read_at is None and messageToView.recipient == user:
        messageToView.read_at = now
        messageToView.save()

    # Get the number of unread message
    userName = request.user
    unreadMessage = inbox_count_for(userName)
    if unreadMessage == 0:
        unreadMessage = None

    if request.method == "POST":
        bodyForm = MessageReply(request.POST)
        if bodyForm.is_valid():
            body = bodyForm.cleaned_data['body']
            try:
                msg = Message.objects.create(
                    subject=messageToView.subject,
                    body=body,
                    sender=userName,
                    recipient=messageToView.sender,
                    parent_msg=messageToView.parent_msg,
                    sent_at=now)
                msg.save()
                succesText = 'Message envoyé'
                loginSuccess = True
            except ValueError as e:
                print('erreur: ', e)
            message_list = Message.objects.inbox_for(request.user)
            return render(request, 'website/templates/message.html', locals())
        else:
            errorText = 'Message non envoyé'
            error = True
            bodyForm = MessageReply()
    else:
        error = False
        loginSuccess = False
        bodyForm = MessageReply()

    message_list = Message.objects.inbox_for(request.user)

    return render(request, 'website/templates/message.html', locals())
Exemplo n.º 7
0
def storefront(request):
    if request.user.is_authenticated():
        if request.user.my_profile.zipcode:
            latest_entries = Entry.objects.filter(zipcode__in=[
                request.user.my_profile.nearbyzips1, request.user.my_profile.
                nearbyzips2, request.user.my_profile.nearbyzips3, request.user.
                my_profile.nearbyzips4, request.user.my_profile.nearbyzips5,
                request.user.my_profile.nearbyzips6, request.user.my_profile.
                nearbyzips7, request.user.my_profile.nearbyzips8, request.user.
                my_profile.nearbyzips9, request.user.my_profile.nearbyzips10,
                request.user.my_profile.nearbyzips11,
                request.user.my_profile.nearbyzips12
            ]).order_by('-pub_date')[:16]
            unread_list = inbox_count_for(request.user)
            context = {
                'latest_entries': latest_entries,
                'unread_list': unread_list
            }
        else:
            latest_entries = Entry.objects.order_by('-pub_date')[:16]
            context = {'latest_entries': latest_entries}
    else:
        latest_entries = Entry.objects.order_by('-pub_date')[:16]
        context = {'latest_entries': latest_entries}
    if request.is_ajax():
        if request.GET.get('filter') == 'strains':
            latest_entries = latest_entries.filter(entrytype=1)
            context = {'latest_entries': latest_entries}
            return render(request, 'storefrontload.html', context)
        if request.GET.get('filter') == 'concentrates':
            latest_entries = Entry.objects.filter(entrytype=2)
            context = {'latest_entries': latest_entries}
            return render(request, 'storefrontload.html', context)
        if request.GET.get('filter') == 'edibles':
            latest_entries = Entry.objects.filter(entrytype=3)
            context = {'latest_entries': latest_entries}
            return render(request, 'storefrontload.html', context)

# if request.GET.get('filter') == 'deliveryyes':
# 	latest_entries = Entry.objects.filter(author__deliveryoption=True)
# 	context = {'latest_entries': latest_entries}
# 	return render(request, 'storefrontload.html', context)
    return render(request, 'storefront.html', context)
Exemplo n.º 8
0
def storefront(request):
    if request.user.is_authenticated():
        if request.user.my_profile.zipcode:
            latest_entries = Entry.objects.filter(zipcode__in=[request.user.my_profile.nearbyzips1,
            request.user.my_profile.nearbyzips2,
            request.user.my_profile.nearbyzips3,
            request.user.my_profile.nearbyzips4,
            request.user.my_profile.nearbyzips5,
            request.user.my_profile.nearbyzips6,
            request.user.my_profile.nearbyzips7,
            request.user.my_profile.nearbyzips8,
            request.user.my_profile.nearbyzips9,
            request.user.my_profile.nearbyzips10,
            request.user.my_profile.nearbyzips11,
            request.user.my_profile.nearbyzips12]).order_by('-pub_date')[:16]
            unread_list = inbox_count_for(request.user)
            context = {'latest_entries': latest_entries, 'unread_list': unread_list}        
        else:
            latest_entries = Entry.objects.order_by('-pub_date')[:16]
            context = {'latest_entries': latest_entries}
    else:
        latest_entries = Entry.objects.order_by('-pub_date')[:16]
        context = {'latest_entries': latest_entries} 
    if request.is_ajax():
	    if request.GET.get('filter') == 'strains':
		    latest_entries = latest_entries.filter(entrytype=1)
		    context = {'latest_entries': latest_entries}
		    return render(request, 'storefrontload.html', context)
	    if request.GET.get('filter') == 'concentrates':
		    latest_entries = Entry.objects.filter(entrytype=2)
		    context = {'latest_entries': latest_entries}
		    return render(request, 'storefrontload.html', context)
	    if request.GET.get('filter') == 'edibles':
		    latest_entries = Entry.objects.filter(entrytype=3)
		    context = {'latest_entries': latest_entries}
		    return render(request, 'storefrontload.html', context)
    return render(request, 'storefront.html', context)
Exemplo n.º 9
0
def inbox(request):
    if request.user.is_authenticated():
        return {'messages_inbox_count': inbox_count_for(request.user)}
    else:
        return {}
Exemplo n.º 10
0
def inbox(request):
    if request.user.is_authenticated():
        return {'messages_inbox_count': inbox_count_for(request.user)}
    else:
        return {}
Exemplo n.º 11
0
def account(request):
    """ Account page """
    user = request.user

    # Check email unread
    unreadMessage = inbox_count_for(user)
    if unreadMessage == 0:
        unreadMessage = None

    interestList = user.userprofile.interestId.all()

    if request.method == "POST":
        addForm = InterestAdd(request.POST)
        if addForm.is_valid():
            interestSelect = addForm.cleaned_data['interestAdd']
            interestInput = addForm.cleaned_data['newInterest']
            getInterest = Interest.objects.get(id=interestSelect)
            user.userprofile.interestId.add(getInterest)
            if interestInput:
                obj, newInterest = Interest.objects.get_or_create(
                    interestName=interestInput.capitalize())
                user.userprofile.interestId.add(obj.id)
                user.save()
                interestForm = InterestAdd()
                delForm = InterestDel(user=user)
                editForm = EditTheProfile()
                deleteAccountForm = DeleteAccount()
                return render(request, 'website/templates/account.html',
                              locals())
            else:
                interestForm = InterestAdd()
                delForm = InterestDel(user=user)
                editForm = EditTheProfile()
                deleteAccountForm = DeleteAccount()
                return render(request, 'website/templates/account.html',
                              locals())

        delForm = InterestDel(request.POST, user=user)
        if delForm.is_valid():
            interestDel = delForm.cleaned_data['interestDel']
            getInterest = Interest.objects.get(id=interestDel)
            user.userprofile.interestId.remove(getInterest)
            user.save()
            interestForm = InterestAdd()
            delForm = InterestDel(user=user)
            editForm = EditTheProfile()
            deleteAccountForm = DeleteAccount()
            return render(request, 'website/templates/account.html', locals())

        editProfileForm = EditTheProfile(request.POST)
        if editProfileForm.is_valid():
            newEmail = editProfileForm.cleaned_data['email']
            newCity = editProfileForm.cleaned_data['city']
            newPassword = editProfileForm.cleaned_data['password']
            newPassword2 = editProfileForm.cleaned_data['password2']
            if newEmail:
                if bool(re.search(r'[^@]+@[^@]+\.[^@]+', newEmail)) is True:
                    if not User.objects.filter(email=newEmail).exists():
                        user.email = newEmail
                        user.save()
                        succesText = "L'email a était modifié"
                        loginSuccess = True
                    else:
                        errorText = "Un compte utilise déjà cette email"
                        error = True
                        subscribeForm = createUser()
                        loginForm = loginUser()
                        editForm = EditTheProfile()
                        deleteAccountForm = DeleteAccount()
                else:
                    errorText = "L'email n'est pas valide"
                    error = True
                    subscribeForm = createUser()
                    loginForm = loginUser()
                    editForm = EditTheProfile()
                    deleteAccountForm = DeleteAccount()

            if newCity:
                try:
                    city = newCity.split(" ")
                    print(city)
                    if len(city) > 2:
                        name = str(city[0]) + " " + str(city[1])
                        print("name: " + str(name))
                        cityQuery = City.objects.filter(
                            cityName__istartswith=name.upper())[:1]
                        cityWord = cityQuery[0]
                    else:
                        cityQuery = City.objects.filter(
                            cityName__istartswith=city[0].upper())[:1]
                        cityWord = cityQuery[0]
                    user.userprofile.city = cityWord
                    user.save()
                    succesText = "Le nom de ville a était changé"
                    loginSuccess = True

                except:
                    errorText = "Le nom de ville entrée n'a pas été trouvé"
                    error = True
                    subscribeForm = createUser()
                    loginForm = loginUser()
                    editForm = EditTheProfile()
                    deleteAccountForm = DeleteAccount()

            if newPassword:
                try:
                    validate_password(newPassword, user)
                    if check_password(newPassword, user.password) is False:
                        if newPassword == newPassword2:
                            # Check if newPassword contain a number
                            if bool(re.search(r'\d', newPassword)) is True:
                                # Check if newPassword contain a letter
                                if bool(re.search(r'[a-zA-Z]',
                                                  newPassword)) is True:
                                    user.set_password(newPassword)
                                    user.save()
                                    succesText = "Le mots de passe a été changé"
                                    loginSuccess = True
                                else:
                                    errorText = "Le mot de passe doit contenir au moins 1 lettre"
                                    error = True
                                    subscribeForm = createUser()
                                    loginForm = loginUser()
                            else:
                                errorText = 'Le mot de passe doit contenir au moins 1 chiffre'
                                error = True
                                subscribeForm = createUser()
                                loginForm = loginUser()
                        else:
                            errorText = 'Les mots de passe ne correspondent pas'
                            error = True
                            subscribeForm = createUser()
                            loginForm = loginUser()
                    else:
                        errorText = 'Le mots de passe correspond au mots de passe actuelle'
                        error = True
                        subscribeForm = createUser()
                        loginForm = loginUser()
                except ValidationError as e:
                    print(' '.join(e))
                    errorText = ' '.join(e)
                    error = True
                    subscribeForm = createUser()
                    loginForm = loginUser()

            interestForm = InterestAdd()
            delForm = InterestDel(user=user)
            editForm = EditTheProfile()
            deleteAccountForm = DeleteAccount()

        deleteAccount = DeleteAccount(request.POST)
        if deleteAccount.is_valid():
            confirmAnswer = deleteAccount.cleaned_data['yesConfirm']
            if confirmAnswer == "OUI":
                user.delete()
                errorText = "Votre compte a été supprimer"
                error = True
                # return redirect(reverse(logoutUser))
                return logoutUser(request, errorText, error)
            else:
                errorText = 'Vous devez tapez OUI en majuscule pour confirmer'
                error = True

    else:
        addForm = InterestAdd()
        delForm = InterestDel(user=user)
        editForm = EditTheProfile()
        deleteAccountForm = DeleteAccount()

    return render(request, 'website/templates/account.html', locals())
Exemplo n.º 12
0
def index(request):
    """ Home page render """

    # Check for modal rgpd
    if request.session.get('rgpd'):
        cookiesAccept = False
    else:
        cookiesAccept = True

    # Get the last 3 news from the database
    news = News.objects.all().order_by('id')[:3]

    # Get the number of unread message
    if request.user.is_authenticated:
        userName = request.user
        unreadMessage = inbox_count_for(userName)
        if unreadMessage == 0:
            unreadMessage = None

    # User connexion
    if request.method == "POST":
        logForm = loginUser(request.POST)
        if logForm.is_valid():
            username = logForm.cleaned_data['username']
            password = logForm.cleaned_data['password']
            authenticate_user = authenticate(username=username,
                                             password=password)
            if authenticate_user:
                login(request, authenticate_user)
                succesText = 'Bienvenue !'
                loginSuccess = True
                error = False
                userName = request.user
                unreadMessage = inbox_count_for(userName)
                if unreadMessage == 0:
                    unreadMessage = None
                searchForm = SearchPeople()
                composeForm = ComposeMessage()
                return render(request, 'website/templates/index.html',
                              locals())
            else:
                errorText = 'Utilisateur inconnu ou mauvais de mot de passe'
                error = True
                loginForm = loginUser()
                subscribeForm = createUser()

        # User subscribe modal
        subForm = createUser(request.POST)
        if subForm.is_valid():
            username = subForm.cleaned_data['username']
            email = subForm.cleaned_data['email']
            password = subForm.cleaned_data['password']
            password2 = subForm.cleaned_data['password2']
            cityInput = subForm.cleaned_data['city']
            # Check if the input password is correct (lenght 8 and 1 number inside)
            if password == password2:
                if len(password) >= 8:
                    # Check if password contain a number
                    if bool(re.search(r'\d', password)) is True:
                        # Check if password contain a letter
                        if bool(re.search(r'[a-zA-Z]', password)) is True:
                            # check if the email form is correct
                            if bool(re.search(r'[^@]+@[^@]+\.[^@]+',
                                              email)) is True:
                                # Check if the email address doesn't already exist in database
                                if not User.objects.filter(
                                        email=email).exists():
                                    # Check if the username doesn't already exist in the database
                                    if not User.objects.filter(
                                            username=username).exists():
                                        try:
                                            cityParse = cityInput.split(" ")
                                            print(cityParse)
                                            if len(cityParse) > 2:
                                                name = str(
                                                    cityParse[0]) + " " + str(
                                                        cityParse[1])
                                                print("name: " + str(name))
                                                cityQuery = City.objects.filter(
                                                    cityName__istartswith=name.
                                                    upper())[:1]
                                                cityWord = cityQuery[0]
                                            else:
                                                cityQuery = City.objects.filter(
                                                    cityName__istartswith=
                                                    cityParse[0].upper())[:1]
                                                cityWord = cityQuery[0]

                                        except:
                                            errorText = "Le nom de ville entrée n'a pas été trouvé"
                                            error = True
                                            subscribeForm = createUser()
                                            loginForm = loginUser()
                                            return render(
                                                request,
                                                'website/templates/index.html',
                                                locals())

                                        user = User.objects.create_user(
                                            username.capitalize(), email,
                                            password)
                                        user.save()
                                        user.userprofile.city = cityWord
                                        user.save()
                                        user = authenticate(
                                            username=username.capitalize(),
                                            password=password)
                                        login(request, user)
                                        succesText = 'Vous êtes connecté ! Veuillez compléter votre profil !'
                                        loginSuccess = True
                                        error = False
                                        userName = request.user
                                        composeForm = ComposeMessage()
                                        searchForm = SearchPeople()
                                        return render(
                                            request,
                                            'website/templates/index.html',
                                            locals())
                                    else:
                                        errorText = "Nom d'utilisateur déja pris"
                                        error = True
                                        subscribeForm = createUser()
                                        loginForm = loginUser()
                                else:
                                    errorText = "Un compte utilise déjà cette email"
                                    error = True
                                    subscribeForm = createUser()
                                    loginForm = loginUser()
                            else:
                                errorText = "L'email n'est pas valide"
                                error = True
                                subscribeForm = createUser()
                                loginForm = loginUser()
                        else:
                            errorText = "Le mot de passe doit contenir au moins 1 lettre"
                            error = True
                            subscribeForm = createUser()
                            loginForm = loginUser()
                    else:
                        errorText = 'Le mot de passe doit contenir au moins 1 chiffre'
                        error = True
                        subscribeForm = createUser()
                        loginForm = loginUser()
                else:
                    errorText = 'Le mot de passe est trop court, il doit faire au minimum 8 caractères et contenir au moins 1 chiffre'
                    error = True
                    subscribeForm = createUser()
                    loginForm = loginUser()
            else:
                errorText = 'Les mots de passe ne correspondent pas'
                error = True
                subscribeForm = createUser()
                loginForm = loginUser()

    else:
        error = False
        loginSuccess = False
        loginForm = loginUser()
        subscribeForm = createUser()

    composeForm = ComposeMessage()
    searchForm = SearchPeople()

    return render(request, 'website/templates/index.html', locals())
Exemplo n.º 13
0
    def test_user_inbox_not_deleted_messages(self):
        msg = self.send_message(self.user1, self.user2)
        msg.recipient_deleted_at = datetime.now()  # recipient deleted conversation thus the message
        msg.save()

        self.assertEquals(inbox_count_for(self.user2), 0)
Exemplo n.º 14
0
    def test_user_inbox_only_unread_message(self):
        msg = self.send_message(self.user1, self.user2)
        msg.read_at = datetime.now()  # set message read
        msg.save()

        self.assertEquals(inbox_count_for(self.user2), 0)
Exemplo n.º 15
0
 def test_user_inbox_is_initialy_empty(self):
     self.assertEquals(inbox_count_for(self.user1), 0)
Exemplo n.º 16
0
def unseen_message_count(request):
    if request.user.is_authenticated():
        return {'unseen_message_count': inbox_count_for(request.user)}
    else:
        return {}