Пример #1
0
def post(request):
    feed = Feed()
    feed.user = request.user
    # data: $("#compose-form").serialize(),
    feed.post = request.POST['post']
    feed.save()
    return render(request, 'feeds/partial_feed.html', {'feed': feed})
Пример #2
0
def register(request):
    if request.method == 'POST':
        user_form = RegistrationForm(request.POST)
        if user_form.is_valid():
            username = user_form.cleaned_data.get('username')
            email = user_form.cleaned_data.get('email')
            password = user_form.cleaned_data.get('password')

            User.objects.create_user(
                username=username,
                email=email,
                password=password,
            )
            user = authenticate(username=username, password=password)
            login(request, user)
            _success_msg = 'User {0} added'.format(user.username)
            feed = Feed(user=user, posts=_success_msg)
            feed.save()
            return redirect('/feeds/')
        else:
            return render(request, 'authentication/register.html',
                          {'form': user_form})
    else:
        user_form = RegistrationForm()

    return render(request, 'authentication/register.html', {'form': user_form})
Пример #3
0
def create_book(request):
    if not request.user.is_authenticated():
        render(request, 'core/cover.html')
    else:
        form = BookForm(request.POST or None, request.FILES or None)
        if form.is_valid():
            books = form.save(commit=False)
            books.user = request.user
            books.logo = request.FILES['logo']
            file_type = books.logo.url.split('.')[-1]
            file_type = file_type.lower()
            if file_type not in IMAGE_FILE_TYPES:
                context = {
                    'books': books,
                    'form': form,
                    'error_message': 'Image file must be PNG, JPG, or JPEG',
                }
                return render(request, 'mylibrary/create_book.html', context)
            books.save()
            user = request.user
            welcome_post = '{0} has added <a href="{1}">{2}</a>.'.format(
                escape(user.username), reverse('mylibrary:index'), books.book_title)
            feed = Feed(user=user, post=welcome_post)
            feed.save()
            return render(request, 'mylibrary/detail.html', {'books': books})
        context = {
            "form": form,
        }
        return render(request, 'mylibrary/create_book.html', context)
Пример #4
0
    def _update_feed(
        cls,
        feed_subscription: FeedSubscription,
        feed_data: FeedParserDict,
    ) -> Feed:
        """
        Create or update Feed based on parsed data.

        :param feed_subscription: FeedSubscription related instance.
        :param feed_data: Parsed RSS data.
        :return: Processed Feed instance.
        """
        cloud = feed_data.feed.get('cloud', {})
        image = feed_data.feed.get('image', {})
        text_input = feed_data.feed.get('textinput', {})
        # Create a filed_name:value dict out of fetched data for Feed
        data = {
            'cloud_domain': cloud.get('domain'),
            'cloud_path': cloud.get('path'),
            'cloud_port': cloud.get('port'),
            'cloud_protocol': cloud.get('protocol'),
            'cloud_register_procedure': cloud.get('registerProcedure'),
            'copyright': feed_data.feed.get('rights'),
            'description': feed_data.feed.get('subtitle'),
            'docs': feed_data.feed.get('docs'),
            'encoding': feed_data.get('encoding'),
            'generator': feed_data.feed.get('generator'),
            'image_description': image.get('description'),
            'image_height': image.get('height'),
            'image_link': image.get('width'),
            'image_title': image.get('title'),
            'image_url': image.get('href'),
            'image_width': image.get('width'),
            'language': feed_data.feed.get('language'),
            'link': feed_data.feed.get('link'),
            'managing_editor': feed_data.feed.get('author'),
            'pub_date': cls.get_pub_date(feed_data.feed),
            'subscription': feed_subscription,
            'text_input_description': text_input.get('description'),
            'text_input_link': text_input.get('link'),
            'text_input_name': text_input.get('name'),
            'text_input_title': text_input.get('title'),
            'title': feed_data.feed.get('title'),
            'ttl': feed_data.feed.get('ttl'),
            'version': feed_data.get('version'),
            'web_master': feed_data.feed.get('publisher')
        }

        try:
            feed = feed_subscription.feed

            # Update Feed with fetched values
            for name, value in data.items():
                setattr(feed, name, value)
        except FeedSubscription.feed.RelatedObjectDoesNotExist:
            # Make a new Feed instance with fetched values
            feed = Feed(**data)

        feed.save()
        return feed
