diff options
-rw-r--r-- | askbot/deps/django_authopenid/views.py | 122 | ||||
-rw-r--r-- | askbot/migrations/0135_auto__add_askwidget.py | 2 | ||||
-rw-r--r-- | askbot/models/question.py | 28 | ||||
-rw-r--r-- | askbot/skins/default/templates/question/sidebar.html | 39 | ||||
-rw-r--r-- | askbot/urls.py | 13 | ||||
-rw-r--r-- | askbot/views/commands.py | 10 | ||||
-rw-r--r-- | askbot/views/readers.py | 14 |
7 files changed, 91 insertions, 137 deletions
diff --git a/askbot/deps/django_authopenid/views.py b/askbot/deps/django_authopenid/views.py index ba25dcef..786a34ca 100644 --- a/askbot/deps/django_authopenid/views.py +++ b/askbot/deps/django_authopenid/views.py @@ -882,55 +882,6 @@ def register(request, login_provider_name=None, user_identifier=None): email = register_form.cleaned_data['email'] subscribe = email_feeds_form.cleaned_data['subscribe'] -<<<<<<< HEAD - user = User.objects.create_user(username, email) - user_registered.send(None, user = user) - - logging.debug('creating new openid user association for %s') - - UserAssociation( - openid_url = user_identifier, - user = user, - provider_name = login_provider_name, - last_used_timestamp = datetime.datetime.now() - ).save() - - del request.session['user_identifier'] - del request.session['login_provider_name'] - - logging.debug('logging the user in') - - user = authenticate(method = 'force', user_id = user.id) - if user is None: - error_message = 'please make sure that ' + \ - 'askbot.deps.django_authopenid.backends.AuthBackend' + \ - 'is in your settings.AUTHENTICATION_BACKENDS' - raise Exception(error_message) - - login(request, user) - - logging.debug('saving email feed settings') - email_feeds_form.save(user) - - #check if we need to post a question that was added anonymously - #this needs to be a function call becase this is also done - #if user just logged in and did not need to create the new account - - if user != None: - if askbot_settings.EMAIL_VALIDATION == True: - logging.debug('sending email validation') - send_new_email_key(user, nomessage=True) - output = validation_email_sent(request) - set_email_validation_message(user) #message set after generating view - return output - if user.is_authenticated(): - logging.debug('success, send user to main page') - return HttpResponseRedirect(reverse('index')) - else: - logging.debug('have really strange error') - raise Exception('openid login failed')#should not ever get here - -======= if askbot_settings.REQUIRE_VALID_EMAIL_FOR == 'nothing': user = create_authenticated_user_account( @@ -954,7 +905,6 @@ def register(request, login_provider_name=None, user_identifier=None): redirect_url = reverse('verify_email_and_register') + '?next=' + next_url return HttpResponseRedirect(redirect_url) ->>>>>>> e294275498398f85d573995c49eee399ec27746e providers = { 'yahoo':'<font color="purple">Yahoo!</font>', 'flickr':'<font color="#0063dc">flick</font><font color="#ff0084">r</font>™', @@ -1084,44 +1034,6 @@ def signup_with_password(request): username = form.cleaned_data['username'] password = form.cleaned_data['password1'] email = form.cleaned_data['email'] -<<<<<<< HEAD - provider_name = form.cleaned_data['login_provider'] - - new_user = User.objects.create_user(username, email, password) - user_registered.send(None, user = new_user) - - logging.debug('new user %s created' % username) - if provider_name != 'local': - raise NotImplementedError('must run create external user code') - - user = authenticate( - username = username, - password = password, - provider_name = provider_name, - method = 'password' - ) - - login(request, user) - logging.debug('new user logged in') - email_feeds_form.save(user) - logging.debug('email feeds form saved') - - # send email - #subject = _("Welcome email subject line") - #message_template = get_emplate( - # 'authopenid/confirm_email.txt' - #) - #message_context = Context({ - # 'signup_url': askbot_settings.APP_URL + reverse('user_signin'), - # 'username': username, - # 'password': password, - #}) - #message = message_template.render(message_context) - #send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, - # [user.email]) - #logging.debug('new password acct created, confirmation email sent!') - return HttpResponseRedirect(next) -======= subscribe = email_feeds_form.cleaned_data['subscribe'] if askbot_settings.REQUIRE_VALID_EMAIL_FOR == 'nothing': @@ -1148,7 +1060,6 @@ def signup_with_password(request): '?next=' + get_next_url(request) return HttpResponseRedirect(redirect_url) ->>>>>>> e294275498398f85d573995c49eee399ec27746e else: #todo: this can be solved with a decorator, maybe form.initial['login_provider'] = provider_name @@ -1241,45 +1152,12 @@ def send_email_key(email, key, handler_url_name='user_account_recover'): message = template.render(data) send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email]) -<<<<<<< HEAD -def send_new_email_key(user,nomessage=False): - import random - random.seed() - user.email_key = '%032x' % random.getrandbits(128) -======= def send_user_new_email_key(user): user.email_key = util.generate_random_key() ->>>>>>> e294275498398f85d573995c49eee399ec27746e user.save() send_email_key(user.email, user.email_key) -<<<<<<< HEAD - raises 404 if email validation is off - if current email is valid shows 'key_not_sent' view of - authopenid/changeemail.html template - """ - if askbot_settings.EMAIL_VALIDATION == True: - if request.user.email_isvalid: - data = { - 'email': request.user.email, - 'action_type': 'key_not_sent', - 'change_link': reverse('user_changeemail') - } - return render_into_skin( - 'authopenid/changeemail.html', - data, - request - ) - else: - send_new_email_key(request.user) - return validation_email_sent(request) - else: - raise Http404 - -def account_recover(request, key = None): -======= def account_recover(request): ->>>>>>> e294275498398f85d573995c49eee399ec27746e """view similar to send_email_key, except it allows user to recover an account by entering his/her email address diff --git a/askbot/migrations/0135_auto__add_askwidget.py b/askbot/migrations/0135_auto__add_askwidget.py index ebf6f717..0764e11d 100644 --- a/askbot/migrations/0135_auto__add_askwidget.py +++ b/askbot/migrations/0135_auto__add_askwidget.py @@ -77,7 +77,7 @@ class Migration(SchemaMigration): }, 'askbot.askwidget': { 'Meta': {'object_name': 'AskWidget'}, - 'default_group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Tag']", 'null': 'True', 'blank': 'True'}), + 'tag': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Tag']", 'null': 'True', 'blank': 'True'}), 'group': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'groups'", 'null': 'True', 'to': "orm['askbot.Tag']"}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'inner_style': ('django.db.models.fields.TextField', [], {'default': "''"}), diff --git a/askbot/models/question.py b/askbot/models/question.py index ab3e6959..bff4bc11 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -497,6 +497,34 @@ class Thread(models.Model): else: return self.get_answers(user).count() + def get_sharing_info(self): + """returns shared with user and group count""" + groups = self.groups + ugroups = groups.filter(name__startswith='_internal_') + ggroups = groups.exclude(name__startswith='_internal_') + return ugroups.count(), ggroups.count() + + def get_users_shared_with(self, max_count=None, exclude_user=None): + """returns query set of users with whom + this thread is shared + """ + groups = self.groups.filter(name__startswith='_internal_') + + if exclude_user: + groups = groups.exclude(created_by__id=exclude_user.id) + + user_ids = groups.values_list('created_by__id', flat=True) + if max_count: + user_ids = user_ids[:max_count] + return User.objects.filter(id__in=user_ids) + + def get_groups_shared_with(self, max_count=None): + """returns query set of groups with whom thread is shared""" + groups = self.groups.exclude(name__startswith='_internal_') + if max_count: + groups = groups[:max_count] + return groups + def update_favorite_count(self): self.favourite_count = FavoriteQuestion.objects.filter(thread=self).count() self.save() diff --git a/askbot/skins/default/templates/question/sidebar.html b/askbot/skins/default/templates/question/sidebar.html index ef99e988..837dfbe2 100644 --- a/askbot/skins/default/templates/question/sidebar.html +++ b/askbot/skins/default/templates/question/sidebar.html @@ -53,28 +53,43 @@ {% if thread.is_private() %} <h2>{% trans %}Share{% endtrans %}</h2> <label for="share_user_name">{% trans %}Share with users{% endtrans %}</label> - <p>{% trans %}Yourself{% endtrans %}</p> - {% for group in thread.groups.all() %} - {% if group.name.startswith('_internal_') %} - <p>{{ group.created_by.get_profile_link() }}<p> - {% endif %} + <p> + <a href="{{ request.user.get_profile_url() }}"> + {% trans %}You{% endtrans %} + </a> + </p> + {% for user in sharing_info['users'] %} + <p>{{ user.get_profile_link() }}<p> {% endfor %} + {% if sharing_info['more_users_count'] > 0 %} + <p><a + class="see-related-users" + data-url="{% url get_thread_shared_users %}" + data-thread-id="{{ thread.id }}" + >{% trans more_count=sharing_info['more_users_count'] %}... and {{ more_count }} more{% endtrans %} + </a></p> + {% endif %} <form action="{% url share_question_with_user %}" method="post">{% csrf_token %} <input id="share_user_name" type="text" class="groups-input" name="recipient_name" /> <input type="hidden" name="thread_id" value="{{ thread.id }}"/> <input type="submit" class="add-groups" value="{% trans %}add{% endtrans %}"/> </form> - {#% if thread.groups.count() %} + {% if sharing_info['groups'].count() > 0 %} <label for="group_name">{% trans %}Shared with groups:{% endtrans %}</label> {% else %} <label for="group_name">{% trans %}Share with a group{% endtrans %}</label> - {% endif %#} - <label for="share_group_name">{% trans %}Share with groups{% endtrans %}</label> - {% for group in thread.groups.all() %} - {% if not group.name.startswith('_internal_') %}{# todo: fix this hack #} - <p>{{ macros.user_group(group) }}</p> - {% endif %} + {% endif %} + {% for group in sharing_info['groups'] %} + <p>{{ macros.user_group(group) }}</p> {% endfor %} + {% if sharing_info['more_groups_count'] > 0 %} + <p><a + class="see-related-groups" + data-url="{% url get_thread_shared_groups %}" + data-thread-id="{{ thread.id }}" + >{% trans more_count=sharing_info['more_groups_count'] %}... and {{ more_count }} more{% endtrans %} + </a></p> + {% endif %} <form action="{% url share_question_with_group %}" method="post">{% csrf_token %} <input id="share_group_name" type="text" class="groups-input" name="recipient_name" /> <input type="hidden" name="thread_id" value="{{ thread.id }}"/> diff --git a/askbot/urls.py b/askbot/urls.py index 8beaa6ba..c55e552e 100644 --- a/askbot/urls.py +++ b/askbot/urls.py @@ -72,11 +72,20 @@ urlpatterns = patterns('', ), # END main page urls - url( r'^api/get_questions/', views.commands.api_get_questions, - name = 'api_get_questions' + name='api_get_questions' + ), + url( + r'^get-thread-shared-users/', + views.commands.get_thread_shared_users, + name='get_thread_shared_users' + ), + url( + r'^get-thread-shared-groups/', + views.commands.get_thread_shared_groups, + name='get_thread_shared_groups' ), url( r'^save-draft-question/', diff --git a/askbot/views/commands.py b/askbot/views/commands.py index 1b6b21e8..123fc112 100644 --- a/askbot/views/commands.py +++ b/askbot/views/commands.py @@ -476,6 +476,16 @@ def get_tags_by_wildcard(request): return HttpResponse(re_data, mimetype = 'application/json') @decorators.ajax_only +@decorators.get_only +def get_thread_shared_users(request): + pass + +@decorators.ajax_only +@decorators.get_only +def get_thread_shared_groups(request): + pass + +@decorators.ajax_only def get_html_template(request): """returns rendered template""" template_name = request.REQUEST.get('template_name', None) diff --git a/askbot/views/readers.py b/askbot/views/readers.py index ba331a83..3d0f131f 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -565,6 +565,19 @@ def question(request, id):#refactor - long subroutine. display question body, an previous_answer = answer break + #shared with ... + users_count, groups_count = thread.get_sharing_info() + shared_users = thread.get_users_shared_with( + max_count=2, + exclude_user=request.user + ) + sharing_info = { + 'users': shared_users, + 'groups': thread.get_groups_shared_with(max_count=2), + 'more_users_count': max(0, users_count - 3), + 'more_groups_count': max(0, groups_count - 3) + } + data = { 'is_cacheable': False,#is_cacheable, #temporary, until invalidation fix 'long_time': const.LONG_TIME,#"forever" caching @@ -586,6 +599,7 @@ def question(request, id):#refactor - long subroutine. display question body, an 'similar_threads' : thread.get_similar_threads(), 'language_code': translation.get_language(), 'paginator_context' : paginator_context, + 'sharing_info': sharing_info, 'show_post': show_post, 'show_comment': show_comment, 'show_comment_position': show_comment_position, |