Fix and simplify the new team form

This commit is contained in:
Michael Hall 2018-01-23 11:12:46 -05:00
parent fe1140d0fc
commit e37a945220
5 changed files with 43 additions and 50 deletions

View file

@ -160,10 +160,10 @@ class TeamForm(ModelForm):
class NewTeamForm(ModelForm):
class Meta:
model = Team
fields = ['name', 'country', 'spr', 'city', 'web_url', 'tz']
fields = ['name', 'city', 'web_url', 'tz']
widgets = {
'country': Lookup(source='/api/country/', label='name'),
'spr': Lookup(source='/api/spr/', label='name'),
#'country': Lookup(source='/api/country/', label='name'),
#'spr': Lookup(source='/api/spr/', label='name'),
'city': Lookup(source='/api/cities/', label='name'),
}
raw_id_fields = ('country','spr','city')

View file

@ -141,9 +141,27 @@ class Team(models.Model):
members = models.ManyToManyField(UserProfile, through='Member', related_name="memberships", blank=True)
@property
def location_name(self):
if self.city:
return str(self.city)
elif self.spr:
return str(self.spr)
elif self.country:
return str(self.country)
else:
return ''
def __str__(self):
return u'%s' % (self.name)
def save(self, *args, **kwargs):
if self.city is not None:
self.spr = self.city.spr
self.country = self.spr.country
super().save(*args, **kwargs) # Call the "real" save() method.
class Member(models.Model):
NORMAL=0
MODERATOR=1

View file

@ -86,9 +86,8 @@ form {
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" integrity="sha256-KM512VNnjElC30ehFwehXjx1YCHPiQkOPmqnrWtpccM=" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
{% block javascript %}{% endblock %}
</html>

View file

@ -13,53 +13,29 @@
{% block javascript %}
<script type="text/javascript">
$(document).ready(function(){
$("#country_search").keyup(function() {
var searchText = this.value;
$.getJSON("/api/countries/?q="+searchText, function(data) {
var searchField = $("#country_search")[0];
var q = this.url.match(/q=([^&]+)/)[1]
var c = searchField.value
if (c != q) return;
var selectField = $("#country_select");
selectField.empty();
$.each(data, function(){
selectField.append('<option value="'+ this.id +'">'+ this.name + '</option>')
});
});
});
$("#spr_search").keyup(function() {
var searchText = this.value;
var country_id = $("#country_select")[0].selectedOptions[0].value;
$.getJSON("/api/spr/?q="+searchText+"&country="+country_id, function(data) {
var searchField = $("#spr_search")[0];
var q = this.url.match(/q=([^&]+)/)[1]
var c = searchField.value
if (c != q) return;
var selectField = $("#spr_select");
selectField.empty();
$.each(data, function(){
selectField.append('<option value="'+ this.id +'">'+ this.name + '</option>')
});
});
});
$("#city_search").keyup(function() {
var searchText = this.value;
var spr_id = $("#spr_select")[0].selectedOptions[0].value;
$.getJSON("/api/cities/?q="+searchText+"&spr="+spr_id, function(data) {
var searchField = $("#city_search")[0];
var q = this.url.match(/q=([^&]+)/)[1]
var c = searchField.value
if (c != q) return;
$.getJSON("/api/cities/?q="+searchText, function(data) {
var searchField = $("#city_search")[0];
var m = this.url.match(/q=([^&]+)/);
var q = "";
if (m && m.length > 0) {
q = this.url.match(/q=([^&]+)/)[1]
} var c = searchField.value
if (c != q) return;
var selectField = $("#city_select");
selectField.empty();
$.each(data, function(){
selectField.append('<option value="'+ this.id +'">'+ this.name + '</option>')
});
});
var selectField = $("#city_select");
selectField.empty();
$.each(data, function(){
selectField.append('<option value="'+ this.id +'">'+ this.display + '</option>')
});
});
});
});</script>
});
</script>
{% endblock %}

View file

@ -25,7 +25,7 @@ def home(request, *args, **kwards):
return render(request, 'get_together/index.html')
def events_list(request, *args, **kwargs):
events = Event.objects.order_by('start_time').all()
events = Event.objects.filter(end_time__gt=datetime.datetime.now()).order_by('start_time')
context = {
'events_list': events,
}