Пример #5
0
 def test_fetching_feed_details_method(self):
     feed = Feed(link=self.feed_url)  # Instantiate, not save
     feed.fetch_and_set_feed_details()  # initialize, nopt saved
     self.assertEqual(Feed.objects.count(), 0)
     self.assertEqual(feed.title, self.feedparser_dict.feed['title'])
     self.assertEqual(feed.description,
                      self.feedparser_dict.feed['description'])
     self.assertEqual(feed.version, self.feedparser_dict['version'])
Пример #6
0
def _process_post_form_messages(form, logged_user, to_user):

    msg = Message(from_user=logged_user,
                  to_user=to_user,
                  post=form.post.data,
                  message_type=POST).save()
    Feed(user=logged_user, message=msg).save()
    MessageProcessor(message_obj=msg).post_message_to_all_friends_feeds()

    return msg
Пример #7
0
 def _save_feed(self):
     """
     Custom method to create and save a new feed to the DB.
     """
     feed = Feed()
     feed.plugin_inst = self
     feed.save()
     feed.name = self.plugin.name
     feed.owner = [self.owner]
     feed.save()
Пример #8
0
 def _save_feed(self):
     """
     Custom internal method to create and save a new feed to the DB.
     """
     feed = Feed()
     feed.name = self.plugin.meta.name
     feed.save()
     feed.owner.set([self.owner])
     feed.save()
     return feed
Пример #9
0
    def test_feed_save_method(self):
        feed = Feed(link=self.feed_url)
        feed.save()
        new_feed = Feed.objects.get(link=self.feed_url)

        self.assertEqual(Feed.objects.count(), 1)
        self.assertEqual(new_feed.title, self.feedparser_dict.feed['title'])
        self.assertEqual(new_feed.description,
                         self.feedparser_dict.feed['description'])
        self.assertEqual(new_feed.link, self.feed_url)
        self.assertEqual(new_feed.version, self.feedparser_dict['version'])
Пример #10
0
    def post_message_to_all_friends_feeds(self):

        friends = self._get_all_my_friends_obj()

        for friend in friends:

            rel_status = Relationship.get_relationship(
                friend.to_user, self._message_obj.to_user)

            if rel_status != constants.BLOCKED:
                Feed(user=friend.to_user, message=self._message_obj).save()
        return True
Пример #11
0
def post(request):
    last_feed = request.POST.get('last_feed')
    user = request.user
    csrf_token = (csrf(request)['csrf_token'])
    feed = Feed()
    feed.user = user
    post = request.POST['post']
    post = post.strip()
    if len(post) > 0:
        feed.post = post[:255]
        feed.save()
    html = _html_feeds(last_feed, user, csrf_token)
    return HttpResponse(html)
Пример #12
0
    def setUp(self):
        """
        Set up enivironment to test models
        """
        self.user = User.objects.create_user(self.username,
                                             '*****@*****.**',
                                             self.password)
        """Test user."""

        self.feed1 = Feed(feed_url=reverse('planet:rss1'),
                          name="rss1",
                          short_name="rss1")
        self.feed1.save()
        """Feed 1."""

        self.feed2 = Feed(feed_url=reverse('planet:rss2'),
                          name="rss2",
                          short_name="rss2")
        self.feed2.save()
        """Feed 2."""

        self.client = Client()
        """Test Client."""
Пример #13
0
def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None

    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.profile.email_confirmed = True
        user.save()
        login(request, user)
        welcome_post = '{0} has joined the network.'.format(user.username,
                                                            user.username)
        feed = Feed(user=user, post=welcome_post)
        feed.save()
        return redirect('/')
    else:
        return render(request, 'authentication/account_activation_invalid.html')
