def add_discussion(request): if request.method == 'POST': # If the form has been submitted... form = NewDiscussionForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data# Process the data in form.cleaned_data user = request.user discussions_list = Discussion.objects.all().filter(owner=user, title= form.cleaned_data[ 'title']) if discussions_list.count() != 0: return render(request, 'coplay/message.html', {'message': 'כבר קיים עבורך דיון באותו נושא', 'rtl': 'dir="rtl"'}) new_discussion = Discussion(owner=user, title=form.cleaned_data['title'], description=form.cleaned_data[ 'description']) new_discussion.clean() new_discussion.save() messages.success(request, _("Your activity was created successfully")) return redirect(new_discussion) else: form = NewDiscussionForm() # An unbound form return render(request, 'coplay/new_discussion.html', { 'form': form, 'rtl': 'dir="rtl"' })
def create_dicussion(self): d = Discussion() d.owner = self.admin d.title = "Visit the moon" d.full_clean() d.save() return d
def add_discussion(request): if request.method == 'POST': # If the form has been submitted... form = NewDiscussionForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data# Process the data in form.cleaned_data user = request.user discussions_list = Discussion.objects.all().filter( owner=user, title=form.cleaned_data['title']) if discussions_list.count() != 0: return render( request, 'coplay/message.html', { 'message': 'כבר קיים עבורך דיון באותו נושא', 'rtl': 'dir="rtl"' }) new_discussion = Discussion( owner=user, title=form.cleaned_data['title'], description=form.cleaned_data['description']) new_discussion.clean() new_discussion.save() return HttpResponseRedirect( new_discussion.get_absolute_url()) # Redirect after POST else: form = NewDiscussionForm() # An unbound form return render(request, 'coplay/new_discussion.html', { 'form': form, 'rtl': 'dir="rtl"' })
def add_discussion(request): if request.method == 'POST': # If the form has been submitted... form = NewDiscussionForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data# Process the data in form.cleaned_data user = request.user list = Discussion.objects.all().filter(owner =user, title = form.cleaned_data['title']) if list.count() != 0: return render(request, 'coplay/message.html', { 'message' : 'כבר קיים עבורך דיון באותו נושא', 'rtl': 'dir="rtl"'}) new_discussion = Discussion(owner = user , title = form.cleaned_data['title'] , description = form.cleaned_data['description']) new_discussion.clean() new_discussion.save() return HttpResponseRedirect(new_discussion.get_absolute_url()) # Redirect after POST else: form = NewDiscussionForm() # An unbound form return render(request, 'coplay/new_discussion.html', { 'form': form, 'rtl' : 'dir="rtl"' })
def add_discussion(request): if request.method == 'POST': # If the form has been submitted... form = NewDiscussionForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data# Process the data in form.cleaned_data user = request.user discussions_list = Discussion.objects.all().filter(owner=user, title= form.cleaned_data[ 'title']) if discussions_list.count() != 0: return render(request, 'coplay/message.html', {'message': 'כבר קיים עבורך דיון באותו נושא', 'rtl': 'dir="rtl"'}) new_discussion = Discussion(owner=user, title=form.cleaned_data['title'], description=form.cleaned_data[ 'description']) new_discussion.clean() new_discussion.save() messages.success(request, _("Your activity was created successfully")) new_discussion.start_follow(user) t = Template(""" {{discussion.owner.get_full_name|default:discussion.owner.username}} מבקש/ת את העזרה שלך ב :\n "{{discussion.title}} "\n """) trunkated_subject_and_detailes = t.render(Context({"discussion": new_discussion})) discussion_email_updates(new_discussion, trunkated_subject_and_detailes, new_discussion.owner, trunkated_subject_and_detailes, mailing_list = get_followers_list(new_discussion.owner)) return redirect(new_discussion) else: form = NewDiscussionForm() # An unbound form return render(request, 'coplay/new_discussion.html', { 'form': form, 'rtl': 'dir="rtl"' })
def create_discussion( user = None, title = None, description = None, location_desc = None, tags_string = None, parent_url = None, parent_url_text = None, latitude = 0.0 , longitude = 0.0 , picture = None, movie_url = None, movie_url_url_text = None, anyway_progress_status = None , anyway_discuss_id = None ): if user is None: return None, 'no user provided' if user.is_authenticated() is False: return None, 'user not authenticated' if title is None: return None, 'Title not provided' if description is None: return None, 'description not provided' if len(description) > MAX_MESSAGE_INPUT_CHARS: return None, 'description len ' + str(len(description)) + '>' + str(MAX_MESSAGE_INPUT_CHARS) discussions_list = Discussion.objects.all().filter(owner=user, title = title ) if discussions_list.count() != 0: return None, 'user posted a discussion with the same title' new_discussion = Discussion( owner = user, title = title, description = description, parent_url = parent_url, parent_url_text = parent_url_text, latitude = latitude, longitude = longitude, picture = picture , movie_url = movie_url , movie_url_url_text = movie_url_url_text, anyway_progress_status = anyway_progress_status, anyway_discuss_id = anyway_discuss_id ) if location_desc: new_discussion.location_desc = location_desc new_discussion.clean() new_discussion.save() if tags_string: tags_list = tags_string.split(',') for tag in tags_list: new_discussion.tags.add( tag) new_discussion.full_clean() new_discussion.description_updated_at = timezone.now() new_discussion.save() user_started_a_new_discussion( new_discussion.owner) start_discussion_following(new_discussion, user) for tag in new_discussion.tags.all(): start_tag_following( user, tag) t = Template(""" {{discussion.owner.get_full_name|default:discussion.owner.username}} ביקש/ה את העזרה שלך ב : "{{discussion.title}} "\n """) trunkated_subject_and_detailes = t.render(Context({"discussion": new_discussion})) new_discussion_followers = [] user_s_following = get_followers_list(new_discussion.owner) #all the followers for the user and all the followers for a tag for user in User.objects.all(): if new_discussion.can_user_access_discussion( user): if user in user_s_following: new_discussion_followers.append(user) else: to_append = False for tag_iter in user.userprofile.followed_discussions_tags.all(): if tag_iter.name in new_discussion.tags.names(): to_append = True if to_append: new_discussion_followers.append(user) discussion_email_updates(new_discussion, trunkated_subject_and_detailes, new_discussion.owner, trunkated_subject_and_detailes, mailing_list = new_discussion_followers ) return new_discussion, None
def create_dicussion(self): d = Discussion( owner = self.admin, title = "Visit the moon") user_started_a_new_discussion( d.owner) d.full_clean() d.save() return d