source: asadb/forms/models.py @ 9fd60d4

fysm-4-1space-accessstablestagetest-hooks
Last change on this file since 9fd60d4 was 9fd60d4, checked in by Alex Dehnert <adehnert@…>, 15 years ago

Add FYSMView and record_metric

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[80982de]1from django.db import models
2
3import datetime
4
[9fd60d4]5import settings
[80982de]6import groups.models
[9fd60d4]7from util.misc import log_and_ignore_failures
[80982de]8
9class FYSM(models.Model):
10    group = models.ForeignKey(groups.models.Group)
[dafa3c8]11    display_name = models.CharField(max_length=50)
[80982de]12    year = models.IntegerField()
13    website = models.URLField()
[80194d8]14    join_url = models.URLField(help_text="If you have a specific web page for students interested in joining your group, you can link to it here. If you leave this blank it will default to your website.")
15    contact_email = models.EmailField(help_text="Give an address for students interested in joining the group to email (e.g., an officers list)")
16    description = models.TextField(help_text="Explain in about three or four sentences what your group does and why incoming freshmen should get involved.")
[1c853ea]17    logo = models.ImageField(upload_to='fysm/logos', blank=True, )
[57f8ffa]18    tags = models.CharField(max_length=100, blank=True, help_text="Specify some free-form, comma-delimited tags for your group", )
19    categories = models.ManyToManyField('FYSMCategory', blank=True, help_text="Put your group into whichever of our categories seem applicable.", )
[80982de]20
21    class Meta:
22        verbose_name = "FYSM submission"
23
[c27da9e]24class FYSMCategory(models.Model):
[80982de]25    name = models.CharField(max_length=10)
[dafa3c8]26    slug = models.SlugField()
[80982de]27    blurb = models.TextField()
[aba463b]28
29    def __str__(self, ):
30        return self.name
[dafa3c8]31
32    class Meta:
[c27da9e]33        verbose_name = "FYSM category"
34        verbose_name_plural = "FYSM categories"
[9fd60d4]35
36class FYSMView(models.Model):
37    fysm = models.ForeignKey(FYSM, blank=True, )
38    year = models.IntegerField(null=True, blank=True, )
39    page = models.CharField(max_length=20, blank=True, )
40    referer = models.URLField(verify_exists=False)
41    user_agent = models.CharField(max_length=255)
42    source_ip = models.IPAddressField()
43    source_user = models.CharField(max_length=30, blank=True, )
44
45    @staticmethod
46    @log_and_ignore_failures(logfile=settings.LOGFILE)
47    def record_metric(request, fysm=None, year=None, page=None, ):
48        record = FYSMView()
49        record.fysm = fysm
50        record.year = year
51        record.page = page
52        record.referer = request.META['HTTP_REFERER']
53        record.user_agent = request.META['HTTP_USER_AGENT']
54        record.source_ip = request.META['REMOTE_ADDR']
55        record.source_user = request.user.username
56        record.save()
Note: See TracBrowser for help on using the repository browser.