Пример #14
0
def post(request):   #feeds on profiles
    to_user = request.POST.get('to_user')
    # profile_pk = request.POST.get('profile_pk')
    # last_feed = request.POST.get('last_feed')
    to_user = get_object_or_404(User, username=to_user)
    to_user_profile_pk = to_user.profile.pk
    user = request.user
    csrf_token = (csrf(request)['csrf_token'])
    feed = Feed()
    feed.user = user
    feed.to_user = to_user
    feed.profile_pk = to_user_profile_pk
    # if not to_user:
    #     feed.profile_pk = profile_pk
    # else:
    #     feed.profile_pk = to_user.profile.pk
    #     profile_pk = to_user.profile.pk
    post = request.POST['post']
    post = post.strip()
    if len(post) > 0 and to_user:
        feed.post = post[:255]
        feed.save()
        profile = Profile.objects.get(pk=to_user_profile_pk) # to_user_profile
        # wrote_on_profile = Activity.objects.filter(activity_type=Activity.WROTE_ON_PROFILE, profile=profile_pk,
        #                            user=user)

        wrote_on_profile = Activity(activity_type=Activity.WROTE_ON_PROFILE, profile=to_user_profile_pk, user=user)
        wrote_on_profile.save()
        user.profile.notify_wrote_on_profile(profile,feed)
        
        html = ''
        html = '{0}{1}'.format(html,
                               render_to_string('feeds/partial_feed_profile.html',
                                                {
                                                    'feed': feed,
                                                    'user': request.user,
                                                    'csrf_token': csrf_token,
                                                    }))
    else:
        html = ''
    return HttpResponse(html)
Пример #15
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if not form.is_valid():
            return render(request, 'auth/signup.html', {'form': form})
        else:
            username = form.cleaned_data.get('username')
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            User.objects.create_user(username=username,
                                     password=password,
                                     email=email)
            user = authenticate(username=username, password=password)
            login(request, user)
            welcome_post = u'{0} has joined the network.'.format(
                user.username, user.username)
            feed = Feed(user=user, post=welcome_post)
            feed.save()
            return redirect('/')
    else:
        return render(request, 'auth/signup.html', {'form': SignUpForm()})
Пример #16
0
 def test_save_without_link_raises_error(self):
     feed = Feed()
     with self.assertRaises(TypeError):
         feed.save()
     self.assertEqual(Feed.objects.count(), 0)
     self.assertFalse(self.mock_fetch_feedparser_dict.called)
