Commits

Nathaniel Tucker  committed d8c8e0f

Add membership creation for captain

  • Participants
  • Parent commits 448e1d0

Comments (0)

Files changed (4)

File ahgl/apps/profiles/templates/profiles/membership_form.html

+{% extends "site_base.html" %}
+
+{% load bootstrap_tags %}
+{% load i18n %}
+{% load account_tags %}
+{% load pagination_tags %}
+
+{% block head_title %}{% if membership %}{% trans "Edit Team Member" %}{% else %}{% trans "New Team Member" %}{% endif %}{% endblock %}
+
+{% block body %}
+<form method="post" class="form-horizontal well">
+    <fieldset>
+        <legend>{% if membership %}{% trans "Edit" %} {{membership}}{% else %}{% trans "New Team Member" %}{% endif %}</legend>
+        {{ form }}
+        <div class="form-actions">
+          <button type="submit" class="btn btn-primary">Submit</button>
+        </div>
+        {% csrf_token %}
+    </fieldset>
+</form>
+{% endblock %}

File ahgl/apps/profiles/views.py

 from django.utils import simplejson as json
 from django.template import RequestContext
 from django.db.models import Count
+from django.template.defaultfilters import slugify
 
 from idios.views import ProfileDetailView
 from idios.utils import get_profile_model
 from emailconfirmation.models import EmailAddress
 
 from utils.views import ObjectPermissionsCheckMixin
-from .models import Team, TeamMembership
+from .models import Team, TeamMembership, Profile
 from apps.tournaments.models import TournamentRound, Tournament
 
 class TournamentSlugContextView(object):
             char_name = forms.CharField(max_length=TeamMembership._meta.get_field('char_name').max_length, required=True, label="Your character name", help_text=u"or Summoner name")
             class Meta:
                 model = Team
-                exclude=('tournament','rank','seed','members',)
+                exclude=('tournament','rank','seed','members','slug')
             """def clean(self):
                 if self.cleaned_data.get('duplicate'):
                     dup = self.cleaned_data.get('duplicate')
                 return super(TeamCreateForm, self).clean()"""
             def save(self, *args, **kwargs):
                 self.instance.tournament = view.tournament
+                self.cleaned_data['slug'] = slugify(self.cleaned_data['name'])
                 super(TeamCreateForm, self).save(*args, **kwargs)
                 view.slug = self.cleaned_data['slug']
                 membership = TeamMembership(team=self.instance, profile=view.request.user.get_profile(), char_name=self.cleaned_data['char_name'], active=True, captain=True)
     def get_template_names(self):
         return "profiles/standings.html"
 
+class TeamMembershipCreateView(CreateView):
+    model = TeamMembership
+    template_name = "profiles/membership_form.html"
+    context_object_name = "membership"
+    def get_form_class(self):
+        view = self
+        class MembershipCreateForm(ModelForm):
+            team = forms.ModelChoiceField(queryset=Team.objects.filter(team_membership__profile__user=view.request.user))
+            profile = forms.ModelChoiceField(queryset=Profile.objects.filter(slug=self.kwargs['slug']), initial=view.profile, widget=forms.HiddenInput())
+            class Meta:
+                model = TeamMembership
+                fields = ('char_name','team','profile')
+            def save(self, *args, **kwargs):
+                self.cleaned_data['profile'] = view.profile
+                return super(MembershipCreateForm, self).save(*args, **kwargs)
+        return MembershipCreateForm
+    @method_decorator(login_required)
+    def dispatch(self, request, *args, **kwargs):
+        self.profile = get_object_or_404(Profile, slug=kwargs['slug'])
+        return super(TeamMembershipCreateView, self).dispatch(request, *args, **kwargs)
+
 class TeamMembershipUpdateView(ObjectPermissionsCheckMixin, UpdateView):
     template_name = "idios/profile_edit.html"
     template_name_ajax = "idios/profile_edit_ajax.html"

File ahgl/templates/profiles/_profile_info.html

 <p><a href="{{ profile.website }}">{{ profile.website }}</a></p>
 {% endif %}
 {% if request.user.is_authenticated and profile != request.user.get_profile %}<a href="{% url messages_compose_to profile.user %}" class="btn">Send Message</a>{% endif %}
+<a href="{% url membership_create slug=profile.slug %}" class="btn">Add to team</a>
 </div>
 <div class="content-section-2">
 {% for membership in profile.memberships %}

File ahgl/urls.py

 from messages.views import compose
 
 from apps.profiles.models import Profile
-from apps.profiles.views import MVPView, TeamListView, TeamDetailView, StandingsView, TeamUpdateView, TeamCreateView, MyProfileDetailView, TeamMembershipView, TeamMembershipUpdateView
+from apps.profiles.views import MVPView, TeamListView, TeamDetailView, StandingsView, TeamUpdateView, TeamCreateView, MyProfileDetailView, TeamMembershipView, TeamMembershipUpdateView, TeamMembershipCreateView
 from apps.tournaments.views import MatchDetailView, MatchListView, MatchReportView, SubmitLineupView, GameListView, PlayerAdminView
 from apps.tournaments.models import Match, Tournament
 
     url(r'^social/', include('social_auth.urls')),
     url(r"^openid/", include(PinaxConsumer().urls)),
     url(r"^profiles/profile/(?P<slug>[\w\._-]+)/$", MyProfileDetailView.as_view(), name="profile_detail"),
+    url(r"^profiles/profile/(?P<slug>[\w\._-]+)/add_membership/$", TeamMembershipCreateView.as_view(), name="membership_create"),
     url(r"^profiles/edit/$", ProfileUpdateView.as_view(form_class=model_forms.modelform_factory(Profile, exclude=('user','signature','signature_html','time_zone','language','post_count','avatar',))), name="profile_edit"),
     url(r"^profiles/membership_edit/(?P<pk>[\d]+)/$", TeamMembershipUpdateView.as_view(), name="membership_edit"),
     url(r"^profiles/", include("idios.urls")),