def gigbargain_band_part_unlock(request, band_slug, gigbargain_uuid): """ During the band negociation phase, when a band unlock its part """ band = get_object_or_404(Band, slug=band_slug) if not request.user.has_perm('band.can_manage', band): return HttpResponseForbidden() gigbargain = get_object_or_404(GigBargain, uuid=gigbargain_uuid) gigbargain_band = get_object_or_404(GigBargainBand, bargain=gigbargain, band__slug=band_slug) if gigbargain.state not in ('band_nego', 'draft') \ or gigbargain_band.state != 'part_validated': # XXX: Maybe it should more explicit return HttpResponseForbidden() # if all bands agreed, then come back to "negociating" phase # if gigbargain.state == 'band_ok': # gigbargain.bands_dont_agree_anymore() # Cancel approval for this band gigbargain_band.cancel_approval() action.send(gigbargain_band, verb='part_unlocked', target=gigbargain, public=False) messages.success(request, _("You have unlocked your part")) return redirect(gigbargain)
def unfollow(user, obj, send_action=False, request=None): """ Removes a "follow" relationship. Set ``send_action`` to ``True`` (``False is default) to also send a ``<user> stopped following <object>`` action signal. Example:: unfollow(request.user, other_user) """ from actstream.models import Follow, action check_actionable_model(obj) Follow.objects.filter( user=user, object_id=obj.pk, content_type=ContentType.objects.get_for_model(obj)).delete() if send_action: if request: from django.utils import simplejson as json from agora_site.misc.utils import geolocate_ip action.send(user, verb=_('stopped following'), target=obj, ipaddr=request.META.get('REMOTE_ADDR'), geolocation=json.dumps( geolocate_ip(request.META.get('REMOTE_ADDR')))) else: action.send(user, verb=_('stopped following'), target=obj)
def record_vote_action(sender, created, instance, **kwargs): if created: action.send(instance.member, verb='voted', description=instance.get_type_display(), target=instance.vote, timestamp=instance.vote.time)
def follow(user, actor, send_action=True): """ Creates a ``User`` -> ``Actor`` follow relationship such that the actor's activities appear in the user's stream. Also sends the ``<user> started following <actor>`` action signal. Returns the created ``Follow`` instance. If ``send_action`` is false, no "started following" signal will be created Syntax:: follow(<user>, <actor>) Example:: follow(request.user, group) """ from actstream.models import Follow, action check_actionable_model(actor) follow, created = Follow.objects.get_or_create(user=user, object_id=actor.pk, content_type=ContentType.objects.get_for_model(actor)) if send_action and created: action.send(user, verb=_('started following'), target=actor) return follow
def follow(user, obj, send_action=True, actor_only=True): """ Creates a relationship allowing the object's activities to appear in the user's stream. Returns the created ``Follow`` instance. If ``send_action`` is ``True`` (the default) then a ``<user> started following <object>`` action signal is sent. If ``actor_only`` is ``True`` (the default) then only actions where the object is the actor will appear in the user's activity stream. Set to ``False`` to also include actions where this object is the action_object or the target. Example:: follow(request.user, group, actor_only=False) """ from actstream.models import Follow, action check_actionable_model(obj) follow, created = Follow.objects.get_or_create(user=user, object_id=obj.pk, content_type=ContentType.objects.get_for_model(obj), actor_only=actor_only) if send_action and created: action.send(user, verb=_('started following'), target=obj) return follow
def gigbargain_venue_renegociate(request, gigbargain_uuid): """ When a bargain has been approved, restart negociations if something is incorrect """ gigbargain = get_object_or_404(GigBargain, uuid=gigbargain_uuid) if not request.user.has_perm('venue.can_manage', gigbargain.venue): return HttpResponseForbidden() if gigbargain.state not in ('band_ok'): # XXX: Maybe it should more explicit return HttpResponseForbidden() reason_form = VenueReasonForm(request.POST or None) if request.method == 'POST' and reason_form.is_valid(): for gigbargainband in gigbargain.gigbargainband_set.filter(state='part_validated'): gigbargainband.cancel_approval() # Save the reason and reset band states gigbargain.venue_reason = reason_form.cleaned_data['venue_reason'] gigbargain.bands_dont_agree_anymore() # Send the action action.send(gigbargain.venue, verb='venue_restarted_negociations', target=gigbargain, public=False) return redirect(gigbargain) else: extra_context = {'gigbargain': gigbargain, 'reason_form': reason_form} return render_to_response(template_name='gigbargain/gigbargain_venue_renegociate.html', context_instance=RequestContext(request, extra_context) )
def unfollow(user, obj, send_action=False, request=None): """ Removes a "follow" relationship. Set ``send_action`` to ``True`` (``False is default) to also send a ``<user> stopped following <object>`` action signal. Example:: unfollow(request.user, other_user) """ from actstream.models import Follow, action check_actionable_model(obj) Follow.objects.filter(user=user, object_id=obj.pk, content_type=ContentType.objects.get_for_model(obj)).delete() if send_action: if request: from django.utils import simplejson as json from agora_site.misc.utils import geolocate_ip action.send(user, verb=_('stopped following'), target=obj, ipaddr=request.META.get('REMOTE_ADDR'), geolocation=json.dumps(geolocate_ip(request.META.get('REMOTE_ADDR')))) else: action.send(user, verb=_('stopped following'), target=obj)
def gigbargain_venue_enter_negociations(request, gigbargain_uuid): """ When a gigbargain is proposed by bands to a venue, a venue can choose to enter the negociations. """ gigbargain = get_object_or_404(GigBargain, uuid=gigbargain_uuid) if not request.user.has_perm('venue.can_manage', gigbargain.venue): return HttpResponseForbidden() if gigbargain.state not in ('complete_proposed_to_venue', 'incomplete_proposed_to_venue'): # XXX Maybe we should be more explicit return HttpResponseForbidden() reason_form = VenueReasonForm(request.POST or None) if request.method == 'POST' and reason_form.is_valid(): # XXX not sure we want to keep this # if this is an incomplete bargain, just make the bands enter # negociations if gigbargain.state == 'incomplete_proposed_to_venue': [gigbargainband.start_negociating() for gigbargainband in gigbargain.gigbargainband_set.all()] # else, if it is a complete bargain, we have to invalidate the # bands approval elif gigbargain.state == 'complete_proposed_to_venue': [gigbargainband.cancel_approval() for gigbargainband in gigbargain.gigbargainband_set.filter(state='part_validated')] # Then, switch our gigbargain state by letting the venue enter gigbargain.venue_reason = reason_form.cleaned_data['venue_reason'] gigbargain.venue_enter_negociations() # Send the action action.send(gigbargain.venue, verb='venue_entered_negociations', target=gigbargain, public=False) # Notify the bands the venue wants to negociate from ..models import collect_band_members_from_gigbargain notification.send(collect_band_members_from_gigbargain(gigbargain), "gigbargain_venue_enters_negociations", {'gigbargain': gigbargain}, ) return redirect(gigbargain) else: extra_context = {'gigbargain': gigbargain, 'reason_form': reason_form} return render_to_response(template_name='gigbargain/gigbargain_venue_enter_negociations.html', context_instance=RequestContext(request, extra_context) )
def post_delete(self, obj): # token logout tokens = obj.get_active_tokens() tokens.select_for_update().update(is_deleted=True) # session logout logout(self.request) # log action.send(obj, verb=User.verbs.get('delete'))
def post(self, request): serializer = self.serializer_class(data=request.DATA) if serializer.is_valid(): login(request, serializer.object['user']) action.send(serializer.object['user'], verb=User.verbs.get("login"), level=Action.INFO, type=settings.AUTH_SESSION) user_data = UserDetailSerializer(serializer.object['user']) return Response(user_data.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self, request): auth = request.auth auth.is_deleted = True auth.deleted_at = datetime.datetime.utcnow().replace(tzinfo=utc) auth.save() action.send(request.user, verb=User.verbs.get('logout'), level=Action.INFO, action_object=auth, auth_key=auth.key) return Response(status=status.HTTP_200_OK)
def on_presskitview_new(sender, **kwargs): presskitview = sender # Log the action action.send(presskitview.presskit.band, verb='presskitview_sent', target=presskitview, public=False) notification.send(presskitview.venue.members.all(), 'presskitview_new', {'presskitview': presskitview})
def gigbargain_band_part_lock(request, band_slug, gigbargain_uuid): """ During the band negociation phase, when a band accepts and locks its part """ band = get_object_or_404(Band, slug=band_slug) if not request.user.has_perm('band.can_manage', band): return HttpResponseForbidden() gigbargain = get_object_or_404(GigBargain, uuid=gigbargain_uuid) gigbargain_band = get_object_or_404(GigBargainBand, bargain=gigbargain, band__slug=band_slug) if gigbargain.state not in ('draft', 'band_nego') \ or gigbargain_band.state not in ('negociating', 'part_validated'): # XXX: Maybe it should more explicit return HttpResponseForbidden() # See if it can be approved with these information or if we need more # Redirect to form edit if can't be approved in state data = model_to_dict(gigbargain_band) # XXX FIXME # data['set_duration'] = from_timedelta(timedelta(microseconds=data['set_duration'])) # XXX Little hack to work around durationfield bug gigbargainband_form = GigBargainBandPartEditForm(data, instance=gigbargain_band) if not gigbargainband_form.is_valid(): messages.error(request, _("You can't lock your part since you haven't finished filling in your part of the bargain")) return redirect(gigbargain) action.send(gigbargain_band, verb='part_locked', target=gigbargain, public=False) gigbargain_band.approve_part() messages.success(request, _("You have locked your part")) # If all bands have accepted their parts, then either : # - set as band_ok if we were in band_nego # - set as draft_ok if we were in draft if len(GigBargainBand.objects.filter(bargain=gigbargain, state='negociating').exclude(id=gigbargain_band.id)) == 0: if gigbargain.state == 'band_nego': gigbargain.bands_have_approved_parts() elif gigbargain.state == 'draft': # We have to check that no band is still being invited. # If this is it the case, we don't validate the bargain if len(gigbargain.gigbargainband_set.filter(state__in=('waiting', 'negociating'))) == 0: gigbargain.bands_have_approved_draft() # Notify users a draft is ready from ..models import collect_band_members_from_gigbargain notification.send(collect_band_members_from_gigbargain(gigbargain), "gigbargain_draft_ready", {'band': gigbargain_band, 'gigbargain': gigbargain } ) return redirect(gigbargain)
def post_save(self, obj, created=False): # Template template = get_template('email/forgot_username.html') template_context = Context({'user': obj, 'request': self.request}) content = template.render(template_context) # log action.send(obj, verb=User.verbs.get('forgot_username'), content=content, level=Action.INFO) # mail send send_mail(subject="Forgot My Username", message=content, recipient_list=[obj.email], from_email=settings.DEFAULT_FROM_EMAIL)
def on_presskitview_band_comment(sender, **kwargs): presskitview = sender # Log the action action.send(presskitview.presskit.band, verb='presskitview_commented_on', target=presskitview, public=False) # Mark there's something new to see for the venue presskitview.news_for_venue = True presskitview.save() notification.send(presskitview.venue.members.all(), 'presskitview_band_comment', {'presskitview': presskitview})
def on_presskitview_refused_by_venue(sender, **kwargs): presskitview = sender # Log the action action.send(presskitview.venue, verb='presskitview_refused', target=presskitview, public=False) # Mark there's something new to see for the band presskitview.news_for_band = True presskitview.save() notification.send(presskitview.presskit.band.members.all(), 'presskitview_refused_by_venue', {'presskitview': presskitview})
def post_save(self, obj, created=False): if not created: return # now create a new NetworkAdmin and NetworkConnection connection = NetworkConnection.objects.create(user=self.request.user, network=obj, is_approved=True) NetworkAdmin.objects.create(user=self.request.user, network=obj, status=NetworkAdmin.ADMIN, connection=connection) action.send(self.request.user, verb=NetworkAdmin.verbs.get('assigned'), action_object=obj)
def post(self, request): serializer = self.serializer_class(data=request.DATA) if serializer.is_valid(): token, created = AccessToken.objects.get_or_create( user=serializer.object['user'], is_deleted=False) if not created: # update the created time of the token to keep it valid token.created = datetime.datetime.utcnow().replace(tzinfo=utc) token.save() action.send(serializer.object['user'], verb=User.verbs.get("login"), level=Action.INFO, type=settings.TOKEN_SESSION) user_data = UserDetailSerializer(serializer.object['user']) return Response({'user': user_data.data, 'token': token.key}) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def unfollow(user, obj, send_action=False): """ Removes a "follow" relationship. Set ``send_action`` to ``True`` (``False is default) to also send a ``<user> stopped following <object>`` action signal. Example:: unfollow(request.user, other_user) """ from actstream.models import Follow, action check_actionable_model(obj) Follow.objects.filter(user=user, object_id=obj.pk, content_type=ContentType.objects.get_for_model(obj)).delete() if send_action: action.send(user, verb=_("stopped following"), target=obj)
def unfollow(user, obj, send_action=False): """ Removes a "follow" relationship. Set ``send_action`` to ``True`` (``False is default) to also send a ``<user> stopped following <object>`` action signal. Example:: unfollow(request.user, other_user) """ from actstream.models import Follow, action check_actionable_model(obj) Follow.objects.filter(user=user, object_id=obj.pk, content_type=ContentType.objects.get_for_model(obj)).delete() if send_action: action.send(user, verb=_('stopped following'), target=obj)
def follow(user, obj, send_action=True, actor_only=False, request=None): """ Creates a relationship allowing the object's activities to appear in the user's stream. Returns the created ``Follow`` instance. If ``send_action`` is ``True`` (the default) then a ``<user> started following <object>`` action signal is sent. If ``actor_only`` is ``True`` (the default) then only actions where the object is the actor will appear in the user's activity stream. Set to ``False`` to also include actions where this object is the action_object or the target. Example:: follow(request.user, group, actor_only=False) """ from actstream.models import Follow, action check_actionable_model(obj) follow, created = Follow.objects.get_or_create( user=user, object_id=obj.pk, content_type=ContentType.objects.get_for_model(obj), actor_only=actor_only) if send_action and created: if request: from django.utils import simplejson as json from agora_site.misc.utils import geolocate_ip action.send(user, verb=_('started following'), target=obj, ipaddr=request.META.get('REMOTE_ADDR'), geolocation=json.dumps( geolocate_ip(request.META.get('REMOTE_ADDR')))) else: action.send(user, verb=_('started following'), target=obj) return follow
def gigbargain_band_invite_band(request, gigbargain_uuid): """ When a Band invites another Band to join a bargain """ gigbargain = get_object_or_404(GigBargain, uuid=gigbargain_uuid) if gigbargain.state not in ('draft'): # XXX: Maybe it should more explicit return HttpResponseForbidden() gigbargainband_form = GigBargainBandInviteForm(gigbargain, request.POST or None) if request.method == 'POST': if gigbargainband_form.is_valid(): gigbargain_band = gigbargainband_form.save(commit=False) gigbargain_band.bargain = gigbargain gigbargain_band.save() # If there were bands that had validated their part, invalidate them for gigbargainband in gigbargain.gigbargainband_set.filter(state='part_validated'): gigbargainband.cancel_approval() action.send(gigbargain_band, verb='was_invited', target=gigbargain, public=False) notification.send(gigbargain_band.band.members.all(), "gigbargain_invitation", {'band': gigbargain_band.band, 'gigbargain': gigbargain } ) messages.success(request, _("%s was successfully invited") % gigbargain_band.band.name) return redirect(gigbargain) extra_context = {'gigbargain': gigbargain, 'gigbargainband_form': gigbargainband_form} return render_to_response(template_name='gigbargain/gigbargain_invite_band.html', context_instance=RequestContext(request, extra_context) )
def unfollow(user, actor, send_action=False): """ Removes ``User`` -> ``Actor`` follow relationship. Optionally sends the ``<user> stopped following <actor>`` action signal. Syntax:: unfollow(<user>, <actor>) Example:: unfollow(request.user, other_user) """ from actstream.models import Follow, action check_actionable_model(actor) Follow.objects.filter(user=user, object_id=actor.pk, content_type=ContentType.objects.get_for_model(actor)).delete() if send_action: action.send(user, verb=_('stopped following'), target=actor)
def follow(user, obj, send_action=True, actor_only=False, request=None): """ Creates a relationship allowing the object's activities to appear in the user's stream. Returns the created ``Follow`` instance. If ``send_action`` is ``True`` (the default) then a ``<user> started following <object>`` action signal is sent. If ``actor_only`` is ``True`` (the default) then only actions where the object is the actor will appear in the user's activity stream. Set to ``False`` to also include actions where this object is the action_object or the target. Example:: follow(request.user, group, actor_only=False) """ from actstream.models import Follow, action check_actionable_model(obj) follow, created = Follow.objects.get_or_create(user=user, object_id=obj.pk, content_type=ContentType.objects.get_for_model(obj), actor_only=actor_only) if send_action and created: if request: from django.utils import simplejson as json from agora_site.misc.utils import geolocate_ip action.send(user, verb=_('started following'), target=obj, ipaddr=request.META.get('REMOTE_ADDR'), geolocation=json.dumps(geolocate_ip(request.META.get('REMOTE_ADDR')))) else: action.send(user, verb=_('started following'), target=obj) return follow
def gigbargain_band_submit_draft_to_venue(request, gigbargain_uuid): """ Submits a draft to the targetted venue """ gigbargain = get_object_or_404(GigBargain, uuid=gigbargain_uuid) if gigbargain.state != 'draft_ok': # XXX: Maybe it should more explicit return HttpResponseForbidden() gigbargain.propose_complete_bargain_to_venue() action.send(request.user, verb='submitted_to_venue', target=gigbargain, public=False) messages.success(request, _("The bargain was submitted to %s") % gigbargain.venue.name) # temporary fix to notify people staff = User.objects.filter(is_staff=True) notification.send(staff, "gigbargain_draft_submitted_to_venue", {'gigbargain': gigbargain} ) return redirect(gigbargain)
def gigbargain_enter_for_band(request, band_slug, gigbargain_uuid): """ Enter a bargain, for a band """ band = get_object_or_404(Band, slug=band_slug) if not request.user.has_perm('band.can_manage', band): return HttpResponseForbidden() gigbargain = get_object_or_404(GigBargain, uuid=gigbargain_uuid) gigbargain_band = get_object_or_404(GigBargainBand, bargain__uuid=gigbargain_uuid, band__slug=band_slug) if gigbargain.state not in ('new', 'draft', 'band_nego'): # XXX: Maybe it should more explicit return HttpResponseForbidden() # If we were waiting, switch to "accepted" and save if gigbargain_band.state == 'waiting': gigbargain_band.accept() # Negociations haven't already started if gigbargain.state == 'new': # If everybody has accepted, bands can start negociating if all([gigbargain_band.state == 'accepted' for gigbargain_band in gigbargain.gigbargainband_set.all()]): for gigbargain_band in gigbargain.gigbargainband_set.all(): gigbargain_band.start_negociating() # Then, update bargain state gigbargain.start_band_negociation() # If /SOME/ of the bands have accepted, ask the venue if we start negociation or not elif all([gigbargain_band.state != 'waiting' for gigbargain_band in gigbargain.gigbargainband_set.all()]): gigbargain.need_venue_confirmation() # If negociations have already started elif gigbargain.state in ('draft', 'band_nego'): gigbargain_band.start_negociating() # Since we're joining, invalidate all parts of other bands for gigbargainband in gigbargain.gigbargainband_set.all(): if gigbargainband.state == 'part_validated': gigbargainband.cancel_approval() # Send the action action.send(gigbargain_band, verb='gigbargain_entered', target=gigbargain, public=False) messages.success(request, _("You (%(band_name)s) are now bargaining with %(venue_name)s") % {'band_name': band.name, 'venue_name': gigbargain.venue.name} ) # If not, warn we have already entered the bargain elif gigbargain_band.state in ('accepted', 'negociating', 'validated'): messages.warning(request, _("You (%(band_name)s) are already bargaining with %(venue_name)s") % {'band_name': band.name, 'venue_name': gigbargain.venue.name} ) # If we're no more in the bargain elif gigbargain_band.state in ('refused', 'exited', 'kicked'): messages.error(request, _("You are no more part of this bargain")) return redirect(gigbargain)
def post_save(self, obj, created=False): action.send(self.request.user, verb=User.verbs.get('update'), level=Action.INFO, old_profile=self.old_profile)
def get(self, request): user = request.user logout(request) action.send(user, verb=User.verbs.get('logout'), level=Action.INFO) return Response(status=status.HTTP_200_OK)
def post_save(self, obj, created=False): action.send(obj, verb=User.verbs.get('new_password'), level=Action.INFO)
def post_delete(self, obj): action.send(self.request.user, verb=Follow.verbs.get('unfollow'), followee=obj.followee.username, follower=obj.follower.username)
def post_save(self, obj, created=False): action.send(obj, verb=User.verbs.get('register'), level=Action.INFO)
def post_save(self, obj, created=False): action.send(self.request.user, verb=Follow.verbs.get('follow'), action_object=obj)
def post_save(self, obj, created=False): action.send(obj, verb=User.verbs.get('password_update'))
def record_vote_action(sender, created, instance, **kwargs): if created: action.send(instance.member, verb='voted', description=instance.get_type_display(), target = instance.vote, timestamp=instance.vote.time)
def generate_activity_stream(self): ''' create an activity stream based on the data stored in self ''' Action.objects.stream_for_actor(self).delete() ps = list(self.proposals.all()) try: ps.append(self.gov_proposal) except GovProposal.DoesNotExist: pass for p in ps: action.send(self, verb='was-proposed', target=p, timestamp=p.date, description=p.title) try: p = self.knesset_proposal action.send(self, verb='was-knesset-proposed', target=p, timestamp=p.date, description=p.title) except KnessetProposal.DoesNotExist: pass for v in self.pre_votes.all(): discussion = False for h in CONVERT_TO_DISCUSSION_HEADERS: if v.title.find(h)>=0: # converted to discussion discussion = True if discussion: action.send(self, verb='was-converted-to-discussion', target=v, timestamp=v.time) else: action.send(self, verb='was-pre-voted', target=v, timestamp=v.time, description=v.passed) if self.first_vote: action.send(self, verb='was-first-voted', target=self.first_vote, timestamp=self.first_vote.time, description=self.first_vote.passed) if self.approval_vote: action.send(self, verb='was-approval-voted', target=self.approval_vote, timestamp=self.approval_vote.time, description=self.approval_vote.passed) for cm in self.first_committee_meetings.all(): action.send(self, verb='was-discussed-1', target=cm, timestamp=cm.date, description=cm.committee.name) for cm in self.second_committee_meetings.all(): action.send(self, verb='was-discussed-2', target=cm, timestamp=cm.date, description=cm.committee.name) for g in self.gov_decisions.all(): action.send(self, verb='was-voted-on-gov', target=g, timestamp=g.date, description=str(g.stand))
def gigbargain_refuse_for_band(request, band_slug, gigbargain_uuid): """ For a Band, don't enter a gigbargain and so refuse it. """ band = get_object_or_404(Band, slug=band_slug) if not request.user.has_perm('band.can_manage', band): return HttpResponseForbidden() gigbargain = get_object_or_404(GigBargain, uuid=gigbargain_uuid) gigbargain_band = get_object_or_404(GigBargainBand, bargain__uuid=gigbargain_uuid, band__slug=band_slug) if gigbargain.state not in ('new', 'draft', 'band_nego'): # XXX: Maybe it should more explicit return HttpResponseForbidden() # Build the form refuse_form = GigBargainBandRefuseForm(request.POST or None) if request.method == 'POST' and refuse_form.is_valid(): # If we were waiting, switch to "refused" and save if gigbargain_band.state == 'waiting': # Save the reason and refuse gigbargain_band.reason = refuse_form.cleaned_data['reason'] gigbargain_band.refuse() action.send(gigbargain_band, verb='refused', target=gigbargain, public=False) messages.success(request, _("You (%(band_name)s) have refused to bargain with %(venue_name)s") % {'band_name': band.name, 'venue_name': gigbargain.venue.name} ) if gigbargain.state == 'new': # If no more bands are waiting, trigger bargain state update if all([gigbargain_band.state != 'waiting' for gigbargain_band in gigbargain.gigbargainband_set.all()]): gigbargain.need_venue_confirmation() elif gigbargain.state == 'draft': # Check if now, there are only bands with their parts # validated, because if so, validate the whole bargain gigbargainbands = gigbargain.gigbargainband_set.all() for state in 'waiting', 'accepted', 'negociating', 'exited', 'kicked', 'refused': gigbargainbands = gigbargainbands.exclude(state=state) if len(gigbargainbands) and all([gigbargain_band.state == 'part_validated' for gigbargain_band in gigbargainbands]): gigbargain.bands_have_approved_draft() elif gigbargain_band.state == 'refused': messages.warning(request, _("You (%s) have already refused this bargain") % (band.name)) return redirect(gigbargain) else: extra_context = {'gigbargain': gigbargain, 'band': band, 'refuse_form': refuse_form} return render_to_response(template_name='gigbargain/gigbargain_band_refuse.html', context_instance=RequestContext(request, extra_context) )
def generate_activity_stream(self): ''' create an activity stream based on the data stored in self ''' Action.objects.stream_for_actor(self).delete() ps = list(self.proposals.all()) try: ps.append(self.gov_proposal) except GovProposal.DoesNotExist: pass for p in ps: action.send(self, verb='was-proposed', target=p, timestamp=p.date, description=p.title) try: p = self.knesset_proposal action.send(self, verb='was-knesset-proposed', target=p, timestamp=p.date, description=p.title) except KnessetProposal.DoesNotExist: pass for v in self.pre_votes.all(): discussion = False for h in CONVERT_TO_DISCUSSION_HEADERS: if v.title.find(h) >= 0: # converted to discussion discussion = True if discussion: action.send(self, verb='was-converted-to-discussion', target=v, timestamp=v.time) else: action.send(self, verb='was-pre-voted', target=v, timestamp=v.time, description=v.passed) if self.first_vote: action.send(self, verb='was-first-voted', target=self.first_vote, timestamp=self.first_vote.time, description=self.first_vote.passed) if self.approval_vote: action.send(self, verb='was-approval-voted', target=self.approval_vote, timestamp=self.approval_vote.time, description=self.approval_vote.passed) for cm in self.first_committee_meetings.all(): action.send(self, verb='was-discussed-1', target=cm, timestamp=cm.date, description=cm.committee.name) for cm in self.second_committee_meetings.all(): action.send(self, verb='was-discussed-2', target=cm, timestamp=cm.date, description=cm.committee.name) for g in self.gov_decisions.all(): action.send(self, verb='was-voted-on-gov', target=g, timestamp=g.date, description=str(g.stand))