Пример #17
0
def signup_human(request):
    print('inside signup_human, authentication.view')
    recent_challenge_feeds = Feed.get_feeds().filter(
        is_challenge=1).order_by('-date')[:20]

    if recent_challenge_feeds:
        users_challenges = recent_challenge_feeds
    else:
        users_challenges = []

    if request.method == 'POST':
        form = SignUpForm(request.POST)
        flag = 'human'
        print('flag', flag)
        if not form.is_valid():
            return render(
                request, 'authentication/signup.html', {
                    'form_human': form,
                    'flag': flag,
                    'users_challenges': users_challenges,
                })

        else:
            username = form.cleaned_data.get('username')
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            gender = form.cleaned_data.get('gender')
            User.objects.create_user(
                username=username, password=password,
                email=email)  # removed email at signup to make signup fast
            user = authenticate(username=username, password=password)

            user.profile.gender = gender
            user.save()
            login(request, user)

            profile_pk = user.profile.pk  # profile_pk of newley registered user
            profile = user.profile  # profile object of newly registered user
            print(profile_pk, user.username)

            hohos = get_object_or_404(User, username='******')
            hohoshelp = get_object_or_404(User, username='******')
            like_by_hohos = Activity(activity_type=Activity.LIKE_PROFILE,
                                     profile=profile_pk,
                                     user=hohos)
            like_by_hohoshelp = Activity(activity_type=Activity.LIKE_PROFILE,
                                         profile=profile_pk,
                                         user=hohoshelp)
            like_by_hohos.save()
            like_by_hohoshelp.save()
            hohos.profile.notify_liked_profile(
                profile)  # hohos to=> user(newly registered)
            hohoshelp.profile.notify_liked_profile(
                profile)  # hohoshelp to user(newly registered)

            like = Activity(activity_type=Activity.LIKE_PROFILE,
                            profile=profile_pk,
                            user=user)
            like.save()

            to_user = user
            from_user = hohos  # get_object_or_404(User, username='******')
            wel_post = ''
            welcome1= ' You seem to love facial expressions?? You can Make it awesome!\n'\
                      +'Challenge your friends and imitate them. Sounds cool??\n'\
                      +'Welcome!\nhttp://www.hohos.tech/feeds/challenge/'
            welcome2= ' Get ready to speak through your awesome facial expressions...\n'\
                      +'http://www.hohos.tech/feeds/'
            welcome3= ' You are awesome! \n'\
                      +'Imitate your friends expressions and challenge them yours.'\
                      +'You should try it once!\n'\
                      +'Its amazing!\nhttp://www.hohos.tech/feeds/'

            post_no = random.randint(1, 3)
            if post_no == 1: wel_post = welcome1
            elif post_no == 2: wel_post = welcome2
            else: wel_post = welcome3

            if from_user:
                welcome_post = 'Hey ' + to_user.username + wel_post
                feed = Feed()
                feed.user = from_user
                feed.to_user = to_user
                to_user_profile_pk = profile_pk  # newley registered users profile pk
                feed.profile_pk = to_user_profile_pk
                feed.post = welcome_post
                feed.save()
                wrote_on_profile = Activity(
                    activity_type=Activity.WROTE_ON_PROFILE,
                    profile=to_user_profile_pk,
                    user=from_user)
                wrote_on_profile.save()
                hohos.profile.notify_wrote_on_profile(profile, feed)

            messages.add_message(
                request, messages.SUCCESS,
                'Get ready to show your own flavours!!' + user.username +
                '\n If you want to make people make a special pose for you, \
                                 just share that and see if your friends could make that better?\
                                  you Can visit your friends profile and say something\
                                  about him/her!')
            from_email = django_settings.EMAIL_HOST_USER
            to = [email]
            subject = 'Welcome at hohos ' + user.username
            message = 'Dear '+user.username+'!\n'\
                          + 'We are happy to see you on hohos.tech\n' \
                          + 'You will have lots of amazing experience along the time. It will get better if '\
                          + 'you participate in share and imitate culture at hohos.tech/feeds/\n'\
                          + 'Challenge your facial expressions, let your likers and other people imitate them.'\
                          + 'Because its awesome to see the different versions of same thing.\n'\
                          + 'This becomes rejoicing when your own friends imitate you.\n\n'\
                          + 'Moreover you can become the part of OpenChat community at - hohos.tech/feeds/openchat/h_h/ '\
                          + ' here You can talk to your daily use products too. Which makes things a lot easier.\n\n'\
                          + 'Build you profile for better interaction.'\
                          + 'First hohos.tech/login and then move to hohos.tech/settings/human/\n\n'\
                          + 'Best wishes!\n'\
                          + '-Team iA at hohos.tech'
            if to:
                try:
                    send_mail(subject,
                              message,
                              from_email,
                              to,
                              fail_silently=False)
                except:
                    pass

            # print('inside signup, authentication.views')
            # print('user\'s pk %d'%(user.pk))
            return redirect('feeds')

    else:
        return render(request, 'authentication/signup.html', {
            'form_human': SignUpForm(),
            'users_challenges': users_challenges,
        })
Пример #18
0
 def setUp(self) -> None:
     title = 'Simple is Better Than Complex'
     link = 'https://simpleisbetterthancomplex.com/'
     rss = 'https://simpleisbetterthancomplex.com/feed.xml/'
     self.feed = Feed(title=title, link=link, rss=rss)
Пример #19
0
 def test_feed_model_defaults(self):
     feed = Feed()
     self.assertEqual(feed.title, '')
     self.assertEqual(feed.description, '')
     self.assertEqual(feed.version, '')
Пример #20
0
 def test_fetching_details_without_link(self):
     feed = Feed()
     with self.assertRaises(TypeError):
         feed.fetch_and_set_feed_details()
Пример #21
0
def signup_products(request):
    print('inside signup_products, authentication.view')

    recent_challenge_feeds = Feed.get_feeds().filter(
        is_challenge=1).order_by('-date')

    if recent_challenge_feeds:
        users_challenges = recent_challenge_feeds
    else:
        users_challenges = []

    if request.method == 'POST':
        form = SignUpForm(request.POST)
        flag = 'products'
        print('flag', 'products')
        if not form.is_valid():
            return render(
                request, 'authentication/signup.html', {
                    'form_products': form,
                    'flag': flag,
                    'users_challenges': users_challenges,
                })

        else:
            is_product = request.POST.get('is_product')
            username = form.cleaned_data.get('username')
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            User.objects.create_user(username=username,
                                     password=password,
                                     email=email)
            user = authenticate(username=username, password=password)

            profile_pk = user.profile.pk
            print(profile_pk, user.username)

            if is_product:
                print('user is a product')
                user.profile.is_product = 1
                user.save()
            login(request, user)

            profile_pk = user.profile.pk  # profile_pk of newley registered user
            profile = user.profile  # profile object of newly registered user
            print(profile_pk, user.username)

            hohos = get_object_or_404(User, username='******')
            hohoshelp = get_object_or_404(User, username='******')
            like_by_hohos = Activity(activity_type=Activity.LIKE_PROFILE,
                                     profile=profile_pk,
                                     user=hohos)
            like_by_hohoshelp = Activity(activity_type=Activity.LIKE_PROFILE,
                                         profile=profile_pk,
                                         user=hohoshelp)
            like_by_hohos.save()
            like_by_hohoshelp.save()
            hohos.profile.notify_liked_profile(
                profile)  # hohos to=> user(newly registered)
            hohoshelp.profile.notify_liked_profile(
                profile)  # hohoshelp to user(newly registered)

            like = Activity(activity_type=Activity.LIKE_PROFILE,
                            profile=profile_pk,
                            user=user)
            like.save()

            to_user = user
            from_user = get_object_or_404(User, username='******')
            if from_user:
                welcome_post = 'Hey ' + to_user.username + ' Get ready to solve your customers issues.'
                feed = Feed()
                feed.user = from_user
                feed.to_user = to_user
                to_user_profile_pk = profile_pk  # newley registered users profile pk
                feed.profile_pk = to_user_profile_pk
                feed.post = welcome_post
                feed.save()
                wrote_on_profile = Activity(
                    activity_type=Activity.WROTE_ON_PROFILE,
                    profile=to_user_profile_pk,
                    user=from_user)
                wrote_on_profile.save()
                hohos.profile.notify_wrote_on_profile(profile, feed)

            messages.add_message(
                request, messages.SUCCESS, 'Hey ,' + user.username +
                '\n Its what people and products are talking about, \
                                 See what people are talking with your friend products\
                                  You are live now you can talk to the people who use you\
                                  and people can talk you on your live profile!'
            )

            from_email = django_settings.EMAIL_HOST_USER
            to = [email]
            subject = 'Welcome at hohos ' + user.username
            message = 'Dear '+user.username+'!\n'\
                          + 'We are happy to see you on hohos.\n' \
                          + 'You will have lots of amazing experience along the time. It will get better if '\
                          + 'people using you start sharing their feedback\n'\
                          + 'This will help you become better and more efficient'\
                          + 'This way both you and customers may get the best of available\n'\
                          + 'Moreover you can become the part of OpenChat community at - hohos.tech/feeds/openchat/h_h/ '\
                          + ' here You can talk to your daily use products too. Which makes things a lot easier.\n\n'\
                          + 'Build you profile for better interaction.'\
                          + 'First hohos.tech/login and then move to hohos.tech/settings/human/\n\n'\
                          + 'Best wishes!\n'\
                          + '-Team iA at hohos.tech'
            if to:
                try:
                    send_mail(subject,
                              message,
                              from_email,
                              to,
                              fail_silently=False)
                except:
                    pass

            print('inside signup, authentication.views')
            print('user\'s pk %d' % (user.pk))
            return redirect('/feeds/openchat/h_p/')

    else:
        return render(request, 'authentication/signup.html', {
            'form_products': SignUpForm(),
            'users_challenges': users_challenges,
        })